fix(back-button): require same-origin referrer before stepping browser history, so fresh-tab Back falls back to the in-app route#1160
Open
pandadev66 wants to merge 1 commit into
Conversation
…r history, so fresh-tab Back falls back to the in-app route
Author
|
@anderdc Could you take a look when you have a moment? Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The shared
BackButtoncomponent used on every detail page (Miner, Repository, PR, Issue, Search) decides whether to step the browser history or fall back to a known in-app route based solely onwindow.history.length > 1. That check isn't a reliable signal that the previous history entry actually belongs to the app — opening a detail page directly in a fresh tab, from a bookmark, or by clicking a shared link from outside the app all leave a non-app entry as the "previous" page, so clicking "Back" callsnavigate(-1)and the user is taken out of the app.This PR tightens the check with the same approach used for the 404 page: require
document.referrerto share the app's origin before stepping back. When the previous entry can't be confirmed in-app, the button falls through to the per-pagetoroute (e.g./top-minersfrom a miner profile,/repositoriesfrom a repo page) that the component already accepts as a fallback.Behavior
history.length > 1AND same-originreferrer) →navigate(-1)— unchanged from today.backTo(set by list pages when they link into a detail page, e.g. "Back to Watchlist") →navigate(state.backTo)— unchanged.navigate(to)— the page-specific in-app fallback the component already takes as a prop. Previously this fell through tonavigate(-1)and left the app.Verification
/miners/details?githubId=<known-id>directly in a brand-new tab (paste the URL into the address bar, or click a link to it from a non-app origin). Click "Back" once — the app should land on/top-minersrather than the browser's previous tab/page./miners/repository?name=…→/repositories,/miners/pr?repo=…&number=…→/repositories,/bounties/details?id=…→/bounties./top-miners). The "Back" button should still callnavigate(-1)and return to the exact list state, including any filters or scroll the page restores from router state.backToin router state (e.g. "Back to Watchlist") and confirm the button still routes to that destination when the in-app history signal isn't trusted.Why this approach
toprop already exists on every caller (it's required), so there's no new copy or routing config to keep in sync — the fix uses what's already there.Recording
84.mp4
Fixes #1162