Skip to content
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] WebAssembly JS initializers don't execute unless webAssembly options are provided to Blazor.start() #54049

Open
MackinnonBuck opened this issue Feb 14, 2024 · 0 comments · May be fixed by #59905
Assignees
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. Priority:1 Work that is critical for the release, but we could probably ship without

Comments

@MackinnonBuck
Copy link
Member

MackinnonBuck commented Feb 14, 2024

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

@MackinnonBuck MackinnonBuck added bug This issue describes a behavior which is not expected - a bug. area-blazor Includes: Blazor, Razor Components labels Feb 14, 2024
@javiercn javiercn added this to the .NET 9 Planning milestone Feb 19, 2024
@danroth27 danroth27 added the Priority:1 Work that is critical for the release, but we could probably ship without label Jan 13, 2025
@maraf maraf self-assigned this Jan 16, 2025
@maraf maraf linked a pull request Jan 16, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. Priority:1 Work that is critical for the release, but we could probably ship without
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants