-
Notifications
You must be signed in to change notification settings - Fork 10.3k
[Blazor] JS root component registration #37180
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
[Blazor] JS root component registration #37180
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense, but it'd odd that this wasn't done in the initial implementation. Can we have @SteveSandersonMS sign off on this in case he's aware of a reason this was separately handled?
It's the same as for any JS interop call. It's the developer's responsibility to wait until their .NET application is ready before making calls into it from outside. People can do this using await JS.InvokeVoidAsync("doMyJSInitialization");
// alternatively:
await JS.InvokeVoidAsync("import", "./myJsInitializationModule.js"); I'd err on the side of not changing this as a special case for JS root components based only on one customer request, especially given that they also said:
Does that sound reasonable @javiercn? |
The issue here is not that the .NET application is not ready, but rather that the host is not yet built (on the .NET side).
I don't think that's the case, since the promise returned from start doesn't guarantee that the host has been built? I think more in general, that people is calling a method on the Blazor object within the result from "Blazor.start" or "afterStarted" (which is virtually the same, since it's the last thing that happens during initialization) and at that point the functions in the Blazor object should be ready to accept being called. I think the fix is simple and that there is no technical reason for us not to internally wait until the framework setups interop internally (as the fix proposes). |
I know we can do it, and I see the fix is simple. My concern is about the wider pattern. Other cases of APIs people can call from JS and might do before the app starts up include:
There may be others in the future. Should they all wait for the runtime to start? Should it be a random subset of them that do? By adding this behavior to That was my reasoning before anyway. After more consideration, I guess some APIs are agnostic to whether the runtime has started (e.g., |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change at https://github.com/dotnet/aspnetcore/pull/37180/files#r720486550 is important; the other comments are just for clarity.
23d199c
to
da499ea
Compare
da499ea
to
c8a199a
Compare
Description
Delays the execution of afterStarted until the runtime has been initialized so that customers can invoke methods within the Blazor instance.
Fixes #37074
Customer Impact
This is feedback that we got in the RC where customers where not able to use two of the features that we built (JS Root Components and JS Initializers) together because the blazor webassembly host wasn't ready at the time.
It prevents customers for using JS initializers to initialize their component libraries in JS effectively, which is one of the goals the feature was designed for.
Regression?
Risk
We have end to end tests in this area, and I've verified manually that the call is now emitted at the right time.
Verification
Packaging changes reviewed?