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]: redundant loader invocation when using prefetch="intent" #1249

Closed
acd02 opened this issue Dec 26, 2021 · 7 comments · Fixed by #2938
Closed

[Bug]: redundant loader invocation when using prefetch="intent" #1249

acd02 opened this issue Dec 26, 2021 · 7 comments · Fixed by #2938
Labels
bug Something isn't working

Comments

@acd02
Copy link

acd02 commented Dec 26, 2021

What version of Remix are you using?

1.1.1

What version of Node are you using? Minimum supported version is 14.

14

Steps to Reproduce

  1. Visit this repro -> https://stackblitz.com/edit/node-huqahk
  2. go to "users" page (you'll see a list of "users" displayed) (url: /users)
  3. click on a a name to see some user details (url: /users/$userId)
    • check out the console, you'll see that a http call has been made to fetch the user details
  4. now, click on an another user name
    • check out the console, you'll see that a http call has been made to fetch the new user details
    • but another call has been made, with the previous id

Expected Behavior

When switching to a different user (url: /users/$userId), I expect the loader (app/routes/users/$userId.tsx) to be called only once, not twice

Actual Behavior

When switching to a different user (url: /users/$userId), the loader (app/routes/users/$userId.tsx) is called twice:

  • one time to fetch the current user details
  • and a second time with the previous user id
  • as mentioned in the title, this phenomenon occurs only when the link has its prefetch attribute set to "intent" (or "render" for that matter)

📽 video

Kapture 2021-12-27 at 18 20 40

@acd02 acd02 added the bug Something isn't working label Dec 26, 2021
@kennethvdberghe
Copy link

Somehow it has to do with the prefetch="intent" on the Links. As soon as that is added, there are indeed calls to both the current and previous loaders 🤔

@acd02 acd02 changed the title [Bug]: redundant loader invocation inside nested route [Bug]: redundant loader invocation when using prefetch="intent" Dec 29, 2021
@acd02
Copy link
Author

acd02 commented Dec 29, 2021

@kennethvdberghe , you're right 👍
I've updated the issue title accordingly

@brophdawg11
Copy link
Contributor

Thanks for the reproduction @acd02! I just pushed a fix for this in #2938 (prefetch=intent only for now) so this should be resolved once we get that merged. But in the meantime if you wanted you could avoid this double-hit using a cache-control header on your loader if the information is safe to cache for a short period

@brophdawg11
Copy link
Contributor

@acd02 This should be fixed in the next release. There should also be a nightly release going out tonight that you could test this out on ahead of the next release if you wanted to

@github-actions
Copy link
Contributor

🤖 Hello there,

We just published version v0.0.0-nightly-9e5cd6d-20220517 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!

@kennethvdberghe
Copy link

Seems to fix this issue indeed, looks like the reproduction is not calling previous loaders anymore. 🎉

@github-actions
Copy link
Contributor

🤖 Hello there,

We just published version v1.5.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 their assignment Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants