[Blazor] Initializers fixes for Blazor Web#50860
Conversation
d9c6241 to
3c8a14c
Compare
| if (beforeWebAssemblyStart) { | ||
| options.webAssembly.initializers.beforeStart.push(beforeWebAssemblyStart); | ||
| } | ||
|
|
||
| if (afterWebAssemblyStarted) { | ||
| options.webAssembly.initializers.afterStarted.push(afterWebAssemblyStarted); | ||
| } | ||
|
|
||
| if (beforeServerStart) { | ||
| options.circuit.initializers.beforeStart.push(beforeServerStart); | ||
| } | ||
|
|
||
| if (afterServerStarted) { | ||
| options.circuit.initializers.afterStarted.push(afterServerStarted); | ||
| } | ||
|
|
||
| if (afterWebStarted) { | ||
| jsInitializer.afterStartedCallbacks.push(afterWebStarted); | ||
| } | ||
|
|
||
| if (beforeWebStart) { | ||
| return beforeWebStart(options); | ||
| } |
There was a problem hiding this comment.
We essentially collect all the callbacks from the initializer for server and webassembly, and set them in their respective options types. After that, we start running the beforeWebStart callback and trigger the afterWebStarted callbacks once we are done with the first render.
f5af2d0 to
c7e1166
Compare
|
@javiercn if this is still needed it should be retargeted to |
|
@wtgodbe I will retarget it once I am done with it. |
149d4a9 to
c8bb94d
Compare
MackinnonBuck
left a comment
There was a problem hiding this comment.
I still need to go through things in more detail, but the approach looks good to me so far.
|
Hi @javiercn. Please make sure you've updated the PR description to use the Shiproom Template. Also, make sure this PR is not marked as a draft and is ready-to-merge. To learn more about how to prepare a servicing PR click here. |
|
this has the servicing-consider label but I don't see a mail for it yet. |
9305ae7 to
7f26317
Compare
7f26317 to
3fb8fff
Compare
|
Hi @javiercn. This PR was just approved to be included in the upcoming servicing release. Somebody from the @dotnet/aspnet-build team will get it merged when the branches are open. Until then, please make sure all the CI checks pass and the PR is reviewed. |
* Updates initializers support to look for runtime specific callbacks
* beforeWebStart, afterWebStarted.
* beforeWebAssemblyStart, afterWebAssemblyStarted
* beforeServerStarts, afterServerStarted
* There is a new option on Blazor Server to get a callback when a circuit
is opened and closed in Blazor web scenarios.
* Blazor web applications ignore old initializers by default and warn in
the console of their presence.
* Classic initializers can be turned on via a setting in Blazor.start
options.
* Blazor WebAssembly and Blazor Server applications are updated to prefer
the new runtime specific initializers over the classic ones, but will
still run the classic ones by default.
3fb8fff to
7ca18db
Compare
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
Fixes #50187
Customer Impact
Regression?
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
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
Packaging changes reviewed?
When servicing release/2.1