-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from ed-pilots-network/root-error-boundary
Setup root error boundary to gracefully handle all unhandled errors
- Loading branch information
Showing
8 changed files
with
99 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use client'; | ||
|
||
import { Button, Center, Flex, Heading, Text } from '@chakra-ui/react'; | ||
import layoutConfig from './_config/layout'; | ||
|
||
export default function Error({ | ||
error, | ||
reset, | ||
}: { | ||
error: Error; | ||
reset: () => void; | ||
}) { | ||
return ( | ||
<Center width="100%"> | ||
<Flex | ||
flexDirection="column" | ||
alignItems="center" | ||
gap="24px" | ||
maxWidth={layoutConfig.maxWidth} | ||
> | ||
<Heading | ||
as="h1" | ||
size={{ base: 'md', md: 'lg', lg: 'lg' }} | ||
marginX={{ base: 'auto', md: '0', lg: '0' }} | ||
> | ||
Something went wrong! | ||
</Heading> | ||
<Text as="samp">{error.message}</Text> | ||
<Button type="button" variant="outline" onClick={() => reset()}> | ||
Try again | ||
</Button> | ||
</Flex> | ||
</Center> | ||
); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use client'; | ||
|
||
const PageClient = () => { | ||
throw new Error('This is a simulated client rendering error.'); | ||
}; | ||
|
||
export default PageClient; |
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,8 @@ | ||
import PageClient from './page.client'; | ||
|
||
// Avoid statically building this page during build. | ||
export const dynamic = 'force-dynamic'; | ||
|
||
export default async function Page() { | ||
return <PageClient />; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Avoid statically building this page during build. | ||
export const dynamic = 'force-dynamic'; | ||
|
||
export default async function Page() { | ||
throw new Error('This is a simulated server rendering error.'); | ||
} |
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,22 @@ | ||
import { test, expect } from '@playwright/test'; | ||
|
||
test('server rendering errors should get caught and gracefully render error', async ({ | ||
page, | ||
}) => { | ||
await page.goto('/playground/server-error'); | ||
await expect(page.locator('h1')).toContainText('Something went wrong!'); | ||
// Error messages for server rendering get replaced for security during builds | ||
await expect(page.locator('samp')).toContainText( | ||
'An error occurred in the Server Components render.', | ||
); | ||
}); | ||
|
||
test('client rendering errors should get caught and gracefully render error', async ({ | ||
page, | ||
}) => { | ||
await page.goto('/playground/client-error'); | ||
await expect(page.locator('h1')).toContainText('Something went wrong!'); | ||
await expect(page.locator('samp')).toContainText( | ||
'This is a simulated client rendering error', | ||
); | ||
}); |