-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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 report: Calling navigate more than once causes 404 error #12853
base: main
Are you sure you want to change the base?
Conversation
|
Hi @Bastian, Welcome, and thank you for contributing to React Router! Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once. You may review the CLA and sign it by adding your name to contributors.yml. Once the CLA is signed, the If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at hello@remix.run. Thanks! - The Remix team |
To make the CLA bot happy. Is this really neccessary for a bug report?
Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳 |
I raised a similar report for Remix over in remix-run/remix#10409 and had narrowed it down to the |
Whoops, I don't know how I missed your already existing issue. At least I can confirm, that it is still an issue in v7 :) A workaround that works (for my use-case) is to prevent double calling using a ref value: const navigate = useNavigate();
const navigating = useRef(false);
useEffect(() => {
if (navigating.current) {
return;
}
void navigate("/somewhere");
navigating.current = true;
}, [navigate]); |
Thank you, it worked for me. I had this problem with the On the other note, I'm curious why did you use |
(https://typescript-eslint.io/rules/no-floating-promises#ignorevoid) |
When calling the
navigate
functions multiple times immediately after the initial rendering in auseEffect
hook, the website shows a 404 error even though the route exists. This does not happen, if the calls to navigate are delayed.This is very likely to happen in dev mode with strict mode enabled, since then React executes the useEffect hook twice. I do not know how to do this with your test template, so to simulate a similar behavior I just called the
navigate
function twice.I did not have this problem with Remix v2.Correction: It also happens with Remix 2.15.2 and all feature flags enabled. But it used to work in older (2.11.1) Remix versions without feature flags. I don't know when exactly it broke.