-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
only prefix prefetch cache entries if they vary based on Next-URL
#61235
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
02dcaa7
to
7f73ce6
Compare
15a66e9
to
a1a5802
Compare
Failing test suitesCommit: 7df6f30
Expand output● app dir - not found with default 404 page › should render default 404 with root layout for non-existent page
Read more about building and testing Next.js in contributing.md. |
Stats from current PRDefault Build (Increase detected
|
vercel/next.js canary | vercel/next.js 01-26-fix_erroneous_prefetch_cache_misses | Change | |
---|---|---|---|
buildDuration | 11.6s | 11.8s | |
buildDurationCached | 5.9s | 5s | N/A |
nodeModulesSize | 196 MB | 196 MB | |
nextStartRea..uration (ms) | 427ms | 439ms | N/A |
Client Bundles (main, webpack) Overall increase ⚠️
vercel/next.js canary | vercel/next.js 01-26-fix_erroneous_prefetch_cache_misses | Change | |
---|---|---|---|
3f784ff6-HASH.js gzip | 53.5 kB | 53.5 kB | N/A |
423.HASH.js gzip | 185 B | 181 B | N/A |
68-HASH.js gzip | 29.7 kB | 29.8 kB | |
framework-HASH.js gzip | 45.2 kB | 45.2 kB | ✓ |
main-app-HASH.js gzip | 238 B | 239 B | N/A |
main-HASH.js gzip | 31.9 kB | 31.9 kB | N/A |
webpack-HASH.js gzip | 1.7 kB | 1.7 kB | ✓ |
Overall change | 76.6 kB | 76.7 kB |
Legacy Client Bundles (polyfills)
vercel/next.js canary | vercel/next.js 01-26-fix_erroneous_prefetch_cache_misses | Change | |
---|---|---|---|
polyfills-HASH.js gzip | 31 kB | 31 kB | ✓ |
Overall change | 31 kB | 31 kB | ✓ |
Client Pages
vercel/next.js canary | vercel/next.js 01-26-fix_erroneous_prefetch_cache_misses | Change | |
---|---|---|---|
_app-HASH.js gzip | 194 B | 195 B | N/A |
_error-HASH.js gzip | 182 B | 181 B | N/A |
amp-HASH.js gzip | 502 B | 501 B | N/A |
css-HASH.js gzip | 320 B | 322 B | N/A |
dynamic-HASH.js gzip | 2.5 kB | 2.5 kB | N/A |
edge-ssr-HASH.js gzip | 255 B | 256 B | N/A |
head-HASH.js gzip | 350 B | 349 B | N/A |
hooks-HASH.js gzip | 368 B | 369 B | N/A |
image-HASH.js gzip | 4.2 kB | 4.2 kB | N/A |
index-HASH.js gzip | 257 B | 256 B | N/A |
link-HASH.js gzip | 2.67 kB | 2.67 kB | N/A |
routerDirect..HASH.js gzip | 310 B | 311 B | N/A |
script-HASH.js gzip | 384 B | 383 B | N/A |
withRouter-HASH.js gzip | 306 B | 308 B | N/A |
1afbb74e6ecf..834.css gzip | 106 B | 106 B | ✓ |
Overall change | 106 B | 106 B | ✓ |
Client Build Manifests
vercel/next.js canary | vercel/next.js 01-26-fix_erroneous_prefetch_cache_misses | Change | |
---|---|---|---|
_buildManifest.js gzip | 483 B | 484 B | N/A |
Overall change | 0 B | 0 B | ✓ |
Rendered Page Sizes
vercel/next.js canary | vercel/next.js 01-26-fix_erroneous_prefetch_cache_misses | Change | |
---|---|---|---|
index.html gzip | 527 B | 527 B | ✓ |
link.html gzip | 541 B | 539 B | N/A |
withRouter.html gzip | 523 B | 522 B | N/A |
Overall change | 527 B | 527 B | ✓ |
Edge SSR bundle Size
vercel/next.js canary | vercel/next.js 01-26-fix_erroneous_prefetch_cache_misses | Change | |
---|---|---|---|
edge-ssr.js gzip | 94.4 kB | 94.4 kB | N/A |
page.js gzip | 150 kB | 150 kB | N/A |
Overall change | 0 B | 0 B | ✓ |
Middleware size
vercel/next.js canary | vercel/next.js 01-26-fix_erroneous_prefetch_cache_misses | Change | |
---|---|---|---|
middleware-b..fest.js gzip | 621 B | 624 B | N/A |
middleware-r..fest.js gzip | 151 B | 149 B | N/A |
middleware.js gzip | 47.4 kB | 47.4 kB | N/A |
edge-runtime..pack.js gzip | 1.94 kB | 1.94 kB | ✓ |
Overall change | 1.94 kB | 1.94 kB | ✓ |
Next Runtimes
vercel/next.js canary | vercel/next.js 01-26-fix_erroneous_prefetch_cache_misses | Change | |
---|---|---|---|
app-page-exp...dev.js gzip | 166 kB | 166 kB | ✓ |
app-page-exp..prod.js gzip | 95.4 kB | 95.4 kB | ✓ |
app-page-tur..prod.js gzip | 97.2 kB | 97.2 kB | ✓ |
app-page-tur..prod.js gzip | 91.6 kB | 91.6 kB | ✓ |
app-page.run...dev.js gzip | 136 kB | 136 kB | ✓ |
app-page.run..prod.js gzip | 90.2 kB | 90.2 kB | ✓ |
app-route-ex...dev.js gzip | 22 kB | 22 kB | ✓ |
app-route-ex..prod.js gzip | 14.9 kB | 14.9 kB | ✓ |
app-route-tu..prod.js gzip | 14.9 kB | 14.9 kB | ✓ |
app-route-tu..prod.js gzip | 14.6 kB | 14.6 kB | ✓ |
app-route.ru...dev.js gzip | 21.7 kB | 21.7 kB | ✓ |
app-route.ru..prod.js gzip | 14.6 kB | 14.6 kB | ✓ |
pages-api-tu..prod.js gzip | 9.43 kB | 9.43 kB | ✓ |
pages-api.ru...dev.js gzip | 9.7 kB | 9.7 kB | ✓ |
pages-api.ru..prod.js gzip | 9.43 kB | 9.43 kB | ✓ |
pages-turbo...prod.js gzip | 22.1 kB | 22.1 kB | ✓ |
pages.runtim...dev.js gzip | 22.7 kB | 22.7 kB | ✓ |
pages.runtim..prod.js gzip | 22.1 kB | 22.1 kB | ✓ |
server.runti..prod.js gzip | 49.9 kB | 49.9 kB | ✓ |
Overall change | 924 kB | 924 kB | ✓ |
Diff details
Diff for page.js
Diff too large to display
Diff for 68-HASH.js
Diff too large to display
2ee2f4e
to
fc0db8a
Compare
7f73ce6
to
e50ec2c
Compare
fc0db8a
to
3dd3a08
Compare
e50ec2c
to
85ef571
Compare
4f48914
to
534f837
Compare
85ef571
to
8fbf043
Compare
534f837
to
557dbe8
Compare
557dbe8
to
916576c
Compare
8fbf043
to
50b00d3
Compare
916576c
to
97b6040
Compare
67494f0
to
4936d42
Compare
2a94573
to
b770e4e
Compare
4936d42
to
e2c7fe9
Compare
e2c7fe9
to
cd928f9
Compare
0f77d79
to
8bd70d5
Compare
Next-URL
cd928f9
to
cd9837c
Compare
02c4657
to
c329086
Compare
To ensure that we properly cache data for routes that change based on `Next-URL` (which is used for route interception), this adjusts how we set the `Vary` header to conditionally include `Next-URL`. The `Next-URL` request header only impacts the response for routes that are intercepted. When we detect that path we're handling could be intercepted, we add `Next-URL` to the vary. This signals in #61235 to prefix these cache entries with `nextUrl` if the response might vary based on it. Closes NEXT-2398
040dd13
to
b400940
Compare
b400940
to
778a4bb
Compare
778a4bb
to
97b0a56
Compare
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.
It's still slightly more changes than I would prefer to review in a single PR but I think it makes sense and I trust you :)
What
Prefetches to pages within a shared layout would frequently cache miss despite having the data available. This causes the "instant navigation" behavior (with the 30s/5min TTL) to not be effective on these pages.
Why
In #59861,
nextUrl
was added as a prefetch cache key prefix to ensure multiple interception routes that correspond to the same URL wouldn't clash in the prefetch cache. However this causes a problem in the case where you're navigating between sub-pages. To illustrate the issue, consider the case where you load/foo
. This will populate the prefetch cache with an entry of{foo: <PrefetchCacheNode}
. Navigating to/foo/bar
, with a link that prefetches back to/foo
, will now result in a new cache node:{foo: <PrefetchCacheNode>, /foo/bar%/foo: <PrefetchCacheNode>}
(whereNext-URL
is/foo/bar
). Now we have a cache entry for the full data, as well as a cache entry for a partial prefetch up to the nearest loading boundary. Now when we navigate back to/foo
, the router will see that it's missing data, and need to lazy-fetch the data triggering the loading boundary.This was especially noticeable in the case where you have a route group with it's own loading.js file because it creates a level of hierarchy in the React tree, and suspending on the data fetch would result in the group's loading boundary to be triggered. In the non-route group scenario, there's still a bug here but it would stall on the data fetch rather than triggering a boundary.
How
In #61794 we conditionally send
Next-URL
as part of theVary
header if we detect it could be intercepted. We use this information when creating the prefetch entry to prefix it, in case it corresponds with an intercepted route.Closes NEXT-2193