-
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
- Loading branch information
Showing
7 changed files
with
96 additions
and
15 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
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 |