Skip to content

Commit 2bf0fe9

Browse files
authored
Update window.history before setting updated React state on navigations (#10448)
* fix window.location is not equal to useLocation() * Update contributors.yml
1 parent f353a6f commit 2bf0fe9

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

.changeset/big-vans-act.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@remix-run/router": patch
3+
"react-router-dom": patch
4+
---
5+
6+
Fix window.location is not equal to useLocation()

contributors.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,4 @@
215215
- yionr
216216
- yuleicul
217217
- zheng-chuang
218+
- holynewbie

packages/router/router.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,16 @@ export function createRouter(init: RouterInit): Router {
10081008
inFlightDataRoutes = undefined;
10091009
}
10101010

1011+
if (isUninterruptedRevalidation) {
1012+
// If this was an uninterrupted revalidation then do not touch history
1013+
} else if (pendingAction === HistoryAction.Pop) {
1014+
// Do nothing for POP - URL has already been updated
1015+
} else if (pendingAction === HistoryAction.Push) {
1016+
init.history.push(location, location.state);
1017+
} else if (pendingAction === HistoryAction.Replace) {
1018+
init.history.replace(location, location.state);
1019+
}
1020+
10111021
updateState({
10121022
...newState, // matches, errors, fetchers go through as-is
10131023
actionData,
@@ -1025,16 +1035,6 @@ export function createRouter(init: RouterInit): Router {
10251035
blockers: new Map(state.blockers),
10261036
});
10271037

1028-
if (isUninterruptedRevalidation) {
1029-
// If this was an uninterrupted revalidation then do not touch history
1030-
} else if (pendingAction === HistoryAction.Pop) {
1031-
// Do nothing for POP - URL has already been updated
1032-
} else if (pendingAction === HistoryAction.Push) {
1033-
init.history.push(location, location.state);
1034-
} else if (pendingAction === HistoryAction.Replace) {
1035-
init.history.replace(location, location.state);
1036-
}
1037-
10381038
// Reset stateful navigation vars
10391039
pendingAction = HistoryAction.Pop;
10401040
pendingPreventScrollReset = false;

0 commit comments

Comments
 (0)