Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[dev-overlay] handle ssrd nextjs internal errors in overlay #76124

Merged
merged 6 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 9 additions & 0 deletions packages/next/src/client/app-index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { MissingSlotContext } from '../shared/lib/app-router-context.shared-runt
import { setAppBuildId } from './app-build-id'
import { shouldRenderRootLevelErrorOverlay } from './lib/is-error-thrown-while-rendering-rsc'
import { handleClientError } from './components/errors/use-error-handler'
import { isNextRouterError } from './components/is-next-router-error'

/// <reference types="react-dom/experimental" />

Expand Down Expand Up @@ -304,7 +305,15 @@ function devQueueSsrError(): Error | undefined {
'data-next-error-message'
)!
const stack = ssrErrorTemplateTag.getAttribute('data-next-error-stack')
const digest = ssrErrorTemplateTag.getAttribute('data-next-error-digest')
const error = new Error(message)
if (digest) {
;(error as any).digest = digest
}
// Skip Next.js SSR'd internal errors that which will be handled by the error boundaries.
if (isNextRouterError(error)) {
return
}
error.stack = stack || ''
return error
}
Expand Down
1 change: 1 addition & 0 deletions packages/next/src/server/app-render/app-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,7 @@ async function getErrorRSCPayload(
{process.env.NODE_ENV !== 'production' && err ? (
<template
data-next-error-message={err.message}
data-next-error-digest={'digest' in err ? err.digest : ''}
data-next-error-stack={err.stack}
/>
) : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('error-ignored-frames', () => {
at OuterLayoutRouter (../src/client/components/layout-router.tsx (607:20))
at Router (../src/client/components/app-router.tsx (633:8))
at AppRouter (../src/client/components/app-router.tsx (679:8))
at ServerRoot (../src/client/app-index.tsx (200:6))"
at ServerRoot (../src/client/app-index.tsx (201:6))"
`)
}
})
Expand Down Expand Up @@ -85,7 +85,7 @@ describe('error-ignored-frames', () => {
at ClientPageRoot (../src/client/components/client-page.tsx (60:13))
at Router (../src/client/components/app-router.tsx (633:8))
at AppRouter (../src/client/components/app-router.tsx (679:8))
at ServerRoot (../src/client/app-index.tsx (200:6))"
at ServerRoot (../src/client/app-index.tsx (201:6))"
`)
}
})
Expand Down Expand Up @@ -123,12 +123,12 @@ describe('error-ignored-frames', () => {
} else {
expect(expendedStack).toMatchInlineSnapshot(`
"at eval (app/interleaved/page.tsx (7:11))
at invokeCallback (node_modules/interleave/index.js (2:1))
at Page (app/interleaved/page.tsx (6:37))
at invokeCallback (node_modules/interleave/index.js (2:1))
at ClientPageRoot (../src/client/components/client-page.tsx (60:13))
at Router (../src/client/components/app-router.tsx (633:8))
at AppRouter (../src/client/components/app-router.tsx (679:8))
at ServerRoot (../src/client/app-index.tsx (200:6))"
at ServerRoot (../src/client/app-index.tsx (201:6))"
`)
}
})
Expand Down
7 changes: 7 additions & 0 deletions test/development/app-dir/ssr-only-error/app/notfound/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { notFound } from 'next/navigation'

export default async function Home() {
notFound()
}

export const dynamic = 'force-dynamic'
11 changes: 11 additions & 0 deletions test/development/app-dir/ssr-only-error/ssr-only-error.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { nextTestSetup } from 'e2e-utils'
import {
assertNoRedbox,
getRedboxDescription,
getRedboxSource,
hasErrorToast,
Expand Down Expand Up @@ -40,4 +41,14 @@ describe('ssr-only-error', () => {
}
`)
})

it('should not handle internal nextjs errors that will be handled by error boundaries', async () => {
const browser = await next.browser('/notfound')

await assertNoRedbox(browser)
expect(await hasErrorToast(browser)).toBe(false)

const text = await browser.elementByCss('body').text()
expect(text).toBe('404\nThis page could not be found.')
})
})
Loading