Description
Summary
The beforeWebAssemblyStart
and afterWebAssemblyStarted
JS initializer callbacks do not run unless autostart="false"
and a webAssembly
options object is passed to Blazor.start()
.
<script src="_framework/blazor.web.js" autostart="false"></script>
<script>
Blazor.start({
// Removing the line below causes WebAssembly JS initializers to get skipped
webAssembly: {}
});
</script>
This bug does not affect any of beforeWebStart
, afterWebStarted
, beforeServerStart
, and afterServerStarted
.
Steps to reproduce
- Create a new Blazor Web App with WebAssembly interactivity (
dotnet new blazor -int WebAssembly
) - Add a JS initializer module in the
wwwroot
folder of the server project (e.g.,MyBlazorApp.lib.module.js
) - Add the following content to the JS initializer module:
export function beforeWebAssemblyStart() { console.log('Before WebAssembly start'); } export function afterWebAssemblyStarted() { console.log('After WebAssembly started'); }
- Run the app and navigate to the
/counter
page - Observe that the browser console does not display any of the log messages from the JS initializers
- Modify
App.razor
to include the following:<script src="_framework/blazor.web.js" autostart="false"></script> <script> Blazor.start({ webAssembly: {} }); </script>
- Run the app again, navigate to the
/counter
page, and observe that the log messages now show up in the browser console.
Other info
- I have not yet tested whether this affects JS initializers defined in RCLs
.NET Version: Tested on 8.0.2 and 8.0.0, and the bug reproduced in both