Skip to content
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]: fetcher.load revalidate when navigation submit without running revalidate function #11723

Closed
CurryYangxx opened this issue Jun 25, 2024 · 9 comments · Fixed by #11839
Closed
Labels

Comments

@CurryYangxx
Copy link

CurryYangxx commented Jun 25, 2024

What version of React Router are you using?

6.23.0

Steps to Reproduce

The permission loader revalidates without running revalidate function in the config.

I dig into the source code.I found it go into this if condition.The loader was canceled because of action submit in this Component.But I found finally the loader is fulfilled and can get data from fetcher. I think maybe it should be deleted from the cancelledFetcherLoads array.Is there any race condition issue?

else if (cancelledFetcherLoads.includes(key)) {
      // Always revalidate if the fetcher was cancelled
      shouldRevalidate = true;
    }

} else if (cancelledFetcherLoads.includes(key)) {

Expected Behavior

The loader should determine if revalidate through the revalidate function.

Actual Behavior

The loader revalidate when navigation.

@brophdawg11
Copy link
Contributor

Could you put together a minimal reproduction of the issue you're seeing so we can be sure we understand the problematic behavior?

@CurryYangxx
Copy link
Author

CurryYangxx commented Jul 1, 2024

Could you put together a minimal reproduction of the issue you're seeing so we can be sure we understand the problematic behavior?

@brophdawg11 This a sandbox for a demo to reproduce.
https://codesandbox.io/p/devbox/react-router-test-forked-6nmdty?file=%2Fsrc%2Froute%2Fchild.tsx%3A11%2C129

const loadFetcher = useFetcher();
fetcher.load('/loader')

const submitFetcherA = useFetcher();
fetcher.submit('/actionA');

const submitFetcherB = useFetcher();
fetcher.submit('/actionB');

I have one fetch.load and two fetcher.submit in my component, when the first action submit, the loadFetcher will be aborted in interruptActiveLoads and will add the fetcher key into cancelledFetcherLoads. Then the second action submit, the loadfetcher will be revalidated and finally executed successfully, but the cancelledFetcherLoads dosen't delete the key.

So when I trigger navigate first time, because of this line, the fetcher will be revalidate even if I return false in shouldRevalidate function.And finally the cancelledFetcherLoads will be empty in completeNavigation function.

} else if (cancelledFetcherLoads.includes(key)) {

So I think we need to delete the key from cancelledFetcherLoads after loaderFetcher revalidated success.

Also when I quickly click the navigate1 and navigate2 button in the demo, sometimes there is an error in the console.
image

@brophdawg11
Copy link
Contributor

Hm, that link is broken for me:

Screenshot 2024-07-02 at 2 38 26 PM

@CurryYangxx
Copy link
Author

CurryYangxx commented Jul 3, 2024

@brophdawg11 Sorry, now I set the devbox to public access: https://codesandbox.io/p/devbox/react-router-test-forked-6nmdty
you can look into the child.tsx

@CurryYangxx
Copy link
Author

@brophdawg11 Hello. Could you please take a look at this?

@brophdawg11
Copy link
Contributor

Thanks for the repro!

@brophdawg11 brophdawg11 added the awaiting release This issue have been fixed and will be released soon label Jul 25, 2024
@brophdawg11
Copy link
Contributor

This should be resolved by #11839 and available in the next release 👍

Copy link
Contributor

🤖 Hello there,

We just published version 6.26.0-pre.0 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

Copy link
Contributor

github-actions bot commented Aug 1, 2024

🤖 Hello there,

We just published version 6.26.0 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@brophdawg11 brophdawg11 removed the awaiting release This issue have been fixed and will be released soon label Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants