Skip to content

Commit a4dafc5

Browse files
authored
[automated] Merge branch 'release/10.0.1xx' => 'main' (#50587)
2 parents cdf3a40 + 7a3cd0c commit a4dafc5

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
@@ -169,7 +169,8 @@ internal static bool IsBrowserDocumentRequest(HttpContext context)
169169

170170
if (request.Headers.TryGetValue("Sec-Fetch-Dest", out var values) &&
171171
!StringValues.IsNullOrEmpty(values) &&
172-
!string.Equals(values[0], "document", StringComparison.OrdinalIgnoreCase))
172+
!string.Equals(values[0], "document", StringComparison.OrdinalIgnoreCase) &&
173+
!IsProgressivelyEnhancedNavigation(context.Request))
173174
{
174175
// See https://github.com/dotnet/aspnetcore/issues/37326.
175176
// Only inject scripts that are destined for a browser page.
@@ -193,6 +194,14 @@ internal static bool IsBrowserDocumentRequest(HttpContext context)
193194
return false;
194195
}
195196

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

0 commit comments

Comments
 (0)