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] dotnet watch may not inject aspnetcore-browser-refresh.js after dotnet run #59276

Closed
1 task done
MackinnonBuck opened this issue Dec 3, 2024 · 2 comments · Fixed by #59340
Closed
1 task done
Assignees
Labels
area-blazor Includes: Blazor, Razor Components feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly feature-hot-reload This issue is related to the Hot Reload feaature
Milestone

Comments

@MackinnonBuck
Copy link
Member

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

dotnet watch may not inject the aspnetcore-browser-refresh.js script for Blazor WebAssesmbly standalone apps. This is because the cached result of index.html gets used, and this bypasses the script injection middleware.

For example, if you run a default Blazor WebAssembly standalone app first using dotnet run, then the response for index.html will not include the browser refresh script (which is expected). Subsequently running dotnet watch will result in that same index.html getting used (without the injected script). Clearing the browser cache results in the script injection middleware re-running, and hot reload will work as expected.

Note that:

  • This bug does not affect Blazor Web Apps
  • This does repro when running a .NET 8 app using either the .NET 9 or .NET 8 SDK.

Expected Behavior

Caching does not interfere with hot reload script injection, and dotnet watch works regardless of whether dotnet run was executed prior to it.

Steps To Reproduce

  1. dotnet new blazorwasm
  2. dotnet run
  3. Open the app in the browser
  4. Stop the app (ctrl+c)
  5. dotnet watch
  6. Open the app in the browser again
  7. Observe that hot reload does not work
  8. Observe that the aspnetcore-browser-refresh.js script was not injected into the document
  9. Clear the browser's cache (Dev Tools -> Application -> Clear site data)
  10. Refresh the page
  11. Observe that the aspnetcore-browser-refresh.js script was injected into the document

Exceptions (if any)

No response

.NET Version

9.0.200-preview.0.24529.19

Anything else?

Was also able to repro using .NET SDK version 8.0.404.

Output of dotnet --info
.NET SDK:
 Version:           9.0.200-preview.0.24529.19
 Commit:            3980fbc52d
 Workload version:  9.0.200-manifests.c6f19616
 MSBuild version:   17.13.0-preview-24529-12+ee511a938

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22631
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\9.0.200-preview.0.24529.19\

.NET workloads installed:
 [tvos]
   Installation Source: VS 17.13.35517.34
   Manifest Version:    18.0.9617/9.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.tvos\18.0.9617\WorkloadManifest.json
   Install Type:              Msi

 [macos]
   Installation Source: VS 17.13.35517.34
   Manifest Version:    15.0.9617/9.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.macos\15.0.9617\WorkloadManifest.json
   Install Type:              Msi

 [maui-windows]
   Installation Source: VS 17.13.35517.34
   Manifest Version:    9.0.0/9.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.maui\9.0.0\WorkloadManifest.json
   Install Type:              Msi

 [maccatalyst]
   Installation Source: VS 17.13.35517.34
   Manifest Version:    18.0.9617/9.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.maccatalyst\18.0.9617\WorkloadManifest.json
   Install Type:              Msi

 [ios]
   Installation Source: VS 17.13.35517.34
   Manifest Version:    18.0.9617/9.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.ios\18.0.9617\WorkloadManifest.json
   Install Type:              Msi

 [android]
   Installation Source: VS 17.13.35517.34
   Manifest Version:    35.0.7/9.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.android\35.0.7\WorkloadManifest.json
   Install Type:              Msi

 [wasm-tools-net6]
   Installation Source: VS 17.13.35517.34
   Manifest Version:    9.0.0/9.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.workload.mono.toolchain.net6\9.0.0\WorkloadManifest.json
   Install Type:              Msi

 [wasm-tools-net7]
   Installation Source: VS 17.13.35517.34
   Manifest Version:    9.0.0/9.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.workload.mono.toolchain.net7\9.0.0\WorkloadManifest.json
   Install Type:              Msi

 [wasm-tools-net8]
   Installation Source: VS 17.13.35517.34
   Manifest Version:    9.0.0/9.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.workload.mono.toolchain.net8\9.0.0\WorkloadManifest.json
   Install Type:              Msi

 [wasm-tools]
   Installation Source: VS 17.13.35517.34
   Manifest Version:    9.0.0/9.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.workload.mono.toolchain.current\9.0.0\WorkloadManifest.json
   Install Type:              Msi

 [aspire]
   Installation Source: VS 17.13.35517.34
   Manifest Version:    8.2.2/8.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.2.2\WorkloadManifest.json
   Install Type:              Msi

Configured to use loose manifests when installing new manifests.

Host:
  Version:      9.0.0
  Architecture: x64
  Commit:       9d5a6a9aa4

.NET SDKs installed:
  8.0.404 [C:\Program Files\dotnet\sdk]
  9.0.100 [C:\Program Files\dotnet\sdk]
  9.0.200-preview.0.24529.19 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.35 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.0-rc.2.24474.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.35 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.0-rc.2.24473.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.35 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.0-rc.2.24474.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download
@MackinnonBuck MackinnonBuck added area-blazor Includes: Blazor, Razor Components feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly feature-hot-reload This issue is related to the Hot Reload feaature labels Dec 3, 2024
@javiercn
Copy link
Member

javiercn commented Dec 3, 2024

@MackinnonBuck thanks for the thorough report.

I imagine this doesn't happen with .NET 9.0 apps?
I also imagine that doing a hard refresh with CTRL+F5 will also work?

Also, is it fair to say that this is not a new thing, but something that has happened since we added the feature? (Since I imagine this is caused by the lack of proper cache-control headers).

@MackinnonBuck
Copy link
Member Author

I imagine this doesn't happen with .NET 9.0 apps?

This actually does repro with .NET 9 apps (Blazor WebAssembly standalone). In both .NET 8 and .NET 9, the Cache-Control header has the value max-age=0.

I also imagine that doing a hard refresh with CTRL+F5 will also work?

Yeah, ctrl+F5 also works

Also, is it fair to say that this is not a new thing, but something that has happened since we added the feature?

I'm not sure how far back the bug goes - I haven't tried it on .NET 6/7 yet.

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 feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly feature-hot-reload This issue is related to the Hot Reload feaature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants