-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
@remix-run/router
: Add support for navigation blocking
#9709
Changes from 1 commit
0cc6142
3c8606c
04a8c8f
2497c02
cbad7dc
5d98596
8e0a8d0
0eedecf
8c4ef44
82a8267
226eb08
0b24b3c
c5f0384
12d8860
5d04b58
4a5ce97
70c4e86
f2ff193
6823f58
3545cdc
f56ab7d
e34bde0
5a81d17
934692f
7285473
8cfc7d3
d2f05a1
12f6daa
bb1bb0a
50d7c80
139974d
e6cbdbb
a943da9
65bba99
23d3aac
2859b13
ba5c76d
6fba7e5
f4d6b00
e25325e
27568f7
fa00b37
546e3ac
76e7fde
2334a5b
b507993
e1426d0
16e464f
b9739ba
28da8cb
b29b5e0
887314a
6f15186
7749172
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,9 @@ export interface Update { | |
*/ | ||
location: Location; | ||
|
||
/** | ||
* The delta between this location and the former location in the history stack | ||
*/ | ||
delta: number; | ||
} | ||
|
||
|
@@ -615,8 +618,8 @@ function getUrlBasedHistory( | |
if (nextIndex != null) { | ||
let delta = nextIndex - index; | ||
action = nextAction; | ||
index = nextIndex; | ||
if (listener) { | ||
index = nextIndex; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should always be updating this even if no one is listening - never showed up as an issue since we always have a |
||
listener({ action, location: history.location, delta }); | ||
} | ||
} else { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1112,15 +1112,6 @@ export function createRouter(init: RouterInit): Router { | |
return; | ||
} | ||
|
||
// Short circuit if navigation is blocked | ||
if ( | ||
Array.from(state.blockers).some(([_, blocker]) => { | ||
return blocker.state === "blocked"; | ||
}) | ||
) { | ||
return; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think his is leftover form very early. Our entry points are |
||
// Short circuit if it's only a hash change | ||
if (isHashChangeOnly(state.location, location)) { | ||
completeNavigation(location, { matches }); | ||
|
@@ -2127,6 +2118,8 @@ export function createRouter(init: RouterInit): Router { | |
function updateBlocker(key: string, newBlocker: Blocker) { | ||
let blocker = state.blockers.get(key) || IDLE_BLOCKER; | ||
|
||
// Poor mans state machine :) | ||
// https://mermaid.live/edit#pako:eNqVkc9OwzAMxl8l8nnjAYrEtDIOHEBIgwvKJTReGy3_lDpIqO27k6awMG0XcrLlnz87nwdonESogKXXBuE79rq75XZO3-yHds0RJVuv70YrPlUrCEe2HfrORS3rubqZfuhtpg5C9wk5tZ4VKcRUq88q9Z8RS0-48cE1iHJkL0ugbHuFLus9L6spZy8nX9MP2CNdomVaposqu3fGayT8T8-jJQwhepo_UtpgBQaDEUom04dZhAN1aJBDlUKJBxE1ceB2Smj0Mln-IBW5AFU2dwUiktt_2Qaq2dBfaKdEup85UV7Yd-dKjlnkabl2Pvr0DTkTreM | ||
invariant( | ||
(blocker.state === "unblocked" && newBlocker.state === "blocked") || | ||
(blocker.state === "blocked" && newBlocker.state === "blocked") || | ||
|
@@ -3673,5 +3666,4 @@ function getTargetMatch( | |
let pathMatches = getPathContributingMatches(matches); | ||
return pathMatches[pathMatches.length - 1]; | ||
} | ||
|
||
//#endregion |
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.
Moved this to a separate component so this wouldn't blow up on
blocker.location.pathname
when in an unblocked state. everything got evaluated in the above key lookup approach.