-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
unstable_Blocker
is making update depth exceeded.
#6704
Comments
I believe the root cause of it is a using a key and setting a key in the useEffect -> https://github.com/remix-run/react-router/blob/843fe0e989b17c484d3cf6b54daf342f7dc65394/packages/react-router/lib/hooks.tsx#L980 |
Introduced by this remix-run/react-router#10573 |
The generation of a net-new function identity is the underlying cause here, since it's triggering a new blocker key generation. I'll look into a fix for this but the workaround for now is to wrap your blocker function in unstable_useBlocker(useCallback(() => false, [])); |
This should be resolved in |
thanks @brophdawg11
Yap, I've missed read the Sorry if this does not make sense but: Why do we have a state for the blocker? React.useEffect(() => {
if (blockerKey !== "") {
// no need to setState since state DataRouterContext will give us any update (if no update IDLE_BLOCKER)
router.getBlocker(blockerKey, blockerFunction);
}
}, [router, blockerFunction]);
// Prefer the blocker from state since DataRouterContext is memoized so this
// ensures we update on blocker state updates
return blockerKey && state.blockers.has(blockerKey) ? state.blockers.get(blockerKey) : IDLE_BLOCKER; Other thing, and to be honest i don't know if would be a good solution: |
Yeah that would probably be fine to remove the The ref I'm less sure about due to the nuances of Strict Mode double rendering. I'd be happy to look over a PR if you wanted to play around with it though! |
Sure. I will open a PR and ping you for you to have a look and see if the problems that you where facing continue. I will ping you in a bit :) |
I endup not making the ref solution because was more an hack than a solution. I believe the one i've create remix-run/react-router#10657 is more interesting Cheers |
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
using react-router-dom 6.21.3 I hit the issue within useBlocker, The behavior is that the first time I go back using browser back button the blocker works as expected even the log |
@devel0 Could you please open a new issue with a reproduction? |
@brophdawg11 did it see mentioned issue above for the repro simplescreenrecorder-2024-01-27_16.49.54.webm |
What version of Remix are you using?
1.18.0
Are all your remix dependencies & dev-dependencies using the same version?
Steps to Reproduce
npx create-remix@latest --template remix-run/indie-stack blog-tutorial
)@remix-run/react
unstable_useBlocker(() => false);
Expected Behavior
The console should be clean without any
Warning: Maximum update depth exceeded.
Actual Behavior
Maximum update depth exceeded.
The text was updated successfully, but these errors were encountered: