Skip to content

Commit 98bf432

Browse files
[release/10.0.1xx] [Blazor][HotReload] Include refresh script for enhanced navigation (#50580)
Co-authored-by: Marek Fišera <[email protected]>
1 parent c0df0ff commit 98bf432

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/BuiltInTools/BrowserRefresh/BrowserRefreshMiddleware.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ internal static bool IsBrowserDocumentRequest(HttpContext context)
164164

165165
if (request.Headers.TryGetValue("Sec-Fetch-Dest", out var values) &&
166166
!StringValues.IsNullOrEmpty(values) &&
167-
!string.Equals(values[0], "document", StringComparison.OrdinalIgnoreCase))
167+
!string.Equals(values[0], "document", StringComparison.OrdinalIgnoreCase) &&
168+
!IsProgressivelyEnhancedNavigation(context.Request))
168169
{
169170
// See https://github.com/dotnet/aspnetcore/issues/37326.
170171
// Only inject scripts that are destined for a browser page.
@@ -188,6 +189,14 @@ internal static bool IsBrowserDocumentRequest(HttpContext context)
188189
return false;
189190
}
190191

192+
private static bool IsProgressivelyEnhancedNavigation(HttpRequest request)
193+
{
194+
// This is an exact copy from https://github.com/dotnet/aspnetcore/blob/bb2d778dc66aa998ea8e26db0e98e7e01423ff78/src/Components/Endpoints/src/Rendering/EndpointHtmlRenderer.Streaming.cs#L327-L332
195+
// For enhanced nav, the Blazor JS code controls the "accept" header precisely, so we can be very specific about the format
196+
var accept = request.Headers.Accept;
197+
return accept.Count == 1 && string.Equals(accept[0]!, "text/html; blazor-enhanced-nav=on", StringComparison.Ordinal);
198+
}
199+
191200
internal void Test_SetEnvironment(string dotnetModifiableAssemblies, string aspnetcoreBrowserTools)
192201
{
193202
_dotnetModifiableAssemblies = dotnetModifiableAssemblies;

0 commit comments

Comments
 (0)