Skip to content

Commit

Permalink
fix window.location is not equal to useLocation()
Browse files Browse the repository at this point in the history
  • Loading branch information
holynewbie committed May 4, 2023
1 parent 4ccdc11 commit 3347921
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,4 @@
- yuleicul
- zheng-chuang
- Ivanrenes
- holynewbie
20 changes: 10 additions & 10 deletions packages/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,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 @@ -1019,16 +1029,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 3347921

Please sign in to comment.