Skip to content

Commit 9f5438f

Browse files
authored
fix: add an error boundary for each section (#176)
This is a guardrail to keep a bad section from crashing the whole app. It's a bit of a hack until I can figure out what's going on with #174 I intentionally broke that section to check how it worked, this is what it looks like: <img width="821" height="341" alt="image" src="https://github.com/user-attachments/assets/1ecaf662-de94-4eff-b5e5-7fbe7a549266" /> ## Checklist - [x] Code is formatted (`yarn format`) - [x] Code is linted (`yarn lint`) - [x] Code builds (`yarn build`) - [x] Tests pass (`yarn test`) - [x] Commit messages and/or this PR's title are formatted per [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)
1 parent de5e862 commit 9f5438f

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/components/section.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { type ReactNode } from "react";
2+
import { ErrorBoundary } from "react-error-boundary";
23
import { type IconType } from "react-icons/lib";
3-
import { Accordion, HStack, Icon } from "@chakra-ui/react";
4+
import { Accordion, Alert, HStack, Icon } from "@chakra-ui/react";
45

56
export default function Section({
67
title,
@@ -25,8 +26,24 @@ export default function Section({
2526
<Accordion.ItemIndicator />
2627
</Accordion.ItemTrigger>
2728
<Accordion.ItemContent>
28-
<Accordion.ItemBody>{children}</Accordion.ItemBody>
29+
<Accordion.ItemBody>
30+
<ErrorBoundary FallbackComponent={FallbackComponent}>
31+
{children}
32+
</ErrorBoundary>
33+
</Accordion.ItemBody>
2934
</Accordion.ItemContent>
3035
</Accordion.Item>
3136
);
3237
}
38+
39+
function FallbackComponent({ error }: { error: Error }) {
40+
return (
41+
<Alert.Root status={"error"}>
42+
<Alert.Indicator />
43+
<Alert.Content>
44+
<Alert.Title>An error occurred during rendering</Alert.Title>
45+
<Alert.Description>{error.message}</Alert.Description>
46+
</Alert.Content>
47+
</Alert.Root>
48+
);
49+
}

0 commit comments

Comments
 (0)