-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Fix 'back' button following navigation to external URL. Fixes #10732 #10839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
// triggering browser-specific behavior issues. | ||
// For details about what this fixes and why, see https://github.com/aspnet/AspNetCore/pull/10839 | ||
const temporaryUri = uri + '?'; | ||
history.replaceState(null, '', temporaryUri); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Does this run in to the same issue if you hit go back + forward + back?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my experiments, that sequence of actions worked fine after this fix.
The fix causes the temporary client-side history entry to get replaced with a regular server-side one, so all back-or-forward sequences cause a full page load when you go across that barrier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that I've only been trying this on desktop browsers, and only in the specific case where it's about navigation to an external URL.
I don't think it's likely to cause regressions in any other case, since the new code path only applies when you're doing a force-load to the same URL you're already on, which is extremely unlikely to be something you're doing in any other case/
Would we want to address this in preview6? We could do a QB bar check at the very least (cc @danroth27 \ @mkArtakMSFT) |
I agree this definitely warrants consideration for inclusion in preview 6, hence getting this PR ready immediately. |
6c528ac
to
dbbfe60
Compare
90baf32
to
056db04
Compare
FYI @wtgodbe @mmitche here is another aspnet P6 QB-approved change. @javiercn @SteveSandersonMS Ping me when PR checks are green and I can merge. |
Code check failed:
@SteveSandersonMS @natemcmaster @javiercn what's needed to fix this? |
Updating some baseline. I'm running the code right now |
056db04
to
0619bd1
Compare
@natemcmaster we're good to go! |
Is #10842 fixed with this change? |
@guidevnet No, that's unrelated. |
@SteveSandersonMS Ok, thanks. |
Reported here: #10732 (comment)
This issue first appeared in preview 6 via #10062
It particularly affects the new auth UIs in preview 6, since many of them involve navigating to external URLs. Example: User clicks 'log in', goes to login screen, presses 'back' because they don't really want to log in, nothing happens.
Technical details
The way we handle external navigations is:
This leads to browser-specific behavioral differences:
Between these, Firefox's behavior is more useful for our scenario, because:
To handle this, the only cross-browser-consistent mechanism I've found is to replace the current history entry with a bogus one (literally any relative URL), then use
location.replace
to replace that with the real one. Since it's no longer the same URL you're already on, it creates a new history entry flagged as server-side navigation, and since you use location.replace, the bogus one is eliminated from history.Further, to avoid too much visible weirdness in the address bar, we can choose a 'bogus' URL that looks almost identical to the real one, e.g., by appending a
?
character. This never gets sent to the server nor triggers client-side navigation, so it doesn't matter what the exact value is.