Skip to content

Commit 2f0b5a2

Browse files
authored
Also check error.message as digest for recoverable errors in pages (#44185)
Follow up for #44161 According to facebook/react#25313, the `errorInfo.digest` will be moved to `error.digest`, but for now we use it as a fallback for pages. we can remove it later once the migration is done in required react version for nextjs ## Bug - [x] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
1 parent 39f30fb commit 2f0b5a2

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

packages/next/client/on-recoverable-error.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { NEXT_DYNAMIC_NO_SSR_CODE } from '../shared/lib/no-ssr-error'
22

3-
export default function onRecoverableError(err: any) {
3+
export default function onRecoverableError(err: any, errorInfo: any) {
4+
const digest = err.digest || errorInfo.digest
5+
46
// Using default react onRecoverableError
57
// x-ref: https://github.com/facebook/react/blob/d4bc16a7d69eb2ea38a88c8ac0b461d5f72cdcab/packages/react-dom/src/client/ReactDOMRoot.js#L83
68
const defaultOnRecoverableError =
@@ -13,6 +15,6 @@ export default function onRecoverableError(err: any) {
1315
}
1416

1517
// Skip certain custom errors which are not expected to be reported on client
16-
if (err.digest === NEXT_DYNAMIC_NO_SSR_CODE) return
18+
if (digest === NEXT_DYNAMIC_NO_SSR_CODE) return
1719
defaultOnRecoverableError(err)
1820
}

test/development/basic/next-dynamic.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { join } from 'path'
22
import cheerio from 'cheerio'
33
import webdriver from 'next-webdriver'
44
import { createNext, FileRef } from 'e2e-utils'
5-
import { renderViaHTTP, check } from 'next-test-utils'
5+
import { renderViaHTTP, check, hasRedbox } from 'next-test-utils'
66
import { NextInstance } from 'test/lib/next-modes/base'
77

88
describe('basic next/dynamic usage', () => {
@@ -124,6 +124,7 @@ describe('basic next/dynamic usage', () => {
124124
() => browser.elementByCss('body').text(),
125125
/Hello World 1/
126126
)
127+
expect(await hasRedbox(browser)).toBe(false)
127128
} finally {
128129
if (browser) {
129130
await browser.close()

0 commit comments

Comments
 (0)