3008af6b0e
### What Given user infomation when the dynamic errors are thrown, e.g. bad `cookies` or `headers` usages. Now users can tell through the error information to see which pathname is broken, and trace down the usage. #### before ``` Page couldn't be rendered statically because ... This page needs to bail out of prerendering at this point because ... ``` #### after ``` Route /cookies couldn't be rendered statically because ... Route /server needs to bail out of prerendering at this point because ... ``` ### Why When you have multi pages in your app, such as 100+, and many page might uses these. This is hard to trace down where exactly the error is from Closes NEXT-2283 Cloese NEXT-2265
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
/* eslint-env jest */
|
|
import { sandbox } from 'development-sandbox'
|
|
import { FileRef, nextTestSetup } from 'e2e-utils'
|
|
import path from 'path'
|
|
import { outdent } from 'outdent'
|
|
|
|
describe('dynamic = "error" in devmode', () => {
|
|
const { next } = nextTestSetup({
|
|
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
|
|
skipStart: true,
|
|
})
|
|
|
|
it('should show error overlay when dynamic is forced', async () => {
|
|
const { session, cleanup } = await sandbox(next, undefined, '/server')
|
|
|
|
// dynamic = "error" and force dynamic
|
|
await session.patch(
|
|
'app/server/page.js',
|
|
outdent`
|
|
import { cookies } from 'next/headers';
|
|
|
|
import Component from '../../index'
|
|
|
|
export default function Page() {
|
|
cookies()
|
|
return <Component />
|
|
}
|
|
|
|
export const dynamic = "error"
|
|
`
|
|
)
|
|
|
|
await session.hasRedbox()
|
|
console.log(await session.getRedboxDescription())
|
|
expect(await session.getRedboxDescription()).toMatchInlineSnapshot(
|
|
`"Error: Route /server with \`dynamic = "error"\` couldn't be rendered statically because it used \`cookies\`. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering"`
|
|
)
|
|
|
|
await cleanup()
|
|
})
|
|
})
|