-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: empty generateStaticParams should still create an ISR route (#73358
) Returning an empty array from `generateStaticParams` should still be deployed as an ISR route to support the `dynamicParams = true` case, where a route can be generated & cached on demand. At the moment the only way to achieve this behavior is with `export const dynamic = 'force-static'`. As a result, these routes are being treated as dynamic and never return a cached response. This PR resolves the bug by fixing several distinct things: - `prerenderedRoutes` does not need to be an array > 0 to mark a route as being a static path. This will ensure the build output shows the correct symbol and adds the path to the list of prerenders. - we initialize `prerenderedRoutes` to an empty array if we determine that the leaf-most segment (the thing rendering the current page) has a `generateStaticParams` function - the function responsible for collecting segments associated with a page only considered the `children` branch, but for something like a parallel/interception route, those segments would be inside of a different parallel route key - the regex for determining if a function was dynamic didn't consider that the dynamic route might also contain an interception marker (eg `(.)`) This appears to have regressed in #68125 Closes NEXT-3905 --------- Co-authored-by: Wyatt Johnson <[email protected]>
- Loading branch information
Showing
8 changed files
with
113 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
test/production/app-dir/empty-generate-static-params/app/[slug]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Suspense } from 'react' | ||
|
||
export default async function Page({ | ||
params, | ||
}: { | ||
params: Promise<{ slug: string }> | ||
}) { | ||
return ( | ||
<div> | ||
Hello World | ||
<div> | ||
<Params params={params} /> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
async function Params({ params }: { params: Promise<{ slug: string }> }) { | ||
return <Suspense>{(await params).slug}</Suspense> | ||
} | ||
|
||
export async function generateStaticParams() { | ||
return [] | ||
} |
10 changes: 10 additions & 0 deletions
10
test/production/app-dir/empty-generate-static-params/app/layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ReactNode, Suspense } from 'react' | ||
export default function Root({ children }: { children: ReactNode }) { | ||
return ( | ||
<html> | ||
<body> | ||
<Suspense>{children}</Suspense> | ||
</body> | ||
</html> | ||
) | ||
} |
3 changes: 3 additions & 0 deletions
3
test/production/app-dir/empty-generate-static-params/app/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Page() { | ||
return <p>hello world</p> | ||
} |
34 changes: 34 additions & 0 deletions
34
test/production/app-dir/empty-generate-static-params/empty-generate-static-params.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { nextTestSetup } from 'e2e-utils' | ||
import { retry } from 'next-test-utils' | ||
|
||
describe('empty-generate-static-params', () => { | ||
const { next, skipped } = nextTestSetup({ | ||
files: __dirname, | ||
skipDeployment: true, | ||
}) | ||
|
||
if (skipped) return | ||
|
||
it('should mark the page with empty generateStaticParams as SSG in build output', async () => { | ||
const isPPREnabled = process.env.__NEXT_EXPERIMENTAL_PPR === 'true' | ||
expect(next.cliOutput).toContain(`${isPPREnabled ? '◐' : '●'} /[slug]`) | ||
}) | ||
|
||
it('should be a cache miss on the initial render followed by a HIT after being generated', async () => { | ||
const firstResponse = await next.fetch('/foo') | ||
expect(firstResponse.status).toBe(200) | ||
|
||
// With PPR enabled, the initial request doesn't send back a cache header | ||
const isPPREnabled = process.env.__NEXT_EXPERIMENTAL_PPR === 'true' | ||
|
||
expect(firstResponse.headers.get('x-nextjs-cache')).toBe( | ||
isPPREnabled ? null : 'MISS' | ||
) | ||
|
||
retry(async () => { | ||
const secondResponse = await next.fetch('/foo') | ||
expect(secondResponse.status).toBe(200) | ||
expect(secondResponse.headers.get('x-nextjs-cache')).toBe('HIT') | ||
}) | ||
}) | ||
}) |
6 changes: 6 additions & 0 deletions
6
test/production/app-dir/empty-generate-static-params/next.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* @type {import('next').NextConfig} | ||
*/ | ||
const nextConfig = {} | ||
|
||
module.exports = nextConfig |