Skip to content

Commit f14ad7c

Browse files
committed
tmp
1 parent fbe2294 commit f14ad7c

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

src/Components/Server/src/Circuits/RemoteNavigationManager.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ async Task PerformNavigationAsync()
106106
}
107107

108108
await _jsRuntime.InvokeVoidAsync(Interop.NavigateTo, uri, options);
109+
Log.NavigationCompleted(_logger, uri);
110+
}
111+
catch (TaskCanceledException) when (_jsRuntime is RemoteJSRuntime remoteRuntime && !remoteRuntime.IsInitialized)
112+
{
113+
Log.NavigationCanceled(_logger, uri);
114+
return;
109115
}
110116
catch (Exception ex)
111117
{
@@ -190,5 +196,8 @@ public static void RequestingNavigation(ILogger logger, string uri, NavigationOp
190196

191197
[LoggerMessage(5, LogLevel.Error, "Failed to refresh", EventName = "RefreshFailed")]
192198
public static partial void RefreshFailed(ILogger logger, Exception exception);
199+
200+
[LoggerMessage(6, LogLevel.Debug, "Navigation completed when changing the location to {Uri}", EventName = "NavigationCompleted")]
201+
public static partial void NavigationCompleted(ILogger logger, string uri);
193202
}
194203
}

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

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function isSamePageWithHash(absoluteHref: string): boolean {
101101
return hashIndex > -1 && location.href.replace(location.hash, '') === absoluteHref.substring(0, hashIndex);
102102
}
103103

104-
function performScrollToElementOnTheSamePage(absoluteHref : string, replace: boolean, state: string | undefined = undefined): void {
104+
function performScrollToElementOnTheSamePage(absoluteHref: string, replace: boolean, state: string | undefined = undefined): void {
105105
saveToBrowserHistory(absoluteHref, replace, state);
106106

107107
const hashIndex = absoluteHref.indexOf('#');
@@ -158,19 +158,23 @@ function navigateToCore(uri: string, options: NavigationOptions, skipLocationCha
158158
}
159159

160160
function performExternalNavigation(uri: string, replace: boolean) {
161-
if (location.href === uri) {
162-
// If you're already on this URL, you can't append another copy of it to the history stack,
163-
// so we can ignore the 'replace' flag. However, reloading the same URL you're already on
164-
// requires special handling to avoid triggering browser-specific behavior issues.
165-
// For details about what this fixes and why, see https://github.com/dotnet/aspnetcore/pull/10839
166-
const temporaryUri = uri + '?';
167-
history.replaceState(null, '', temporaryUri);
168-
location.replace(uri);
169-
} else if (replace) {
170-
location.replace(uri);
171-
} else {
172-
location.href = uri;
173-
}
161+
// If we are navigating to an external URI, defer setting the URL so that we can
162+
// complete the current navigation operation if the request comes from .NET.
163+
setTimeout(() => {
164+
if (location.href === uri) {
165+
// If you're already on this URL, you can't append another copy of it to the history stack,
166+
// so we can ignore the 'replace' flag. However, reloading the same URL you're already on
167+
// requires special handling to avoid triggering browser-specific behavior issues.
168+
// For details about what this fixes and why, see https://github.com/dotnet/aspnetcore/pull/10839
169+
const temporaryUri = uri + '?';
170+
history.replaceState(null, '', temporaryUri);
171+
location.replace(uri);
172+
} else if (replace) {
173+
location.replace(uri);
174+
} else {
175+
location.href = uri;
176+
}
177+
}, 0);
174178
}
175179

176180
async function performInternalNavigation(absoluteInternalHref: string, interceptedLink: boolean, replace: boolean, state: string | undefined = undefined, skipLocationChangingCallback = false) {

0 commit comments

Comments
 (0)