Themes and OnAfterRenderAsync #4171
Replies: 2 comments 2 replies
-
@leigh-pointer can you share your OnAfterRenderAsync code? JS Interop is painful as there is so much potential for race conditions |
Beta Was this translation helpful? Give feedback.
-
@leigh-pointer how are you loading the JavaScript which is being used by the Theme component. When using Interactive Blazor and JS Interop you need to coordinate the loading of the JavaScript with the execution of the JavaScript. Usually this means that you need to register the JavaScript in the Resources collection within the Theme component and you need to call b await base.OnAfterRenderAsync(firstRender); as the first step in your Theme component's OnAfterRenderAsync() event. Calling await base.OnAfterRenderAsync(firstRender); is what actually loads the JavaScript into the page. Once it is loaded then you can execute one of its methods. However it can get very tricky if you have StateHasChanged() logic elsewhere in your component as the life cycle events can fire out of order. |
Beta Was this translation helpful? Give feedback.
-
I am having an issue trying to execute s JSRuntime.InvokeVoidAsync call in the OnAfterRenderAsync method. I am checking if (firstRender)
ERROR
Am I missing some voodoo magic ?
Beta Was this translation helpful? Give feedback.
All reactions