-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Js initialization in OnAfterRender stopped working with 0.7.0 #5649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@fs86 I have also seen this issue when using 0.7.0 where the overridden OnAfterRender is not getting fired, |
@fs86 looks like there are is a lot of refactoring happening at present, check out |
It is getting fired but DOM elements are not accessible in OnAfterRender. I think it might be possible that the event is getting fired too early. |
Anyone happen to have a workaround for this while we wait for it to hopefully be fixed in 0.8.0? |
I am not sure this will be workaround for this case, but you can try. Please follow timer2 in code Idea here is to delay some method call. In my case I used this trick because calling my method inside OnAfterRender was doing nothing, but from timer callback it is working as expected. Hope it helps. |
Closing this as this is definitely working now. Please check out a recent release and if you would experience the same issue feel free to file a new issue. |
After I upgraded to Blazor 0.7.0 I noticed that initialization scripts of 3rd party JavaScript libraries which I usually call in OnAfterRender stopped working.
E.g. I use select2 (https://github.com/select2/select2) to apply a custom style for my select fields. But it seems like something has changed with Blazor 0.7.0, because the following code (which used to work in 0.6.0) dosn't work anymore:
My JavaScript function:
The control style will get applied when I call StateHasChanged() after JsInterop.InitializeSelect2(), but this will end up in an endless loop. Is there a better place to call InitializeSelect2() than OnAfterRender?
Edit:
I found the following statement about lifecycle methods in the official documentation:
After doing a bit of research I can say that the corresponding field is not accessible in OnAfterRender.
The text was updated successfully, but these errors were encountered: