-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Catch layout error in global-error (#52654)
When there's a runtime error showing in root layout (server components), it should be able to catch by `global-error`. For server components, we caught it and gonna render the error fallback components (either not-found or error page), and the response status is `200`, and since we'll display error dev overlay in developmenet mode so we only render `global-error` for production. So that you can catch more errors with `global-error` and maybe do potential error tracking on client side. Follow up of #52573 Closes NEXT-1442 minor refactor: move `appUsingSizeAdjust` into `Metadata` component so that we can just tune the flag as prop
- Loading branch information
Showing
13 changed files
with
128 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions
14
test/e2e/app-dir/global-error/layout-error/app/global-error.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use client' | ||
|
||
export default function GlobalError({ error }) { | ||
return ( | ||
<html> | ||
<head></head> | ||
<body> | ||
<h1>Global Error</h1> | ||
<p id="error">{`Global error: ${error?.message}`}</p> | ||
{error?.digest && <p id="digest">{error?.digest}</p>} | ||
</body> | ||
</html> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default function layout() { | ||
throw new Error('Global error: layout error') | ||
} | ||
|
||
export const revalidate = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function page() { | ||
return <div>Page</div> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { getRedboxHeader, hasRedbox } from 'next-test-utils' | ||
import { createNextDescribe } from 'e2e-utils' | ||
|
||
async function testDev(browser, errorRegex) { | ||
expect(await hasRedbox(browser, true)).toBe(true) | ||
expect(await getRedboxHeader(browser)).toMatch(errorRegex) | ||
} | ||
|
||
createNextDescribe( | ||
'app dir - global error - layout error', | ||
{ | ||
files: __dirname, | ||
skipDeployment: true, | ||
}, | ||
({ next, isNextDev }) => { | ||
it('should render global error for error in server components', async () => { | ||
const browser = await next.browser('/') | ||
|
||
if (isNextDev) { | ||
await testDev(browser, /Global error: layout error/) | ||
} else { | ||
expect(await browser.elementByCss('h1').text()).toBe('Global Error') | ||
expect(await browser.elementByCss('#error').text()).toBe( | ||
'Global error: 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.elementByCss('#digest').text()).toMatch(/\w+/) | ||
} | ||
}) | ||
} | ||
) |