Skip to content

Commit e368936

Browse files
authored
Fix uniqueness detection for generateStaticParams (#76713)
1 parent 170f459 commit e368936

File tree

3 files changed

+102
-1
lines changed

3 files changed

+102
-1
lines changed

packages/next/src/build/static-paths/app.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function areParamValuesEqual(a: ParamValue, b: ParamValue) {
3838
return false
3939
}
4040

41-
return a.every((item) => b.includes(item))
41+
return a.every((item, index) => item === b[index])
4242
}
4343

4444
// Otherwise, they're not equal.

test/e2e/app-dir/app-static/app-static.test.ts

+84
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,10 @@ describe('app-dir static/dynamic handling', () => {
833833
"force-static/first.rsc",
834834
"force-static/second.html",
835835
"force-static/second.rsc",
836+
"gen-params-catch-all-unique/foo/bar.html",
837+
"gen-params-catch-all-unique/foo/bar.rsc",
838+
"gen-params-catch-all-unique/foo/foo.html",
839+
"gen-params-catch-all-unique/foo/foo.rsc",
836840
"gen-params-dynamic-revalidate/one.html",
837841
"gen-params-dynamic-revalidate/one.rsc",
838842
"hooks/use-pathname/slug.html",
@@ -1314,6 +1318,54 @@ describe('app-dir static/dynamic handling', () => {
13141318
"initialRevalidateSeconds": false,
13151319
"srcRoute": "/force-static/[slug]",
13161320
},
1321+
"/gen-params-catch-all-unique/foo/bar": {
1322+
"allowHeader": [
1323+
"host",
1324+
"x-matched-path",
1325+
"x-prerender-revalidate",
1326+
"x-prerender-revalidate-if-generated",
1327+
"x-next-revalidated-tags",
1328+
"x-next-revalidate-tag-token",
1329+
],
1330+
"dataRoute": "/gen-params-catch-all-unique/foo/bar.rsc",
1331+
"experimentalBypassFor": [
1332+
{
1333+
"key": "Next-Action",
1334+
"type": "header",
1335+
},
1336+
{
1337+
"key": "content-type",
1338+
"type": "header",
1339+
"value": "multipart/form-data;.*",
1340+
},
1341+
],
1342+
"initialRevalidateSeconds": false,
1343+
"srcRoute": "/gen-params-catch-all-unique/[...slug]",
1344+
},
1345+
"/gen-params-catch-all-unique/foo/foo": {
1346+
"allowHeader": [
1347+
"host",
1348+
"x-matched-path",
1349+
"x-prerender-revalidate",
1350+
"x-prerender-revalidate-if-generated",
1351+
"x-next-revalidated-tags",
1352+
"x-next-revalidate-tag-token",
1353+
],
1354+
"dataRoute": "/gen-params-catch-all-unique/foo/foo.rsc",
1355+
"experimentalBypassFor": [
1356+
{
1357+
"key": "Next-Action",
1358+
"type": "header",
1359+
},
1360+
{
1361+
"key": "content-type",
1362+
"type": "header",
1363+
"value": "multipart/form-data;.*",
1364+
},
1365+
],
1366+
"initialRevalidateSeconds": false,
1367+
"srcRoute": "/gen-params-catch-all-unique/[...slug]",
1368+
},
13171369
"/gen-params-dynamic-revalidate/one": {
13181370
"allowHeader": [
13191371
"host",
@@ -2430,6 +2482,31 @@ describe('app-dir static/dynamic handling', () => {
24302482
"fallback": null,
24312483
"routeRegex": "^\\/force\\-static\\/([^\\/]+?)(?:\\/)?$",
24322484
},
2485+
"/gen-params-catch-all-unique/[...slug]": {
2486+
"allowHeader": [
2487+
"host",
2488+
"x-matched-path",
2489+
"x-prerender-revalidate",
2490+
"x-prerender-revalidate-if-generated",
2491+
"x-next-revalidated-tags",
2492+
"x-next-revalidate-tag-token",
2493+
],
2494+
"dataRoute": "/gen-params-catch-all-unique/[...slug].rsc",
2495+
"dataRouteRegex": "^\\/gen\\-params\\-catch\\-all\\-unique\\/(.+?)\\.rsc$",
2496+
"experimentalBypassFor": [
2497+
{
2498+
"key": "Next-Action",
2499+
"type": "header",
2500+
},
2501+
{
2502+
"key": "content-type",
2503+
"type": "header",
2504+
"value": "multipart/form-data;.*",
2505+
},
2506+
],
2507+
"fallback": false,
2508+
"routeRegex": "^\\/gen\\-params\\-catch\\-all\\-unique\\/(.+?)(?:\\/)?$",
2509+
},
24332510
"/gen-params-dynamic-revalidate/[slug]": {
24342511
"allowHeader": [
24352512
"host",
@@ -3678,6 +3755,13 @@ describe('app-dir static/dynamic handling', () => {
36783755
})
36793756

36803757
if (!process.env.CUSTOM_CACHE_HANDLER) {
3758+
it('should not filter out catch-all params with repeated segments in generateStaticParams', async () => {
3759+
const res1 = await next.fetch('/gen-params-catch-all-unique/foo/foo')
3760+
expect(res1.status).toBe(200)
3761+
const res2 = await next.fetch('/gen-params-catch-all-unique/foo/bar')
3762+
expect(res2.status).toBe(200)
3763+
})
3764+
36813765
it('should honor dynamic = "force-static" correctly', async () => {
36823766
const res = await next.fetch('/force-static/first')
36833767
expect(res.status).toBe(200)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export const dynamicParams = false
2+
3+
export default async function Page({ params }) {
4+
const { slug } = await params
5+
return <p>Test {slug.join('/')}</p>
6+
}
7+
8+
export function generateStaticParams() {
9+
return [
10+
{
11+
slug: ['foo', 'foo'],
12+
},
13+
{
14+
slug: ['foo', 'bar'],
15+
},
16+
]
17+
}

0 commit comments

Comments
 (0)