Skip to content

Commit 4fbbb62

Browse files
authored
Update normalize revalidate params for named matches (#48032)
This ensures the prefix for route params is stripped when pulled from the revalidate headers. Also updates tests accordingly. x-ref: #47930
1 parent 946424e commit 4fbbb62

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

packages/next/src/server/server-utils.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,21 @@ export function getUtils({
262262
const matchesHasLocale =
263263
i18n && detectedLocale && obj['1'] === detectedLocale
264264

265+
for (const key of Object.keys(obj)) {
266+
const value = obj[key]
267+
268+
if (
269+
key !== NEXT_QUERY_PARAM_PREFIX &&
270+
key.startsWith(NEXT_QUERY_PARAM_PREFIX)
271+
) {
272+
const normalizedKey = key.substring(
273+
NEXT_QUERY_PARAM_PREFIX.length
274+
)
275+
obj[normalizedKey] = value
276+
delete obj[key]
277+
}
278+
}
279+
265280
// favor named matches if available
266281
const routeKeyNames = Object.keys(routeKeys || {})
267282
const filterLocaleItem = (val: string | string[] | undefined) => {

test/production/standalone-mode/required-server-files/required-server-files-i18n.test.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ describe('should set-up next', () => {
349349
const html3 = await renderViaHTTP(appPort, '/some-other-path', undefined, {
350350
headers: {
351351
'x-matched-path': '/dynamic/[slug]?slug=%5Bslug%5D.json',
352-
'x-now-route-matches': '1=second&slug=second',
352+
'x-now-route-matches': '1=second&nextParamslug=second',
353353
},
354354
})
355355
const $3 = cheerio.load(html3)
@@ -451,7 +451,7 @@ describe('should set-up next', () => {
451451
{
452452
headers: {
453453
'x-matched-path': '/catch-all/[[...rest]]',
454-
'x-now-route-matches': '1=hello&catchAll=hello',
454+
'x-now-route-matches': '1=hello&nextParamcatchAll=hello',
455455
},
456456
}
457457
)
@@ -470,7 +470,7 @@ describe('should set-up next', () => {
470470
{
471471
headers: {
472472
'x-matched-path': '/catch-all/[[...rest]]',
473-
'x-now-route-matches': '1=hello/world&catchAll=hello/world',
473+
'x-now-route-matches': '1=hello/world&nextParamcatchAll=hello/world',
474474
},
475475
}
476476
)
@@ -507,7 +507,7 @@ describe('should set-up next', () => {
507507
{
508508
headers: {
509509
'x-matched-path': `/_next/data/${next.buildId}/en/catch-all/[[...rest]].json`,
510-
'x-now-route-matches': '1=hello&rest=hello',
510+
'x-now-route-matches': '1=hello&nextParamrest=hello',
511511
},
512512
}
513513
)
@@ -524,7 +524,7 @@ describe('should set-up next', () => {
524524
{
525525
headers: {
526526
'x-matched-path': `/_next/data/${next.buildId}/en/catch-all/[[...rest]].json`,
527-
'x-now-route-matches': '1=hello/world&rest=hello/world',
527+
'x-now-route-matches': '1=hello/world&nextParamrest=hello/world',
528528
},
529529
}
530530
)
@@ -682,7 +682,8 @@ describe('should set-up next', () => {
682682
{
683683
headers: {
684684
'x-matched-path': '/en/[slug]/social/[[...rest]]',
685-
'x-now-route-matches': 'nextLocale=en&1=en&2=user-123&slug=user-123',
685+
'x-now-route-matches':
686+
'nextLocale=en&1=en&2=user-123&nextParamslug=user-123',
686687
},
687688
}
688689
)
@@ -705,7 +706,7 @@ describe('should set-up next', () => {
705706
headers: {
706707
'x-matched-path': '/optional-ssg/[[...rest]]',
707708
'x-now-route-matches':
708-
'1=en%2Fes%2Fhello%252Fworld&rest=en%2Fes%2Fhello%252Fworld',
709+
'1=en%2Fes%2Fhello%252Fworld&nextParamrest=en%2Fes%2Fhello%252Fworld',
709710
},
710711
}
711712
)
@@ -765,7 +766,8 @@ describe('should set-up next', () => {
765766
const res = await fetchViaHTTP(appPort, '/en/fallback/[slug]', undefined, {
766767
headers: {
767768
'x-matched-path': '/en/fallback/[slug]',
768-
'x-now-route-matches': '2=another&slug=another&1=en&nextLocale=en',
769+
'x-now-route-matches':
770+
'2=another&nextParamslug=another&1=en&nextLocale=en',
769771
},
770772
redirect: 'manual',
771773
})
@@ -783,7 +785,8 @@ describe('should set-up next', () => {
783785
const res = await fetchViaHTTP(appPort, '/fr/fallback/[slug]', undefined, {
784786
headers: {
785787
'x-matched-path': '/fr/fallback/[slug]',
786-
'x-now-route-matches': '2=another&slug=another&1=fr&nextLocale=fr',
788+
'x-now-route-matches':
789+
'2=another&nextParamslug=another&1=fr&nextLocale=fr',
787790
},
788791
redirect: 'manual',
789792
})

test/production/standalone-mode/required-server-files/required-server-files.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ describe('should set-up next', () => {
606606
const html3 = await renderViaHTTP(appPort, '/some-other-path', undefined, {
607607
headers: {
608608
'x-matched-path': '/dynamic/[slug]',
609-
'x-now-route-matches': '1=second&slug=second',
609+
'x-now-route-matches': '1=second&nextParamslug=second',
610610
},
611611
})
612612
const $3 = cheerio.load(html3)
@@ -761,7 +761,7 @@ describe('should set-up next', () => {
761761
{
762762
headers: {
763763
'x-matched-path': '/catch-all/[[...rest]]',
764-
'x-now-route-matches': '1=hello&catchAll=hello',
764+
'x-now-route-matches': '1=hello&nextParamcatchAll=hello',
765765
},
766766
}
767767
)
@@ -780,7 +780,7 @@ describe('should set-up next', () => {
780780
{
781781
headers: {
782782
'x-matched-path': '/catch-all/[[...rest]]',
783-
'x-now-route-matches': '1=hello/world&catchAll=hello/world',
783+
'x-now-route-matches': '1=hello/world&nextParamcatchAll=hello/world',
784784
},
785785
}
786786
)
@@ -818,7 +818,7 @@ describe('should set-up next', () => {
818818
{
819819
headers: {
820820
'x-matched-path': `/_next/data/${next.buildId}/catch-all/[[...rest]].json`,
821-
'x-now-route-matches': '1=hello&rest=hello',
821+
'x-now-route-matches': '1=hello&nextParamrest=hello',
822822
},
823823
}
824824
)
@@ -835,7 +835,7 @@ describe('should set-up next', () => {
835835
{
836836
headers: {
837837
'x-matched-path': `/_next/data/${next.buildId}/catch-all/[[...rest]].json`,
838-
'x-now-route-matches': '1=hello/world&rest=hello/world',
838+
'x-now-route-matches': '1=hello/world&nextParamrest=hello/world',
839839
},
840840
}
841841
)
@@ -1111,7 +1111,7 @@ describe('should set-up next', () => {
11111111
headers: {
11121112
'x-matched-path': '/optional-ssg/[[...rest]]',
11131113
'x-now-route-matches':
1114-
'1=en%2Fes%2Fhello%252Fworld&rest=en%2Fes%2Fhello%252Fworld',
1114+
'1=en%2Fes%2Fhello%252Fworld&nextParamrest=en%2Fes%2Fhello%252Fworld',
11151115
},
11161116
}
11171117
)

0 commit comments

Comments
 (0)