mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
d7aa66c345
### Why? Should come up with better solution that does not block PRs with git conflict x-ref: https://vercel.slack.com/archives/C02CDC2ALJH/p1785263902728189?thread_ts=1785263687.502649&cid=C02CDC2ALJH ### How? - Delete `errors.json`, the error-code SWC plugin, generated WASM, merge driver, and validation/build tooling. - Stop attaching error codes to server-rendering digests, redboxes, and telemetry; native `Error.code` and `Error.name` remain available where applicable. - Remove the development-overlay error feedback UI, middleware, and telemetry event that depended on stable codes. - Update fixtures, snapshots, and guidance for code-free errors and numeric-only digests. <!-- NEXT_JS_LLM -->
96 lines
2.7 KiB
TypeScript
96 lines
2.7 KiB
TypeScript
import path from 'path'
|
|
import { outdent } from 'outdent'
|
|
import { FileRef, nextTestSetup } from 'e2e-utils'
|
|
|
|
describe('Error overlay - RSC runtime errors', () => {
|
|
const { next } = nextTestSetup({
|
|
files: new FileRef(path.join(__dirname, 'fixtures', 'rsc-runtime-errors')),
|
|
})
|
|
|
|
it('should show runtime errors if invalid client API from node_modules is executed', async () => {
|
|
await next.patchFile(
|
|
'app/server/page.js',
|
|
outdent`
|
|
import { callClientApi } from 'client-package'
|
|
export default function Page() {
|
|
callClientApi()
|
|
return 'page'
|
|
}
|
|
`
|
|
)
|
|
|
|
const browser = await next.browser('/server')
|
|
|
|
await expect(browser).toDisplayRedbox(`
|
|
{
|
|
"description": "useState only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/react-client-hook-in-server-component",
|
|
"environmentLabel": "Server",
|
|
"label": "Runtime TypeError",
|
|
"source": "app/server/page.js (3:16) @ Page
|
|
> 3 | callClientApi()
|
|
| ^",
|
|
"stack": [
|
|
"Page app/server/page.js (3:16)",
|
|
],
|
|
}
|
|
`)
|
|
})
|
|
|
|
it('should show runtime errors if invalid server API from node_modules is executed', async () => {
|
|
await next.patchFile(
|
|
'app/client/page.js',
|
|
outdent`
|
|
'use client'
|
|
import { callServerApi } from 'server-package'
|
|
export default function Page() {
|
|
callServerApi()
|
|
return 'page'
|
|
}
|
|
`
|
|
)
|
|
|
|
const browser = await next.browser('/client')
|
|
|
|
await expect(browser).toDisplayRedbox(`
|
|
{
|
|
"description": "\`cookies\` was called outside a request scope. Read more: https://nextjs.org/docs/messages/next-dynamic-api-wrong-context",
|
|
"environmentLabel": null,
|
|
"label": "Runtime Error",
|
|
"source": "app/client/page.js (4:16) @ Page
|
|
> 4 | callServerApi()
|
|
| ^",
|
|
"stack": [
|
|
"Page app/client/page.js (4:16)",
|
|
],
|
|
}
|
|
`)
|
|
})
|
|
|
|
it('should show source code for jsx errors from server component', async () => {
|
|
await next.patchFile(
|
|
'app/server/page.js',
|
|
outdent`
|
|
export default function Page() {
|
|
return <div>{alert('warn')}</div>
|
|
}
|
|
`
|
|
)
|
|
|
|
const browser = await next.browser('/server')
|
|
|
|
await expect(browser).toDisplayRedbox(`
|
|
{
|
|
"description": "alert is not defined",
|
|
"environmentLabel": "Server",
|
|
"label": "Runtime ReferenceError",
|
|
"source": "app/server/page.js (2:16) @ Page
|
|
> 2 | return <div>{alert('warn')}</div>
|
|
| ^",
|
|
"stack": [
|
|
"Page app/server/page.js (2:16)",
|
|
],
|
|
}
|
|
`)
|
|
})
|
|
})
|