Skip to content

Commit

Permalink
Update window.history before setting updated React state on navigatio…
Browse files Browse the repository at this point in the history
…ns (#10448)

* fix window.location is not equal to useLocation()

* Update contributors.yml
  • Loading branch information
holynewbie committed Jun 2, 2023
1 parent f353a6f commit 2bf0fe9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .changeset/big-vans-act.md
@@ -0,0 +1,6 @@
---
"@remix-run/router": patch
"react-router-dom": patch
---

Fix window.location is not equal to useLocation()
1 change: 1 addition & 0 deletions contributors.yml
Expand Up @@ -215,3 +215,4 @@
- yionr
- yuleicul
- zheng-chuang
- holynewbie
20 changes: 10 additions & 10 deletions packages/router/router.ts
Expand Up @@ -1008,6 +1008,16 @@ export function createRouter(init: RouterInit): Router {
inFlightDataRoutes = undefined;
}

if (isUninterruptedRevalidation) {
// If this was an uninterrupted revalidation then do not touch history
} else if (pendingAction === HistoryAction.Pop) {
// Do nothing for POP - URL has already been updated
} else if (pendingAction === HistoryAction.Push) {
init.history.push(location, location.state);
} else if (pendingAction === HistoryAction.Replace) {
init.history.replace(location, location.state);
}

updateState({
...newState, // matches, errors, fetchers go through as-is
actionData,
Expand All @@ -1025,16 +1035,6 @@ export function createRouter(init: RouterInit): Router {
blockers: new Map(state.blockers),
});

if (isUninterruptedRevalidation) {
// If this was an uninterrupted revalidation then do not touch history
} else if (pendingAction === HistoryAction.Pop) {
// Do nothing for POP - URL has already been updated
} else if (pendingAction === HistoryAction.Push) {
init.history.push(location, location.state);
} else if (pendingAction === HistoryAction.Replace) {
init.history.replace(location, location.state);
}

// Reset stateful navigation vars
pendingAction = HistoryAction.Pop;
pendingPreventScrollReset = false;
Expand Down

0 comments on commit 2bf0fe9

Please sign in to comment.