-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Awaiting RenderFragment to render #11338
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
@SteveSandersonMS @rynowak @javiercn Can you add some quick thoughts on the above as this is somewhat blocking for me. Is this approach valid in general? |
Thanks for contacting us, @Stamo-Gochev. |
If you want a parent to perform some actions on a child, use the combination of
|
@SteveSandersonMS This is indeed what I used as the JS interop call wasn't necessary in the real scenario. Still, I cannot figure out why such a call fixes the async behavior. |
Closing as the question seems to be answered :) |
@SteveSandersonMS I agree, it is seems reasonable for a child component and its ref to be populated after What I still cannot figure out is why making a JS interop call in:
makes the Here is a list of method calls when
Here is a list of method calls when
I understand that the proper way to 'await" |
Your JS interop call is async, so you're interrupting the method's execution while the JS interop call occurs. Blazor is performing a render in the meantime, which populates your |
The issue is about server-side blazor.
I am trying to follow the Manual RenderTreeBuilder logic topic in order to initialize a child component from a parent component.
The basic idea is: when the button in the
ParentComponent
is clicked, theChildComponent
is dynamically initialized and then itsShow
method is called.The problem I am facing is that the
OnClick
handler runs asynchronously:so the call
ChildComponent.Show()
throws a null reference exception as the code inCreateChildComponent
hasn't finished yet (probably due to the call toStateHasChanged()
). IfStateHasChanged
isn't called, then the fragment is not rendered at all.I tried things like wrapping the call in a
Task.Run()
:but this fails with an exception:
so this surely isn't the blazor way of doing things.
Interestingly, making a JS interop call makes the
OnClick
method run "synchronously", so the fragment is appended and theChildComponentRef.Show()
is working:Why the JS interop call fixes the problem? Is there another way to append a fragment that initializes a component and then use this component right away in a synchronous manner?
The text was updated successfully, but these errors were encountered: