I run into problem with multiple times called OnAfterRenderAsync(bool firstRender) even when a previous run of the same method in the same component is not yet finished.
protected override async Task OnAfterRenderAsync(bool firstRender){ if (firstRender) { _jsModule = await JsRuntime.LoadJSModule(this); await _jsModule!.InvokeVoidAsync("doLogic"); } await _jsModule!.InvokeVoidAsync("doSomethingElse");}What the problem is:
- On
OnAfterRenderAsyncruns first time with parameterfirstRender = true - It goes inside first condition
- I run
StateHasChangedin parent component - On
AfterRenderAsyncis called second time with parameterfirstRender = false, even first run is still running and it's inside first condition - Second run skipped first condition and goes directly to logic after, but
_jsModuleis still null here. So it fails
How this situation should be handled correctly? I tried use Semaphore, and then it works fine. But I think that this situation should be handled somehow by Blazor itself?
I found this problem with one component till now, because I run StateHasChanged in very short period of time.
I can imagine that it can happens also in other components and should be solved generally. Do you have some ideas or do I miss something?