Skip to content

[Blazor] WebAssembly JS initializers don't execute unless webAssembly options are provided to Blazor.start() #54049

Closed
@MackinnonBuck

Description

@MackinnonBuck

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

  1. Create a new Blazor Web App with WebAssembly interactivity (dotnet new blazor -int WebAssembly)
  2. Add a JS initializer module in the wwwroot folder of the server project (e.g., MyBlazorApp.lib.module.js)
  3. 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');
    }
  4. Run the app and navigate to the /counter page
  5. Observe that the browser console does not display any of the log messages from the JS initializers
  6. Modify App.razor to include the following:
    <script src="_framework/blazor.web.js" autostart="false"></script>
    <script>
        Blazor.start({
            webAssembly: {}
        });
    </script>
  7. 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

Metadata

Metadata

Assignees

Labels

Priority:1Work that is critical for the release, but we could probably ship withoutarea-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions