-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
fix(remix-react): avoid duplicate loader
calls when using prefetch-intent
#2938
Conversation
d65159d
to
23a5719
Compare
@@ -185,7 +185,29 @@ test.describe("prefetch=intent (hover)", () => { | |||
"#nav link[rel='modulepreload'][href^='/build/routes/without-loader-']", | |||
{ state: "attached" } | |||
); | |||
expect(await page.locator("#nav link").count()).toBe(3); | |||
expect(await page.locator("#nav link").count()).toBe(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ryanflorence Now that we setShouldPrefetch(false)
in cancelIntent
these tests are invalid since the link tags remove - just confirming that's expected 👍
loader
calls when using prefetch-intent
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
This fixes a nuanced issue when using
<Link prefetch="intent" />
due to prefetch cache behavior. Subsequent<link rel="prefetch">
elements to the same locations as previous prefetch elements will not leverage prior prefetch cache entries unless the endpoint returned acache-control
header. Couldn't find much official docs on this, but GoogleChromeLabs/quicklink#21 (comment) was the most relevant bit I found.So, in the scenario described by #1249 when a loader does not return
cache-control
, the behavior ended up being:/users/1
/users/1
which has nocache-control
header/users/1
/users/1
/users/2
/users/1
since it was still in ashouldPrefetch
state from it's prior hover and is no longer activeThis PR updates it such that
shouldPrefetch
is unset upon navigating to the link in question, thus requiring another hover/focus intent to re-add<link rel="prefetch">
elements. If developers wish to avoid subsequent hits to their loaders on those calls they should leverage acache-control
header which will be respected by the prefetch links.Closes #1249