Skip to content

Commit f5296c3

Browse files
authored
Rework prefetch route handling (#10779)
Follow-up to #10750 this removes the underscore prefetching from all prefetch outputs and instead only applies it to the index route itself as this causes issues with PPR making these outputs prerenders and being able to interpolate the route param values. There is the edge case of a user returning the literal value `index` from `generateStaticParams` but we can tolerate that more than ppr not working as expected.
1 parent d9065c2 commit f5296c3

File tree

9 files changed

+29
-64
lines changed

9 files changed

+29
-64
lines changed

.changeset/tricky-rules-sin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@vercel/next": patch
3+
---
4+
5+
Rework prefetch route handling

packages/next/src/server-build.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,7 @@ export async function serverBuild({
16421642
dest: path.posix.join(
16431643
'/',
16441644
entryDirectory,
1645-
`/__$1${RSC_PREFETCH_SUFFIX}`
1645+
`/$1${RSC_PREFETCH_SUFFIX}`
16461646
),
16471647
headers: { vary: rscVaryHeader },
16481648
continue: true,
@@ -1737,7 +1737,7 @@ export async function serverBuild({
17371737
src: `^${path.posix.join(
17381738
'/',
17391739
entryDirectory,
1740-
`/__(.+?)${RSC_PREFETCH_SUFFIX}(?:/)?$`
1740+
`/(.+?)${RSC_PREFETCH_SUFFIX}(?:/)?$`
17411741
)}`,
17421742
dest: path.posix.join('/', entryDirectory, '/$1.rsc'),
17431743
has: [

packages/next/src/utils.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3127,8 +3127,12 @@ export function normalizePrefetches(prefetches: Record<string, FileFsRef>) {
31273127
const updatedPrefetches: Record<string, FileFsRef> = {};
31283128

31293129
for (const key in prefetches) {
3130-
const newKey = key.replace(/([^/]+\.prefetch\.rsc)$/, '__$1');
3131-
updatedPrefetches[newKey] = prefetches[key];
3130+
if (key === 'index.prefetch.rsc') {
3131+
const newKey = key.replace(/([^/]+\.prefetch\.rsc)$/, '__$1');
3132+
updatedPrefetches[newKey] = prefetches[key];
3133+
} else {
3134+
updatedPrefetches[key] = prefetches[key];
3135+
}
31323136
}
31333137

31343138
return updatedPrefetches;

packages/next/test/fixtures/00-app-dir-root-catch-all/app/[[...slug]]/page.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ export function generateStaticParams() {
1515
{
1616
slug: [''],
1717
},
18-
{
19-
slug: ['index'],
20-
},
18+
// this case is not supported
19+
// {
20+
// slug: ['index'],
21+
// },
2122
{
2223
slug: ['first'],
2324
},

packages/next/test/fixtures/00-app-dir-root-catch-all/app/nested/[[...slug]]/page.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ export function generateStaticParams() {
1515
{
1616
slug: [''],
1717
},
18-
{
19-
slug: ['index'],
20-
},
18+
// not supported
19+
// {
20+
// slug: ['index'],
21+
// },
2122
{
2223
slug: ['first'],
2324
},

packages/next/test/fixtures/00-app-dir-root-catch-all/vercel.json

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,6 @@
2525
"mustNotContain": "<html",
2626
"mustContain": "catch-all"
2727
},
28-
{
29-
"path": "/index",
30-
"status": 200,
31-
"mustContain": "html"
32-
},
33-
{
34-
"path": "/index",
35-
"status": 200,
36-
"mustContain": "catch-all"
37-
},
38-
{
39-
"path": "/index",
40-
"status": 200,
41-
"headers": {
42-
"RSC": 1
43-
},
44-
"mustNotContain": "<html",
45-
"mustContain": "catch-all"
46-
},
4728
{
4829
"path": "/nested",
4930
"status": 200,
@@ -63,25 +44,6 @@
6344
"mustNotContain": "<html",
6445
"mustContain": "catch-all"
6546
},
66-
{
67-
"path": "/nested/index",
68-
"status": 200,
69-
"mustContain": "html"
70-
},
71-
{
72-
"path": "/nested/index",
73-
"status": 200,
74-
"mustContain": "catch-all"
75-
},
76-
{
77-
"path": "/nested/index",
78-
"status": 200,
79-
"headers": {
80-
"RSC": 1
81-
},
82-
"mustNotContain": "<html",
83-
"mustContain": "catch-all"
84-
},
8547
{
8648
"path": "/first",
8749
"status": 200,

packages/next/test/integration/integration-1.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,10 @@ it('Should throw when package.json or next.config.js is not the "src"', async ()
451451
}
452452
});
453453

454+
it('Should build the serverless-config-async example', async () => {
455+
await runBuildLambda(path.join(__dirname, 'serverless-config-async'));
456+
});
457+
454458
describe('Middleware simple project', () => {
455459
const ctx = {};
456460

packages/next/test/integration/legacy/integration-legacy.test.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -247,18 +247,6 @@ it('Should opt-out of shared lambdas when routes are detected', async () => {
247247
expect(hasUnderScoreErrorStaticFile).toBeTruthy();
248248
});
249249

250-
it('Should build the serverless-config-async example', async () => {
251-
let error = null;
252-
253-
try {
254-
await runBuildLambda(path.join(__dirname, '..', 'serverless-config-async'));
255-
} catch (err) {
256-
error = err;
257-
}
258-
259-
expect(error).toBe(null);
260-
});
261-
262250
it('Should provide lambda info when limit is hit (shared lambdas)', async () => {
263251
let logs = '';
264252

packages/next/test/unit/utils.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,10 @@ describe('normalizePrefetches', () => {
426426

427427
expect(Object.keys(updatedPrefetches)).toEqual([
428428
'__index.prefetch.rsc',
429-
'index/__index.prefetch.rsc',
430-
'__foo.prefetch.rsc',
431-
'foo/__index.prefetch.rsc',
432-
'foo/bar/__baz.prefetch.rsc',
429+
'index/index.prefetch.rsc',
430+
'foo.prefetch.rsc',
431+
'foo/index.prefetch.rsc',
432+
'foo/bar/baz.prefetch.rsc',
433433
]);
434434
});
435435
});

0 commit comments

Comments
 (0)