Skip to content

Commit bf73e6e

Browse files
authored
Log when an enhanced navigation fails (#62598)
* Added warning when enhanced navigation falls back to full page reload + test * tests fix
1 parent e93c889 commit bf73e6e

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/Components/Web.JS/src/Services/NavigationEnhancement.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ function enhancedNavigationIsEnabledForForm(form: HTMLFormElement): boolean {
455455
function retryEnhancedNavAsFullPageLoad(internalDestinationHref: string) {
456456
// The ? trick here is the same workaround as described in #10839, and without it, the user
457457
// would not be able to use the back button afterwards.
458+
console.warn(`Enhanced navigation failed for destination ${internalDestinationHref}. Falling back to full page load.`);
458459
history.replaceState(null, '', internalDestinationHref + '?');
459460
location.replace(internalDestinationHref);
460461
}

src/Components/test/E2ETest/ServerRenderingTests/EnhancedNavigationTest.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ public void CanNavigateToNonHtmlResponse()
7373
Navigate($"{ServerPathBase}/nav");
7474
Browser.Exists(By.TagName("nav")).FindElement(By.LinkText("Non-HTML page")).Click();
7575
Browser.Equal("Hello, this is plain text", () => Browser.Exists(By.TagName("html")).Text);
76+
77+
//Check if the fall back because of the non-html response sends a warning
78+
var logs = Browser.GetBrowserLogs(LogLevel.Warning);
79+
Assert.Contains(logs, log => log.Message.Contains("Enhanced navigation failed for destination") && log.Message.Contains("Falling back to full page load.") && !log.Message.Contains("Error"));
7680
}
7781

7882
[Fact]
@@ -465,6 +469,11 @@ public void EnhancedNavNotUsedForNonBlazorDestinations()
465469
Browser.Exists(By.TagName("nav")).FindElement(By.LinkText("Non-Blazor HTML page")).Click();
466470
Browser.Equal("This is a non-Blazor endpoint", () => Browser.Exists(By.TagName("h1")).Text);
467471
Assert.Equal("undefined", Browser.ExecuteJavaScript<string>("return typeof Blazor")); // Blazor JS is NOT loaded
472+
473+
//Check if the fall back because of the non-blazor endpoint navigation sends a warning
474+
var logs = Browser.GetBrowserLogs(LogLevel.Warning);
475+
Assert.Contains(logs, log => log.Message.Contains("Enhanced navigation failed for destination") && log.Message.Contains("Falling back to full page load.") && !log.Message.Contains("Error"));
476+
468477
}
469478

470479
[Theory]

0 commit comments

Comments
 (0)