-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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] Finalize behavior of JavaScript initializers for Blazor Web apps #50187
Comments
After discussing offline, this is what the current thinking is: Legacy initializers ( We will add new We will also add a new API on the options object passed to |
Updates the initializers in Blazor to include platform specific variants that can be tailored to each runtime. ## Description * Initializers in Blazor WebAssembly and Server allowed library authors and applications to define JS modules that would be automatically imported by the JS Blazor runtime when it booted up. * These JS modules were used to tweak the configuration of a given Blazor Runtime or perform additional initialization of JS libraries on the page. * Since Blazor Web can have multiple runtimes running simultaneously on the page at the same time (server and webassembly), libraries can run into issues like initializing the wrong runtime, running initialization multiple times, or having to wait until we initialize a runtime to apply custom styles and other logic that might be necessary for the correct function of their libraries. * This PR addresses that by defining runtime specific extension points that libraries can use to tweak a concrete runtime when it boots as well as an initial extension point to target Blazor Web specific scenarios that don't involve a runtime. Fixes #50187 ## Customer Impact * Existing libraries with initializers won't be initialized until an interactive component is rendered on the page. * Initialization logic might run more than once for existing libraries, causing all sorts of unpredictable side effects. * For example, double initialization. ## Regression? - [ ] Yes - [X] No It's not a regression in the sense that Blazor Web is a new scenario, but a feature that library authors depend on (for example the Fluent UI Blazor components library does) will not work reliably in this scenario. ## Risk - [ ] High - [ ] Medium - [X] Low The fix is an extension to the existing mechanism to give library authors a path forward. The previous mechanism is disabled by default in Blazor Web scenarios and this fix gives library authors a path forward to make the feature work reliably here. In addition to that, with this fix app developers are not blocked on library authors updating their packages to work on Blazor web, as they can author adapters for the initializers within their apps that use the extension defined by the fix. ## Verification - [ ] Manual (required) - [X] Automated ## Packaging changes reviewed? - [ ] Yes - [ ] No - [X] N/A ---- ## When servicing release/2.1 - [ ] Make necessary changes in eng/PatchConfig.props
Updates the initializers in Blazor to include platform specific variants that can be tailored to each runtime. ## Description * Initializers in Blazor WebAssembly and Server allowed library authors and applications to define JS modules that would be automatically imported by the JS Blazor runtime when it booted up. * These JS modules were used to tweak the configuration of a given Blazor Runtime or perform additional initialization of JS libraries on the page. * Since Blazor Web can have multiple runtimes running simultaneously on the page at the same time (server and webassembly), libraries can run into issues like initializing the wrong runtime, running initialization multiple times, or having to wait until we initialize a runtime to apply custom styles and other logic that might be necessary for the correct function of their libraries. * This PR addresses that by defining runtime specific extension points that libraries can use to tweak a concrete runtime when it boots as well as an initial extension point to target Blazor Web specific scenarios that don't involve a runtime. Fixes #50187 ## Customer Impact * Existing libraries with initializers won't be initialized until an interactive component is rendered on the page. * Initialization logic might run more than once for existing libraries, causing all sorts of unpredictable side effects. * For example, double initialization. ## Regression? - [ ] Yes - [X] No It's not a regression in the sense that Blazor Web is a new scenario, but a feature that library authors depend on (for example the Fluent UI Blazor components library does) will not work reliably in this scenario. ## Risk - [ ] High - [ ] Medium - [X] Low The fix is an extension to the existing mechanism to give library authors a path forward. The previous mechanism is disabled by default in Blazor Web scenarios and this fix gives library authors a path forward to make the feature work reliably here. In addition to that, with this fix app developers are not blocked on library authors updating their packages to work on Blazor web, as they can author adapters for the initializers within their apps that use the extension defined by the fix. ## Verification - [ ] Manual (required) - [X] Automated ## Packaging changes reviewed? - [ ] Yes - [ ] No - [X] N/A ---- ## When servicing release/2.1 - [ ] Make necessary changes in eng/PatchConfig.props
Open questions with JavaScript initializers:
beforeStart
to make it easier to detect which .NET runtime (Server/WebAssembly) is starting?beforeStart
until we know for sure that Blazor WebAssembly is starting? Currently,beforeStart
gets invoked during the Blazor WebAssembly loading procedure, but this doesn't always indicate that Blazor WebAssembly will be used (consider auto mode).afterStarted
callback run each time a new circuit is created? We plan on closing circuits automatically if all Blazor Server components get removed from the page.beforeStart
execute immediately afterBlazor.start()
is called when usingblazor.web.js
? Currently,beforeStart
only executes just before Blazor WebAssembly or Blazor Server starts up.Blazor.start()
gets called, butbeforeStart
only gets called when Blazor Server or WebAssembly starts?afterStarted
callback to indicate which .NET runtime started?The text was updated successfully, but these errors were encountered: