From 4b277b8dc9aafbe16ecef2401fd1d5d5ea425a31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 10 Jan 2025 10:08:57 +0100 Subject: [PATCH 1/2] Incorporate changes from https://github.com/dotnet/aspnetcore/pull/59340 --- src/mono/wasm/host/DevServer/DevServerStartup.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/mono/wasm/host/DevServer/DevServerStartup.cs b/src/mono/wasm/host/DevServer/DevServerStartup.cs index 87dfc0eb70f474..38fd525e8d6e8f 100644 --- a/src/mono/wasm/host/DevServer/DevServerStartup.cs +++ b/src/mono/wasm/host/DevServer/DevServerStartup.cs @@ -67,7 +67,6 @@ public static void Configure(IApplicationBuilder app, IOptions ServeUnknownFileTypes = true, }); - app.UseRouting(); app.UseWebSockets(); if (options.OnConsoleConnected is not null) @@ -100,6 +99,14 @@ public static void Configure(IApplicationBuilder app, IOptions { OnPrepareResponse = fileContext => { + // Avoid caching index.html during development. + // When hot reload is enabled, a middleware injects a hot reload script into the response HTML. + // We don't want the browser to bypass this injection by using a cached response that doesn't + // contain the injected script. In the future, if script injection is removed in favor of a + // different mechanism, we can delete this comment and the line below it. + // See also: https://github.com/dotnet/aspnetcore/issues/45213 + fileContext.Context.Response.Headers[HeaderNames.CacheControl] = "no-store"; + if (options.WebServerUseCrossOriginPolicy) { // Browser multi-threaded runtime requires cross-origin policy headers to enable SharedArrayBuffer. From 54e492deb12a4bd675c0f044a4cd521eeceb32b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 10 Jan 2025 10:45:46 +0100 Subject: [PATCH 2/2] Add using --- src/mono/wasm/host/DevServer/DevServerStartup.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mono/wasm/host/DevServer/DevServerStartup.cs b/src/mono/wasm/host/DevServer/DevServerStartup.cs index 38fd525e8d6e8f..5df2eabcaa8606 100644 --- a/src/mono/wasm/host/DevServer/DevServerStartup.cs +++ b/src/mono/wasm/host/DevServer/DevServerStartup.cs @@ -12,6 +12,7 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using Microsoft.Net.Http.Headers; using Microsoft.WebAssembly.AppHost; namespace Microsoft.WebAssembly.AppHost.DevServer;