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

clientLoader revalidate even though shouldRevalidate returns false #12607

Open
prxg22 opened this issue Dec 21, 2024 · 5 comments
Open

clientLoader revalidate even though shouldRevalidate returns false #12607

prxg22 opened this issue Dec 21, 2024 · 5 comments
Labels

Comments

@prxg22
Copy link

prxg22 commented Dec 21, 2024

I'm using React Router as a...

framework

Reproduction

  1. Go to this stackblitz
  2. On the reproduction browser, navigate to /main/view
  3. Click the toggle theme button
  4. Check the child clientLoader count increase

System Info

System:
    OS: macOS 14.6.1
    CPU: (8) arm64 Apple M1
    Memory: 129.34 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.18.1 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.8.2 - /usr/local/bin/npm
    pnpm: 8.15.7 - /usr/local/bin/pnpm
  Browsers:
    Chrome: 131.0.6778.205
    Safari: 17.6
  npmPackages:
    @react-router/dev: ^7.1.0 => 7.1.0 
    @react-router/node: ^7.1.0 => 7.1.0 
    @react-router/serve: ^7.1.0 => 7.1.0 
    react-router: ^7.1.0 => 7.1.0 
    vite: ^5.4.11 => 5.4.11

Used Package Manager

npm

Expected Behavior

As reported in remix-run/remix#10234, single fetch feature introduced an unexpected behavior on clientLoader revalidation when using ssr = false strategy.

When a child route's shouldRevalidate function returns false, I expected that this route's clientLoader would not be triggered after a fetcher's submission in a parent route.

In my example / route has a fetcher.Form, that when submitted, should run its clientAction and revalidate that route's clientLoader, but routes /main and /main/view should not be revalidate, since their shouldRevalidate function will return false for that form submission.

Actual Behavior

After a fetcher submission in a parent route, child clientLoaders are being revalidated, even though their route's shouldRevalidate returns false.

In my example, you can check /main and /main/view counters increasing after each action dispatched by the parent route's fetcher.

@prxg22 prxg22 added the bug label Dec 21, 2024
@aland-x
Copy link

aland-x commented Dec 22, 2024

Reported this also in #12551 unfortunately I think @timdorr misunderstood the issue. I hope this makes it more clear.

@lukejagodzinski
Copy link

I have exactly same issue. I think it was fine in RR 7.0 but got broken in 7.1. However, my use case was a little bit different. In RR 7.0, when action failed with error 422 or whatever other 4XX, it didn't revalidate. Now it revalidates. So I thought I will fix it with the shouldRevalidate and then I discover this bug and I see I'm not the only one. The question also is, should it revalidate on error? I think, I heard in one of the streams that it will not revalidate on action error but I'm not sure in what version it's gonna be implemented

@matheuscscp
Copy link

@timdorr Can you please look into this? 🙏 😸

@lukejagodzinski
Copy link

I've just checked code and in deed it shouldn't revalidate on 4XX or 5XX. You can see it here:

let actionStatus = pendingActionResult
? pendingActionResult[1].statusCode
: undefined;
let shouldSkipRevalidation = actionStatus && actionStatus >= 400;

@prxg22
Copy link
Author

prxg22 commented Jan 12, 2025

@lukejagodzinski according to this doc, it should not revalidate if you throw or return a 4xx/5xx Response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants