Unverified Commit 0a4cc0a0 authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

[dev-overlay] add error env name label (#76003)

parent 520318b3
...@@ -7,14 +7,23 @@ const consoleTypeSym = Symbol.for('next.console.error.type') ...@@ -7,14 +7,23 @@ const consoleTypeSym = Symbol.for('next.console.error.type')
type UnhandledError = Error & { type UnhandledError = Error & {
[digestSym]: 'NEXT_UNHANDLED_ERROR' [digestSym]: 'NEXT_UNHANDLED_ERROR'
[consoleTypeSym]: 'string' | 'error' [consoleTypeSym]: 'string' | 'error'
environmentName: string
} }
export function createUnhandledError(message: string | Error): UnhandledError { export function createUnhandledError(
message: string | Error,
environmentName?: string | null
): UnhandledError {
const error = ( const error = (
typeof message === 'string' ? new Error(message) : message typeof message === 'string' ? new Error(message) : message
) as UnhandledError ) as UnhandledError
error[digestSym] = 'NEXT_UNHANDLED_ERROR' error[digestSym] = 'NEXT_UNHANDLED_ERROR'
error[consoleTypeSym] = typeof message === 'string' ? 'string' : 'error' error[consoleTypeSym] = typeof message === 'string' ? 'string' : 'error'
if (environmentName && !error.environmentName) {
error.environmentName = environmentName
}
return error return error
} }
......
...@@ -2,7 +2,7 @@ import { useEffect } from 'react' ...@@ -2,7 +2,7 @@ import { useEffect } from 'react'
import { attachHydrationErrorState } from './attach-hydration-error-state' import { attachHydrationErrorState } from './attach-hydration-error-state'
import { isNextRouterError } from '../is-next-router-error' import { isNextRouterError } from '../is-next-router-error'
import { storeHydrationErrorStateFromConsoleArgs } from './hydration-error-info' import { storeHydrationErrorStateFromConsoleArgs } from './hydration-error-info'
import { formatConsoleArgs } from '../../lib/console' import { formatConsoleArgs, parseConsoleArgs } from '../../lib/console'
import isError from '../../../lib/is-error' import isError from '../../../lib/is-error'
import { createUnhandledError } from './console-error' import { createUnhandledError } from './console-error'
import { enqueueConsecutiveDedupedError } from './enqueue-client-error' import { enqueueConsecutiveDedupedError } from './enqueue-client-error'
...@@ -27,7 +27,8 @@ export function handleClientError( ...@@ -27,7 +27,8 @@ export function handleClientError(
if (!originError || !isError(originError)) { if (!originError || !isError(originError)) {
// If it's not an error, format the args into an error // If it's not an error, format the args into an error
const formattedErrorMessage = formatConsoleArgs(consoleErrorArgs) const formattedErrorMessage = formatConsoleArgs(consoleErrorArgs)
error = createUnhandledError(formattedErrorMessage) const { environmentName } = parseConsoleArgs(consoleErrorArgs)
error = createUnhandledError(formattedErrorMessage, environmentName)
} else { } else {
error = capturedFromConsole error = capturedFromConsole
? createUnhandledError(originError) ? createUnhandledError(originError)
......
import isError from '../../../lib/is-error' import isError from '../../../lib/is-error'
import { isNextRouterError } from '../is-next-router-error' import { isNextRouterError } from '../is-next-router-error'
import { handleClientError } from '../errors/use-error-handler' import { handleClientError } from '../errors/use-error-handler'
import { parseConsoleArgs } from '../../lib/console'
export const originConsoleError = window.console.error export const originConsoleError = window.console.error
...@@ -13,7 +14,7 @@ export function patchConsoleError() { ...@@ -13,7 +14,7 @@ export function patchConsoleError() {
window.console.error = function error(...args: any[]) { window.console.error = function error(...args: any[]) {
let maybeError: unknown let maybeError: unknown
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
const replayedError = matchReplayedError(...args) const { error: replayedError } = parseConsoleArgs(args)
if (replayedError) { if (replayedError) {
maybeError = replayedError maybeError = replayedError
} else if (isError(args[0])) { } else if (isError(args[0])) {
...@@ -41,34 +42,3 @@ export function patchConsoleError() { ...@@ -41,34 +42,3 @@ export function patchConsoleError() {
} }
} }
} }
function matchReplayedError(...args: unknown[]): Error | null {
// See
// https://github.com/facebook/react/blob/65a56d0e99261481c721334a3ec4561d173594cd/packages/react-devtools-shared/src/backend/flight/renderer.js#L88-L93
//
// Logs replayed from the server look like this:
// [
// "%c%s%c %o\n\n%s\n\n%s\n",
// "background: #e6e6e6; ...",
// " Server ", // can also be e.g. " Prerender "
// "",
// Error
// "The above error occurred in the <Page> component."
// ...
// ]
if (
args.length > 3 &&
typeof args[0] === 'string' &&
args[0].startsWith('%c%s%c ') &&
typeof args[1] === 'string' &&
typeof args[2] === 'string' &&
typeof args[3] === 'string'
) {
const maybeError = args[4]
if (isError(maybeError)) {
return maybeError
}
}
return null
}
import type { Meta, StoryObj } from '@storybook/react'
import { EnvironmentNameLabel } from './environment-name-label'
import { withShadowPortal } from '../../../storybook/with-shadow-portal'
const meta: Meta<typeof EnvironmentNameLabel> = {
component: EnvironmentNameLabel,
parameters: {
layout: 'centered',
},
decorators: [withShadowPortal],
}
export default meta
type Story = StoryObj<typeof EnvironmentNameLabel>
export const Server: Story = {
args: {
environmentName: 'Server',
},
}
export const Prerender: Story = {
args: {
environmentName: 'Prerender',
},
}
export const Cache: Story = {
args: {
environmentName: 'Cache',
},
}
import { noop as css } from '../../../helpers/noop-template'
export function EnvironmentNameLabel({
environmentName,
}: {
environmentName: string
}) {
return <span data-nextjs-environment-name-label>{environmentName}</span>
}
export const ENVIRONMENT_NAME_LABEL_STYLES = css`
[data-nextjs-environment-name-label] {
padding: var(--size-0_5) var(--size-1_5);
margin: 0;
/* used --size instead of --rounded because --rounded is missing 6px */
border-radius: var(--size-1_5);
background: var(--color-gray-300);
font-weight: 600;
font-size: var(--size-font-11);
color: var(--color-gray-900);
font-family: var(--font-stack-monospace);
line-height: var(--size-5);
}
`
...@@ -33,13 +33,14 @@ import { OVERLAY_STYLES, ErrorOverlayOverlay } from '../overlay/overlay' ...@@ -33,13 +33,14 @@ import { OVERLAY_STYLES, ErrorOverlayOverlay } from '../overlay/overlay'
import { ErrorOverlayBottomStack } from '../error-overlay-bottom-stack' import { ErrorOverlayBottomStack } from '../error-overlay-bottom-stack'
import type { ErrorBaseProps } from '../error-overlay/error-overlay' import type { ErrorBaseProps } from '../error-overlay/error-overlay'
import type { ReadyRuntimeError } from '../../../../../internal/helpers/get-error-by-type' import type { ReadyRuntimeError } from '../../../../../internal/helpers/get-error-by-type'
import { EnvironmentNameLabel } from '../environment-name-label/environment-name-label'
interface ErrorOverlayLayoutProps extends ErrorBaseProps { interface ErrorOverlayLayoutProps extends ErrorBaseProps {
errorMessage: ErrorMessageType errorMessage: ErrorMessageType
errorType: ErrorType errorType: ErrorType
children?: React.ReactNode children?: React.ReactNode
errorCode?: string errorCode?: string
error: Error error: ReadyRuntimeError['error']
debugInfo?: DebugInfo debugInfo?: DebugInfo
isBuildError?: boolean isBuildError?: boolean
onClose?: () => void onClose?: () => void
...@@ -97,7 +98,14 @@ export function ErrorOverlayLayout({ ...@@ -97,7 +98,14 @@ export function ErrorOverlayLayout({
// allow assertion in tests before error rating is implemented // allow assertion in tests before error rating is implemented
data-nextjs-error-code={errorCode} data-nextjs-error-code={errorCode}
> >
<span data-nextjs-error-label-group>
<ErrorTypeLabel errorType={errorType} /> <ErrorTypeLabel errorType={errorType} />
{error.environmentName && (
<EnvironmentNameLabel
environmentName={error.environmentName}
/>
)}
</span>
<ErrorOverlayToolbar error={error} debugInfo={debugInfo} /> <ErrorOverlayToolbar error={error} debugInfo={debugInfo} />
</div> </div>
<ErrorMessage errorMessage={errorMessage} /> <ErrorMessage errorMessage={errorMessage} />
...@@ -141,4 +149,10 @@ export const styles = css` ...@@ -141,4 +149,10 @@ export const styles = css`
${errorMessageStyles} ${errorMessageStyles}
${toolbarStyles} ${toolbarStyles}
${CALL_STACK_STYLES} ${CALL_STACK_STYLES}
[data-nextjs-error-label-group] {
display: flex;
align-items: center;
gap: var(--size-2);
}
` `
...@@ -28,7 +28,7 @@ export const styles = css` ...@@ -28,7 +28,7 @@ export const styles = css`
margin: 0; margin: 0;
/* used --size instead of --rounded because --rounded is missing 6px */ /* used --size instead of --rounded because --rounded is missing 6px */
border-radius: var(--size-1_5); border-radius: var(--size-1_5);
background: var(--color-red-100); background: var(--color-red-300);
font-weight: 600; font-weight: 600;
font-size: var(--size-font-11); font-size: var(--size-font-11);
color: var(--color-red-900); color: var(--color-red-900);
......
...@@ -53,16 +53,22 @@ function ErrorDescription({ ...@@ -53,16 +53,22 @@ function ErrorDescription({
? '' ? ''
: error.name + ': ' : error.name + ': '
// If it's replayed error, display the environment name
const environmentName = const environmentName =
'environmentName' in error ? error['environmentName'] : '' 'environmentName' in error ? error.environmentName : ''
const envPrefix = environmentName ? `[ ${environmentName} ] ` : '' const envPrefix = environmentName ? `[ ${environmentName} ] ` : ''
// The environment name will be displayed as a label, so remove it
// from the message (e.g. "[ Server ] hello world" -> "hello world").
let message = error.message
if (message.startsWith(envPrefix)) {
message = message.slice(envPrefix.length)
}
return ( return (
<> <>
{envPrefix}
{title} {title}
<HotlinkedText <HotlinkedText
text={hydrationWarning || error.message} text={hydrationWarning || message}
matcher={isNextjsLink} matcher={isNextjsLink}
/> />
</> </>
......
...@@ -16,13 +16,14 @@ import { CALL_STACK_FRAME_STYLES } from '../components/call-stack-frame/call-sta ...@@ -16,13 +16,14 @@ import { CALL_STACK_FRAME_STYLES } from '../components/call-stack-frame/call-sta
import { styles as devToolsIndicator } from '../components/errors/dev-tools-indicator/styles' import { styles as devToolsIndicator } from '../components/errors/dev-tools-indicator/styles'
import { noop as css } from '../helpers/noop-template' import { noop as css } from '../helpers/noop-template'
import { EDITOR_LINK_STYLES } from '../components/terminal/editor-link' import { EDITOR_LINK_STYLES } from '../components/terminal/editor-link'
import { ENVIRONMENT_NAME_LABEL_STYLES } from '../components/errors/environment-name-label/environment-name-label'
export function ComponentStyles() { export function ComponentStyles() {
return ( return (
<style> <style>
{css` {css`
${COPY_BUTTON_STYLES} ${COPY_BUTTON_STYLES}
${CALL_STACK_FRAME_STYLES} ${CALL_STACK_FRAME_STYLES}
${ENVIRONMENT_NAME_LABEL_STYLES}
${overlay} ${overlay}
${toast} ${toast}
${dialog} ${dialog}
......
...@@ -84,9 +84,10 @@ function ErrorDescription({ ...@@ -84,9 +84,10 @@ function ErrorDescription({
const environmentName = const environmentName =
'environmentName' in error ? error['environmentName'] : '' 'environmentName' in error ? error['environmentName'] : ''
const envPrefix = environmentName ? `[ ${environmentName} ] ` : '' const envPrefix = environmentName ? `[ ${environmentName} ] ` : ''
const isMsgMissingEnvPrefix = !error.message.startsWith(envPrefix)
return ( return (
<> <>
{envPrefix} {isMsgMissingEnvPrefix && envPrefix}
{title} {title}
<HotlinkedText <HotlinkedText
text={hydrationWarning || error.message} text={hydrationWarning || error.message}
......
...@@ -12,7 +12,7 @@ import React from 'react' ...@@ -12,7 +12,7 @@ import React from 'react'
export type ReadyRuntimeError = { export type ReadyRuntimeError = {
id: number id: number
runtime: true runtime: true
error: Error error: Error & { environmentName?: string }
frames: OriginalStackFrame[] | (() => Promise<OriginalStackFrame[]>) frames: OriginalStackFrame[] | (() => Promise<OriginalStackFrame[]>)
componentStackFrames?: ComponentStackFrame[] componentStackFrames?: ComponentStackFrame[]
} }
......
import isError from '../../lib/is-error'
function formatObject(arg: unknown, depth: number) { function formatObject(arg: unknown, depth: number) {
switch (typeof arg) { switch (typeof arg) {
case 'object': case 'object':
...@@ -109,3 +111,43 @@ export function formatConsoleArgs(args: unknown[]): string { ...@@ -109,3 +111,43 @@ export function formatConsoleArgs(args: unknown[]): string {
return result return result
} }
export function parseConsoleArgs(args: unknown[]): {
environmentName: string | null
error: Error | null
} {
// See
// https://github.com/facebook/react/blob/65a56d0e99261481c721334a3ec4561d173594cd/packages/react-devtools-shared/src/backend/flight/renderer.js#L88-L93
//
// Logs replayed from the server look like this:
// [
// "%c%s%c %o\n\n%s\n\n%s\n",
// "background: #e6e6e6; ...",
// " Server ", // can also be e.g. " Prerender "
// "",
// Error,
// "The above error occurred in the <Page> component.",
// ...
// ]
if (
args.length > 3 &&
typeof args[0] === 'string' &&
args[0].startsWith('%c%s%c ') &&
typeof args[1] === 'string' &&
typeof args[2] === 'string' &&
typeof args[3] === 'string'
) {
const environmentName = args[2]
const maybeError = args[4]
return {
environmentName: environmentName.trim(),
error: isError(maybeError) ? maybeError : null,
}
}
return {
environmentName: null,
error: null,
}
}
...@@ -31,8 +31,15 @@ describe('dynamic = "error" in devmode', () => { ...@@ -31,8 +31,15 @@ describe('dynamic = "error" in devmode', () => {
) )
const { session } = sandbox const { session } = sandbox
await session.assertHasRedbox() await session.assertHasRedbox()
expect(await session.getRedboxDescription()).toMatchInlineSnapshot( const description = await session.getRedboxDescription()
if (process.env.__NEXT_EXPERIMENTAL_NEW_DEV_OVERLAY === 'true') {
expect(description).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"`
)
} else {
expect(description).toMatchInlineSnapshot(
`"[ Server ] 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"` `"[ Server ] 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"`
) )
}
}) })
}) })
...@@ -203,6 +203,30 @@ describe('app-dir - capture-console-error-owner-stack', () => { ...@@ -203,6 +203,30 @@ describe('app-dir - capture-console-error-owner-stack', () => {
const result = await getRedboxResult(browser) const result = await getRedboxResult(browser)
if (process.env.__NEXT_EXPERIMENTAL_NEW_DEV_OVERLAY === 'true') {
expect(result).toMatchInlineSnapshot(`
{
"callStacks": "Page
app/rsc/page.js (2:17)
JSON.parse
<anonymous> (0:0)
Page
<anonymous> (0:0)",
"count": 1,
"description": "Error: boom",
"source": "app/rsc/page.js (2:17) @ Page
1 | export default function Page() {
> 2 | console.error(new Error('boom'))
| ^
3 | return <p>rsc</p>
4 | }
5 |",
"title": "Console Error
Server",
}
`)
} else {
if (process.env.TURBOPACK) { if (process.env.TURBOPACK) {
expect(result).toMatchInlineSnapshot(` expect(result).toMatchInlineSnapshot(`
{ {
...@@ -248,6 +272,7 @@ describe('app-dir - capture-console-error-owner-stack', () => { ...@@ -248,6 +272,7 @@ describe('app-dir - capture-console-error-owner-stack', () => {
} }
`) `)
} }
}
}) })
it('should display the error message in error event when event.error is not present', async () => { it('should display the error message in error event when event.error is not present', async () => {
......
...@@ -19,14 +19,23 @@ describe('Dynamic IO Dev Errors', () => { ...@@ -19,14 +19,23 @@ describe('Dynamic IO Dev Errors', () => {
files: __dirname, files: __dirname,
}) })
const isNewOverlay =
process.env.__NEXT_EXPERIMENTAL_NEW_DEV_OVERLAY === 'true'
it('should show a red box error on the SSR render', async () => { it('should show a red box error on the SSR render', async () => {
const browser = await next.browser('/error') const browser = await next.browser('/error')
await openRedbox(browser) await openRedbox(browser)
if (isNewOverlay) {
expect(await getRedboxDescription(browser)).toMatchInlineSnapshot(
`"Error: Route "/error" used \`Math.random()\` outside of \`"use cache"\` and without explicitly calling \`await connection()\` beforehand. See more info here: https://nextjs.org/docs/messages/next-prerender-random"`
)
} else {
expect(await getRedboxDescription(browser)).toMatchInlineSnapshot( expect(await getRedboxDescription(browser)).toMatchInlineSnapshot(
`"[ Server ] Error: Route "/error" used \`Math.random()\` outside of \`"use cache"\` and without explicitly calling \`await connection()\` beforehand. See more info here: https://nextjs.org/docs/messages/next-prerender-random"` `"[ Server ] Error: Route "/error" used \`Math.random()\` outside of \`"use cache"\` and without explicitly calling \`await connection()\` beforehand. See more info here: https://nextjs.org/docs/messages/next-prerender-random"`
) )
}
}) })
it('should show a red box error on client navigations', async () => { it('should show a red box error on client navigations', async () => {
...@@ -39,10 +48,15 @@ describe('Dynamic IO Dev Errors', () => { ...@@ -39,10 +48,15 @@ describe('Dynamic IO Dev Errors', () => {
await browser.elementByCss("[href='/error']").click() await browser.elementByCss("[href='/error']").click()
await openRedbox(browser) await openRedbox(browser)
if (isNewOverlay) {
expect(await getRedboxDescription(browser)).toMatchInlineSnapshot(
`"Error: Route "/error" used \`Math.random()\` outside of \`"use cache"\` and without explicitly calling \`await connection()\` beforehand. See more info here: https://nextjs.org/docs/messages/next-prerender-random"`
)
} else {
expect(await getRedboxDescription(browser)).toMatchInlineSnapshot( expect(await getRedboxDescription(browser)).toMatchInlineSnapshot(
`"[ Server ] Error: Route "/error" used \`Math.random()\` outside of \`"use cache"\` and without explicitly calling \`await connection()\` beforehand. See more info here: https://nextjs.org/docs/messages/next-prerender-random"` `"[ Server ] Error: Route "/error" used \`Math.random()\` outside of \`"use cache"\` and without explicitly calling \`await connection()\` beforehand. See more info here: https://nextjs.org/docs/messages/next-prerender-random"`
) )
}
}) })
it('should not log unhandled rejections for persistently thrown top-level errors', async () => { it('should not log unhandled rejections for persistently thrown top-level errors', async () => {
...@@ -86,9 +100,15 @@ describe('Dynamic IO Dev Errors', () => { ...@@ -86,9 +100,15 @@ describe('Dynamic IO Dev Errors', () => {
const description = await getRedboxDescription(browser) const description = await getRedboxDescription(browser)
if (isNewOverlay) {
expect(description).toMatchInlineSnapshot(
`"Error: Route "/no-accessed-data": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense"`
)
} else {
expect(description).toMatchInlineSnapshot( expect(description).toMatchInlineSnapshot(
`"[ Server ] Error: Route "/no-accessed-data": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense"` `"[ Server ] Error: Route "/no-accessed-data": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense"`
) )
}
// Expand the stack frames, since the first frame `Page [Server] <anonymous>` is treated as ignored. // Expand the stack frames, since the first frame `Page [Server] <anonymous>` is treated as ignored.
// TODO: Remove the filter of anonymous frames when we have a better way to handle them. // TODO: Remove the filter of anonymous frames when we have a better way to handle them.
......
...@@ -16,9 +16,15 @@ describe('serialize-circular-error', () => { ...@@ -16,9 +16,15 @@ describe('serialize-circular-error', () => {
const description = await getRedboxDescription(browser) const description = await getRedboxDescription(browser)
// React cannot serialize thrown objects with circular references // React cannot serialize thrown objects with circular references
if (process.env.__NEXT_EXPERIMENTAL_NEW_DEV_OVERLAY === 'true') {
expect(description).toBe( expect(description).toBe(
'[ Server ] Error: An error occurred but serializing the error message failed.' `Error: An error occurred but serializing the error message failed.`
) )
} else {
expect(description).toBe(
`[ Server ] Error: An error occurred but serializing the error message failed.`
)
}
const output = next.cliOutput const output = next.cliOutput
expect(output).toContain( expect(output).toContain(
......
...@@ -6,6 +6,9 @@ describe('app dir - global error', () => { ...@@ -6,6 +6,9 @@ describe('app dir - global error', () => {
files: __dirname, files: __dirname,
}) })
const isNewOverlay =
process.env.__NEXT_EXPERIMENTAL_NEW_DEV_OVERLAY === 'true'
it('should trigger error component when an error happens during rendering', async () => { it('should trigger error component when an error happens during rendering', async () => {
const browser = await next.browser('/client') const browser = await next.browser('/client')
await browser await browser
...@@ -30,10 +33,14 @@ describe('app dir - global error', () => { ...@@ -30,10 +33,14 @@ describe('app dir - global error', () => {
if (isNextDev) { if (isNextDev) {
await assertHasRedbox(browser) await assertHasRedbox(browser)
const description = await getRedboxDescription(browser) const description = await getRedboxDescription(browser)
if (isNewOverlay) {
expect(description).toMatchInlineSnapshot(`"Error: server page error"`)
} else {
expect(description).toMatchInlineSnapshot( expect(description).toMatchInlineSnapshot(
`"[ Server ] Error: server page error"` `"[ Server ] Error: server page error"`
) )
} }
}
// Show original error message in dev mode, but hide with the react fallback RSC error message in production mode // Show original error message in dev mode, but hide with the react fallback RSC error message in production mode
expect(await browser.elementByCss('#error').text()).toBe( expect(await browser.elementByCss('#error').text()).toBe(
isNextDev isNextDev
...@@ -74,10 +81,14 @@ describe('app dir - global error', () => { ...@@ -74,10 +81,14 @@ describe('app dir - global error', () => {
if (isNextDev) { if (isNextDev) {
await assertHasRedbox(browser) await assertHasRedbox(browser)
const description = await getRedboxDescription(browser) const description = await getRedboxDescription(browser)
if (isNewOverlay) {
expect(description).toMatchInlineSnapshot(`"Error: Metadata error"`)
} else {
expect(description).toMatchInlineSnapshot( expect(description).toMatchInlineSnapshot(
`"[ Server ] Error: Metadata error"` `"[ Server ] Error: Metadata error"`
) )
} }
}
expect(await browser.elementByCss('h1').text()).toBe('Global Error') expect(await browser.elementByCss('h1').text()).toBe('Global Error')
expect(await browser.elementByCss('#error').text()).toBe( expect(await browser.elementByCss('#error').text()).toBe(
isNextDev isNextDev
......
...@@ -17,10 +17,14 @@ describe('app dir - global error - layout error', () => { ...@@ -17,10 +17,14 @@ describe('app dir - global error - layout error', () => {
if (isNextDev) { if (isNextDev) {
await assertHasRedbox(browser) await assertHasRedbox(browser)
const description = await getRedboxDescription(browser) const description = await getRedboxDescription(browser)
if (process.env.__NEXT_EXPERIMENTAL_NEW_DEV_OVERLAY === 'true') {
expect(description).toMatchInlineSnapshot(`"Error: layout error"`)
} else {
expect(description).toMatchInlineSnapshot( expect(description).toMatchInlineSnapshot(
`"[ Server ] Error: layout error"` `"[ Server ] Error: layout error"`
) )
} }
}
expect(await browser.elementByCss('h1').text()).toBe('Global Error') expect(await browser.elementByCss('h1').text()).toBe('Global Error')
expect(await browser.elementByCss('#error').text()).toBe( expect(await browser.elementByCss('#error').text()).toBe(
......
...@@ -18,6 +18,9 @@ describe('use-cache-close-over-function', () => { ...@@ -18,6 +18,9 @@ describe('use-cache-close-over-function', () => {
return return
} }
const isNewOverlay =
process.env.__NEXT_EXPERIMENTAL_NEW_DEV_OVERLAY === 'true'
if (isNextDev) { if (isNextDev) {
it('should show an error toast for client-side usage', async () => { it('should show an error toast for client-side usage', async () => {
const outputIndex = next.cliOutput.length const outputIndex = next.cliOutput.length
...@@ -28,11 +31,19 @@ describe('use-cache-close-over-function', () => { ...@@ -28,11 +31,19 @@ describe('use-cache-close-over-function', () => {
const errorDescription = await getRedboxDescription(browser) const errorDescription = await getRedboxDescription(browser)
const errorSource = await getRedboxSource(browser) const errorSource = await getRedboxSource(browser)
if (isNewOverlay) {
expect(errorDescription).toMatchInlineSnapshot(`
"Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server". Or maybe you meant to call this function rather than return it.
[function fn]
^^^^^^^^^^^"
`)
} else {
expect(errorDescription).toMatchInlineSnapshot(` expect(errorDescription).toMatchInlineSnapshot(`
"[ Prerender ] Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server". Or maybe you meant to call this function rather than return it. "[ Prerender ] Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server". Or maybe you meant to call this function rather than return it.
[function fn] [function fn]
^^^^^^^^^^^" ^^^^^^^^^^^"
`) `)
}
expect(errorSource).toMatchInlineSnapshot(` expect(errorSource).toMatchInlineSnapshot(`
"app/client/page.tsx (8:3) @ createCachedFn "app/client/page.tsx (8:3) @ createCachedFn
...@@ -86,11 +97,19 @@ describe('use-cache-close-over-function', () => { ...@@ -86,11 +97,19 @@ describe('use-cache-close-over-function', () => {
const errorDescription = await getRedboxDescription(browser) const errorDescription = await getRedboxDescription(browser)
const errorSource = await getRedboxSource(browser) const errorSource = await getRedboxSource(browser)
if (isNewOverlay) {
expect(errorDescription).toMatchInlineSnapshot(`
"Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server". Or maybe you meant to call this function rather than return it.
[function fn]
^^^^^^^^^^^"
`)
} else {
expect(errorDescription).toMatchInlineSnapshot(` expect(errorDescription).toMatchInlineSnapshot(`
"[ Prerender ] Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server". Or maybe you meant to call this function rather than return it. "[ Prerender ] Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server". Or maybe you meant to call this function rather than return it.
[function fn] [function fn]
^^^^^^^^^^^" ^^^^^^^^^^^"
`) `)
}
expect(errorSource).toMatchInlineSnapshot(` expect(errorSource).toMatchInlineSnapshot(`
"app/server/page.tsx (6:3) @ createCachedFn "app/server/page.tsx (6:3) @ createCachedFn
......
...@@ -11,6 +11,8 @@ import { ...@@ -11,6 +11,8 @@ import {
import stripAnsi from 'strip-ansi' import stripAnsi from 'strip-ansi'
const isExperimentalReact = process.env.__NEXT_EXPERIMENTAL_PPR const isExperimentalReact = process.env.__NEXT_EXPERIMENTAL_PPR
const isNewDevOverlay =
process.env.__NEXT_EXPERIMENTAL_NEW_DEV_OVERLAY === 'true'
const expectedErrorMessage = const expectedErrorMessage =
'Error: Filling a cache during prerender timed out, likely because request-specific arguments such as params, searchParams, cookies() or dynamic data were used inside "use cache".' 'Error: Filling a cache during prerender timed out, likely because request-specific arguments such as params, searchParams, cookies() or dynamic data were used inside "use cache".'
...@@ -41,7 +43,11 @@ describe('use-cache-hanging-inputs', () => { ...@@ -41,7 +43,11 @@ describe('use-cache-hanging-inputs', () => {
const errorDescription = await getRedboxDescription(browser) const errorDescription = await getRedboxDescription(browser)
const errorSource = await getRedboxSource(browser) const errorSource = await getRedboxSource(browser)
if (isNewDevOverlay) {
expect(errorDescription).toBe(expectedErrorMessage)
} else {
expect(errorDescription).toBe(`[ Cache ] ${expectedErrorMessage}`) expect(errorDescription).toBe(`[ Cache ] ${expectedErrorMessage}`)
}
const cliOutput = stripAnsi(next.cliOutput.slice(outputIndex)) const cliOutput = stripAnsi(next.cliOutput.slice(outputIndex))
...@@ -100,7 +106,11 @@ describe('use-cache-hanging-inputs', () => { ...@@ -100,7 +106,11 @@ describe('use-cache-hanging-inputs', () => {
const errorDescription = await getRedboxDescription(browser) const errorDescription = await getRedboxDescription(browser)
const errorSource = await getRedboxSource(browser) const errorSource = await getRedboxSource(browser)
if (isNewDevOverlay) {
expect(errorDescription).toBe(expectedErrorMessage)
} else {
expect(errorDescription).toBe(`[ Cache ] ${expectedErrorMessage}`) expect(errorDescription).toBe(`[ Cache ] ${expectedErrorMessage}`)
}
const cliOutput = stripAnsi(next.cliOutput.slice(outputIndex)) const cliOutput = stripAnsi(next.cliOutput.slice(outputIndex))
...@@ -146,7 +156,11 @@ describe('use-cache-hanging-inputs', () => { ...@@ -146,7 +156,11 @@ describe('use-cache-hanging-inputs', () => {
const errorDescription = await getRedboxDescription(browser) const errorDescription = await getRedboxDescription(browser)
const errorSource = await getRedboxSource(browser) const errorSource = await getRedboxSource(browser)
if (isNewDevOverlay) {
expect(errorDescription).toBe(expectedErrorMessage)
} else {
expect(errorDescription).toBe(`[ Cache ] ${expectedErrorMessage}`) expect(errorDescription).toBe(`[ Cache ] ${expectedErrorMessage}`)
}
const cliOutput = stripAnsi(next.cliOutput.slice(outputIndex)) const cliOutput = stripAnsi(next.cliOutput.slice(outputIndex))
...@@ -203,14 +217,24 @@ describe('use-cache-hanging-inputs', () => { ...@@ -203,14 +217,24 @@ describe('use-cache-hanging-inputs', () => {
const expectedErrorMessagePpr = const expectedErrorMessagePpr =
'Error: Route "/bound-args": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don\'t have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense' 'Error: Route "/bound-args": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don\'t have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense'
expect(errorDescription).toBe(`[ Server ] ${expectedErrorMessagePpr}`) if (isNewDevOverlay) {
expect(errorDescription).toBe(expectedErrorMessagePpr)
} else {
expect(errorDescription).toBe(
`[ Server ] ${expectedErrorMessagePpr}`
)
}
expect(cliOutput).toContain( expect(cliOutput).toContain(
`${expectedErrorMessagePpr} `${expectedErrorMessagePpr}
at Page [Server] (<anonymous>)` at Page [Server] (<anonymous>)`
) )
} else {
if (isNewDevOverlay) {
expect(errorDescription).toBe(expectedErrorMessage)
} else { } else {
expect(errorDescription).toBe(`[ Cache ] ${expectedErrorMessage}`) expect(errorDescription).toBe(`[ Cache ] ${expectedErrorMessage}`)
}
if (isTurbopack) { if (isTurbopack) {
// TODO(veil): For Turbopack, a fix in the React Flight Client, where // TODO(veil): For Turbopack, a fix in the React Flight Client, where
...@@ -251,11 +275,19 @@ describe('use-cache-hanging-inputs', () => { ...@@ -251,11 +275,19 @@ describe('use-cache-hanging-inputs', () => {
const title = await getRedboxTitle(browser) const title = await getRedboxTitle(browser)
const description = await getRedboxDescription(browser) const description = await getRedboxDescription(browser)
if (isNewDevOverlay) {
expect({ count, title, description }).toEqual({
count: 1,
title: 'Unhandled Runtime Error\nCache',
description: 'Error: kaputt!',
})
} else {
expect({ count, title, description }).toEqual({ expect({ count, title, description }).toEqual({
count: 1, count: 1,
title: 'Unhandled Runtime Error', title: 'Unhandled Runtime Error',
description: '[ Cache ] Error: kaputt!', description: '[ Cache ] Error: kaputt!',
}) })
}
}) })
}) })
} else { } else {
......
...@@ -39,7 +39,11 @@ describe('use-cache-standalone-search-params', () => { ...@@ -39,7 +39,11 @@ describe('use-cache-standalone-search-params', () => {
const errorSource = await getRedboxSource(browser) const errorSource = await getRedboxSource(browser)
const expectedErrorMessage = getExpectedErrorMessage(route) const expectedErrorMessage = getExpectedErrorMessage(route)
if (process.env.__NEXT_EXPERIMENTAL_NEW_DEV_OVERLAY === 'true') {
expect(errorDescription).toBe(expectedErrorMessage)
} else {
expect(errorDescription).toBe(`[ Cache ] ${expectedErrorMessage}`) expect(errorDescription).toBe(`[ Cache ] ${expectedErrorMessage}`)
}
const cliOutput = stripAnsi(next.cliOutput.slice(outputIndex)) const cliOutput = stripAnsi(next.cliOutput.slice(outputIndex))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment