Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { connection } from 'next/server'

export default function Page() {
return <p>connection</p>
}

export async function generateStaticParams() {
await connection()
return [{ slug: 'test' }]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { cookies } from 'next/headers'

export default function Page() {
return <p>cookies</p>
}

export async function generateStaticParams() {
await cookies()
return [{ slug: 'test' }]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { draftMode } from 'next/headers'

export default function Page() {
return <p>draft-mode</p>
}

export async function generateStaticParams() {
await draftMode()
return [{ slug: 'test' }]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { headers } from 'next/headers'

export default function Page() {
return <p>headers</p>
}

export async function generateStaticParams() {
await headers()
return [{ slug: 'test' }]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default function Root({ children }: { children: React.ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}

export async function generateStaticParams() {
return [{ lang: 'en' }]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { lang } from 'next/root-params'

export default function Page() {
return <p>root-params</p>
}

export async function generateStaticParams() {
await lang()
return [{ slug: 'test' }]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { nextTestSetup } from 'e2e-utils'

describe('generate-static-params-errors', () => {
const { next } = nextTestSetup({
files: __dirname,
skipStart: true,
})

let cliOutputLength: number

afterEach(async () => {
await next.stop()
})

const buildRoute = async (routePath: string) => {
cliOutputLength = next.cliOutput.length
await next.build({ args: ['--debug-build-paths', routePath] })
}

const getCliOutput = () => next.cliOutput.slice(cliOutputLength)

it('should error when cookies() is called inside generateStaticParams', async () => {
await buildRoute('app/[lang]/cookies/[slug]/page.tsx')
expect(getCliOutput()).toContain(
'Error: `cookies` was called outside a request scope. Read more: https://nextjs.org/docs/messages/next-dynamic-api-wrong-context'
)
})

it('should error when headers() is called inside generateStaticParams', async () => {
await buildRoute('app/[lang]/headers/[slug]/page.tsx')
expect(getCliOutput()).toContain(
'Error: `headers` was called outside a request scope. Read more: https://nextjs.org/docs/messages/next-dynamic-api-wrong-context'
)
})

it('should error when connection() is called inside generateStaticParams', async () => {
await buildRoute('app/[lang]/connection/[slug]/page.tsx')
expect(getCliOutput()).toContain(
'Error: `connection` was called outside a request scope. Read more: https://nextjs.org/docs/messages/next-dynamic-api-wrong-context'
)
})

it('should error when draftMode() is called inside generateStaticParams', async () => {
await buildRoute('app/[lang]/draft-mode/[slug]/page.tsx')
expect(getCliOutput()).toContain(
'Error: `draftMode` was called outside a request scope. Read more: https://nextjs.org/docs/messages/next-dynamic-api-wrong-context'
)
})

it('should error when root params are accessed inside generateStaticParams', async () => {
await buildRoute('app/[lang]/root-params/[slug]/page.tsx')
expect(getCliOutput()).toContain(
"Error: Route /[lang]/root-params/[slug] used `import('next/root-params').lang()` outside of a Server Component. This is not allowed."
)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { NextConfig } from 'next'

const nextConfig: NextConfig = {
experimental: { rootParams: true },
}

export default nextConfig
Loading