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] JS initializers declared in RCLs run twice #57087

Closed
MackinnonBuck opened this issue Jul 30, 2024 · 5 comments
Closed

[Blazor] JS initializers declared in RCLs run twice #57087

MackinnonBuck opened this issue Jul 30, 2024 · 5 comments
Assignees
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug.
Milestone

Comments

@MackinnonBuck
Copy link
Member

Summary

JS initializers declared in a Razor Class Libraries have each of their callbacks executed twice.

Steps to reproduce

  1. Install versions 8.0.303 and 9.0.100-preview.6.24328.19 of the .NET SDK
  2. Run dotnet new blazor -int None -o ./BlazorApp -f net8.0
  3. Run dotnet new razorclasslib -o ./RazorClassLibrary -f net8.0
  4. Run dotnet add ./BlazorApp/BlazorApp.csproj reference ./RazorClassLibrary/RazorClassLibrary.csproj
  5. Create the file ./RazorClassLibrary/wwwroot/RazorClassLibrary.lib.module.js and add the following content:
    export function afterWebStarted() {
        console.log('Hello, world!');
    }
  6. Run dotnet run --project .\BlazorApp\BlazorApp.csproj
  7. Observe that the browser console window logged "Hello, world!" twice
  8. Run dotnet new globaljson --sdk-version 8.0.303
  9. Run dotnet run --project .\BlazorApp\BlazorApp.csproj
  10. 🟢 Observe that the browser console window now only logs "Hello, world!" once

Other notes

  1. This issue also occurs when creating projects with a net9.0 TFM
  2. The .NET 8 SDK is not required to reproduce the bug - it was included in the repro steps only to demonstrate that the issue is unique to the .NET 9 SDK.
@MackinnonBuck MackinnonBuck added the area-blazor Includes: Blazor, Razor Components label Jul 30, 2024
@javiercn
Copy link
Member

@MackinnonBuck is this an 8.0 app compiled with the 9.0 SDK?

@MackinnonBuck
Copy link
Member Author

@javiercn yes, but it also reproduces for a 9.0 app as well.

@javiercn
Copy link
Member

@MackinnonBuck but it does not reproduce with a net 8.0 SDK, isn't it? (It's surprising that our tests didn't catch this)

@MackinnonBuck
Copy link
Member Author

@javiercn yes, that's correct

@javiercn javiercn added the bug This issue describes a behavior which is not expected - a bug. label Jul 31, 2024
@javiercn javiercn added this to the 9.0-rc1 milestone Jul 31, 2024
@MackinnonBuck
Copy link
Member Author

No longer reproduces in the latest SDK build.

It looks like dotnet/sdk#41995 was the culprit, and this is now fixed.

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.
Projects
None yet
Development

No branches or pull requests

2 participants