-
-
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
Fix issue with reused blockers on subsequent navigations #10656
Conversation
🦋 Changeset detectedLatest commit: 599d2fc The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@@ -939,7 +939,6 @@ export function useBlocker(shouldBlock: boolean | BlockerFunction): Blocker { | |||
let state = useDataRouterState(DataRouterStateHook.UseBlocker); | |||
|
|||
let [blockerKey, setBlockerKey] = React.useState(""); | |||
let [blocker, setBlocker] = React.useState<Blocker>(IDLE_BLOCKER); |
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.
Per remix-run/remix#6704 (comment), it was pointed out that we don't even need the blocker in local state anymore. We prefer the state.blockers
value anyway as the source of truth that updates via DataRouterStateContext
and we can just fallback on IDLE_BLOCKER
instead of syncing router state into local state.
let blockers = state.blockers; | ||
if (blockers.size > 0) { | ||
blockers = new Map(blockers); | ||
blockers.forEach((_, k) => blockers.set(k, IDLE_BLOCKER)); | ||
} |
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.
Deleting the blockers here was incorrect if they existed in a reused layout route. Instead we just want to set them back to IDLE_BLOCKER
and let the useBlocker
useEffect
handle deletion on unmount
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
Our approach for clearing blockers after a successful navigation was incorrect for blockers that were reused in a layout route.
Closes #10649