Skip to content

Commit

Permalink
Remove custom digest support. Take into account stack
Browse files Browse the repository at this point in the history
  • Loading branch information
timneutkens committed Oct 19, 2022
1 parent 8995f6b commit c5b1580
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 41 deletions.
6 changes: 1 addition & 5 deletions packages/next/server/app-render.tsx
Expand Up @@ -190,12 +190,8 @@ function createErrorHandler(
// console.error(_source, err)
console.error(err)
capturedErrors.push(err)
if (err.digest) {
return err.digest
}

// TODO-APP: look at using webcrypto instead. Requires a promise to be awaited.
return stringHash(err.message).toString()
return stringHash(err.message + err.stack + (err.digest || '')).toString()
}
}

Expand Down
38 changes: 2 additions & 36 deletions test/e2e/app-dir/index.test.ts
Expand Up @@ -1578,7 +1578,7 @@ describe('app dir', () => {
expect(
await browser.waitForElementByCss('#error-boundary-digest').text()
// Digest of the error message should be stable.
).toBe('2397877870')
).not.toBe('')
// TODO-APP: ensure error overlay is shown for errors that happened before/during hydration
// expect(await hasRedbox(browser)).toBe(true)
// expect(await getRedboxHeader(browser)).toMatch(/this is a test/)
Expand All @@ -1592,41 +1592,7 @@ describe('app dir', () => {
expect(
await browser.waitForElementByCss('#error-boundary-digest').text()
// Digest of the error message should be stable.
).toBe('2397877870')
}
})

it('should trigger error component when an error with custom digest happens during server components rendering', async () => {
const browser = await webdriver(
next.url,
'/error/server-component/custom-digest'
)

if (isDev) {
expect(
await browser
.waitForElementByCss('#error-boundary-message')
.elementByCss('#error-boundary-message')
.text()
).toBe('this is a test')
expect(
await browser.waitForElementByCss('#error-boundary-digest').text()
// Digest of the error message should be stable.
).toBe('custom')
// TODO-APP: ensure error overlay is shown for errors that happened before/during hydration
// expect(await hasRedbox(browser)).toBe(true)
// expect(await getRedboxHeader(browser)).toMatch(/this is a test/)
} else {
await browser
expect(
await browser.waitForElementByCss('#error-boundary-message').text()
).toBe(
'An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.'
)
expect(
await browser.waitForElementByCss('#error-boundary-digest').text()
// Digest of the error message should be stable.
).toBe('custom')
).not.toBe('')
}
})

Expand Down

0 comments on commit c5b1580

Please sign in to comment.