From 1b96e76bcde48965f0a6ca0c7784b07ba2bfe9a4 Mon Sep 17 00:00:00 2001 From: Rick Martens Date: Sat, 26 Oct 2024 14:43:13 +0200 Subject: [PATCH 1/2] Fix prerendered dynamic ISR functions for nested routes --- .../invalidFunctions.ts | 2 +- .../invalidFunctions.test.ts | 23 +++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/packages/next-on-pages/src/buildApplication/processVercelFunctions/invalidFunctions.ts b/packages/next-on-pages/src/buildApplication/processVercelFunctions/invalidFunctions.ts index 00872adaa..b1eb592b4 100644 --- a/packages/next-on-pages/src/buildApplication/processVercelFunctions/invalidFunctions.ts +++ b/packages/next-on-pages/src/buildApplication/processVercelFunctions/invalidFunctions.ts @@ -339,7 +339,7 @@ async function tryToFixInvalidDynamicISRFuncs({ const isDynamicISRFunc = fnInfo.config.operationType === 'ISR' && - /\/\[(?:\.\.\.)?[\w-]+\]$/.test(fnPathWithoutRscOrFuncExt); + /\/\[(?:\.\.\.)?[\w-]+\]/.test(fnPathWithoutRscOrFuncExt); if (isDynamicISRFunc) { const matchingPrerenderedChildFunc = prerenderedFunctionEntries.find( diff --git a/packages/next-on-pages/tests/src/buildApplication/processVercelFunctions/invalidFunctions.test.ts b/packages/next-on-pages/tests/src/buildApplication/processVercelFunctions/invalidFunctions.test.ts index 8cb1bb226..1716c7d3d 100644 --- a/packages/next-on-pages/tests/src/buildApplication/processVercelFunctions/invalidFunctions.test.ts +++ b/packages/next-on-pages/tests/src/buildApplication/processVercelFunctions/invalidFunctions.test.ts @@ -243,6 +243,18 @@ describe('checkInvalidFunctions', () => { ), 'dynamic-2-child.prerender-fallback.html': '', }, + '[dynamic-3]': { + 'nested.func': prerenderFuncDir, + 'nested.rsc.func': prerenderFuncDir, + }, + 'dynamic-3-child': { + 'nested.func': prerenderFuncDir, + 'nested.prerender-config.json': mockPrerenderConfigFile( + 'nested', + { sourcePath: '/[dynamic-3]/nested' }, + ), + 'nested.prerender-fallback.html': '', + }, }, }); @@ -260,9 +272,9 @@ describe('checkInvalidFunctions', () => { const { prerenderedFunctions, invalidFunctions, ignoredFunctions } = collectedFunctions; - expect(prerenderedFunctions.size).toEqual(2); + expect(prerenderedFunctions.size).toEqual(3); expect(invalidFunctions.size).toEqual(0); - expect(ignoredFunctions.size).toEqual(3); + expect(ignoredFunctions.size).toEqual(5); expect(getRouteInfo(prerenderedFunctions, 'dynamic-1-child.func')).toEqual({ path: '/dynamic-1-child.html', @@ -276,10 +288,17 @@ describe('checkInvalidFunctions', () => { overrides: ['/nested/dynamic-2-child'], headers: { vary: 'RSC, Next-Router-State-Tree, Next-Router-Prefetch' }, }); + expect(getRouteInfo(prerenderedFunctions, 'dynamic-3-child/nested.func')).toEqual({ + path: '/dynamic-3-child/nested.html', + overrides: ['/dynamic-3-child/nested'], + headers: { vary: 'RSC, Next-Router-State-Tree, Next-Router-Prefetch' }, + }); expect([...ignoredFunctions.keys()]).toEqual([ resolve(functionsDir, '[dynamic-1].func'), resolve(functionsDir, '[dynamic-1].rsc.func'), + resolve(functionsDir, '[dynamic-3]/nested.func'), + resolve(functionsDir, '[dynamic-3]/nested.rsc.func'), resolve(functionsDir, 'nested/[dynamic-2].func'), ]); From 3e0119e76f79735cee6893ce73ea9979fdcbb448 Mon Sep 17 00:00:00 2001 From: Rick Martens Date: Sat, 26 Oct 2024 15:17:12 +0200 Subject: [PATCH 2/2] Create changeset. --- .changeset/wild-coats-pull.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/wild-coats-pull.md diff --git a/.changeset/wild-coats-pull.md b/.changeset/wild-coats-pull.md new file mode 100644 index 000000000..f78168778 --- /dev/null +++ b/.changeset/wild-coats-pull.md @@ -0,0 +1,5 @@ +--- +'@cloudflare/next-on-pages': patch +--- + +Fix prerendered dynamic ISR functions with catch-all segments