Skip to content

Commit

Permalink
Also check error.message as digest for recoverable errors in pages (#…
Browse files Browse the repository at this point in the history
…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)
  • Loading branch information
huozhi committed Dec 20, 2022
1 parent 39f30fb commit 2f0b5a2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions packages/next/client/on-recoverable-error.ts
@@ -1,6 +1,8 @@
import { NEXT_DYNAMIC_NO_SSR_CODE } from '../shared/lib/no-ssr-error'

export default function onRecoverableError(err: any) {
export default function onRecoverableError(err: any, errorInfo: any) {
const digest = err.digest || errorInfo.digest

// Using default react onRecoverableError
// x-ref: https://github.com/facebook/react/blob/d4bc16a7d69eb2ea38a88c8ac0b461d5f72cdcab/packages/react-dom/src/client/ReactDOMRoot.js#L83
const defaultOnRecoverableError =
Expand All @@ -13,6 +15,6 @@ export default function onRecoverableError(err: any) {
}

// Skip certain custom errors which are not expected to be reported on client
if (err.digest === NEXT_DYNAMIC_NO_SSR_CODE) return
if (digest === NEXT_DYNAMIC_NO_SSR_CODE) return
defaultOnRecoverableError(err)
}
3 changes: 2 additions & 1 deletion test/development/basic/next-dynamic.test.ts
Expand Up @@ -2,7 +2,7 @@ import { join } from 'path'
import cheerio from 'cheerio'
import webdriver from 'next-webdriver'
import { createNext, FileRef } from 'e2e-utils'
import { renderViaHTTP, check } from 'next-test-utils'
import { renderViaHTTP, check, hasRedbox } from 'next-test-utils'
import { NextInstance } from 'test/lib/next-modes/base'

describe('basic next/dynamic usage', () => {
Expand Down Expand Up @@ -124,6 +124,7 @@ describe('basic next/dynamic usage', () => {
() => browser.elementByCss('body').text(),
/Hello World 1/
)
expect(await hasRedbox(browser)).toBe(false)
} finally {
if (browser) {
await browser.close()
Expand Down

0 comments on commit 2f0b5a2

Please sign in to comment.