-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
[Bug]: Getting "A router only supports one blocker at a time" warning when running your navigation-blocking example #11430
Comments
Hi, If a new router is recreated while a useBlocker is "active/mounted", it is not reseted properly. Thanks for your help in fixing this. |
I've been seeing this same issue for a while now, but after updating to react-router-dom v6.23.0 today I haven't seen it again. Can anyone else confirm that this issue is fixed in 6.23.0? |
@JasonDyke it is still happening to me in |
Same issue still exists on 6.23.0. |
Same issue for me on 6.23.0. In fact, it also really prevents navigation for me. The last version which worked for me was 6.13.0 - all versions since then breaks navigation after form submission for me. |
Same issue still exists on 6.23.0. |
Not sure if this is a valid solution, but I notice in the example: if (import.meta.hot) {
import.meta.hot.dispose(() => router.dispose());
} ...seems to resolve the warning for me |
I see that the import.meta.hot.dispose(...) function is called in the example, but it doesn't solve the issue because you still get the "A router only supports one blocker at a time" message in the browser dev console if you follow the steps mentioned in the original post above. (Just re-tested it with version 6.24.0). Also, this could only be a potential solution for when in development mode and because the issue also is present when "a new router is recreated while a useBlocker is "active/mounted"" (as mentioned above as well) it's not a valid solution imho. |
We have the same issue, because our routes depend on a state and recreate the router whenever this state changes. As a temporary fix, we create the router only when the module is loaded and pass route updates via |
same problem here, with react-router 6.26.1: if I change something in code (with hot-reload in Browser) while a useBlocker is mounted, the warning "A router only supports one blocker at a time" is printed. => the conclusion of @simonbaas seems to be the most reasonable related to my issue. And no, it's not a solution to dispose the router on hot reload like mentioned above. |
I have same problem. After hot reload while in page with active What I figured out is that my const isMountedRef = useRef<boolean>();
useEffect(() => {
isMountedRef.current = true;
return () => {
isMountedRef.current = false;
};
}, []);
const shouldBlock = useCallback<BlockerFunction>(
({ currentLocation, nextLocation }) => {
return (
isMountedRef.current &&
currentLocation.pathname !== nextLocation.pathname
// your other blocking conditions here
);
},
[state],
);
const blocker = useBlocker(shouldBlock); That doesn't solve the warning though |
What version of React Router are you using?
6.22.3
Steps to Reproduce
Expected Behavior
Not getting the warning. Any blocker should be disposed/cleaned up correctly.
Actual Behavior
Getting warning "A router only supports one blocker at a time" in console.
I'm seeing this issue in real world case as well, even if useBlocker is only called once in the entire app. It the component which calls useBlocker is "mounted" (in lack of better term) and the router is re-created higher up it seems like the old blocker is not disposed/removed/cleanup correctly.
The text was updated successfully, but these errors were encountered: