Skip to content

Commit 0bed199

Browse files
authored
Merge pull request #1656 from thunderstore-io/eb2-error-logging
Replace root error boundary with RouteErrorBoundary
2 parents ecf7186 + 7a38fee commit 0bed199

File tree

3 files changed

+15
-42
lines changed

3 files changed

+15
-42
lines changed

apps/cyberstorm-remix/app/commonComponents/ErrorBoundary/RouteErrorBoundary.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import type { JSX } from "react";
1+
import { useEffect, type JSX } from "react";
22
import { isRouteErrorResponse, useRouteError } from "react-router";
3+
import { captureRemixErrorBoundaryError } from "@sentry/remix";
34

45
import { ApiError } from "@thunderstore/thunderstore-api";
56

@@ -15,6 +16,17 @@ type StatusCode = number | "???";
1516
export function RouteErrorBoundary() {
1617
const error = useRouteError();
1718

19+
// Seeing double console logs caused by React's strictMode (that
20+
// *should* happen only in dev mode) makes me want to ensure any
21+
// rerenders don't get logged in Sentry twice.
22+
useEffect(() => {
23+
if (error && import.meta.env.PROD) {
24+
captureRemixErrorBoundaryError(error);
25+
} else if (error) {
26+
console.error("Error boundary caught error", error);
27+
}
28+
}, [error]);
29+
1830
let statusCode: StatusCode = "???";
1931

2032
if (isRouteErrorResponse(error)) {

apps/cyberstorm-remix/app/root.tsx

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ import {
1010
ScrollRestoration,
1111
type ShouldRevalidateFunctionArgs,
1212
type UIMatch,
13-
isRouteErrorResponse,
1413
useLoaderData,
1514
useLocation,
1615
useMatches,
17-
useRouteError,
1816
} from "react-router";
1917
// import { LinksFunction } from "@remix-run/react/dist/routeModules";
2018
import { Provider as RadixTooltip } from "@radix-ui/react-tooltip";
@@ -30,7 +28,7 @@ import {
3028
import { DapperTs } from "@thunderstore/dapper-ts";
3129
import { type CurrentUser } from "@thunderstore/dapper/types";
3230

33-
import { captureRemixErrorBoundaryError, withSentry } from "@sentry/remix";
31+
import { withSentry } from "@sentry/remix";
3432
import { memo, type ReactNode, Suspense, useEffect, useRef } from "react";
3533
import { useHydrated } from "remix-utils/use-hydrated";
3634
import Toast from "@thunderstore/cyberstorm/src/newComponents/Toast";
@@ -600,42 +598,7 @@ function App() {
600598
}
601599

602600
export default withSentry(App);
603-
604-
// REMIX TODO: We don't have any data available in the root ErrorBoundary, so we might want to change the designs
605-
export function ErrorBoundary() {
606-
// REMIX TODO: We need to call the loader separately somehow to get the CurrentUser
607-
// const loaderOutput = useLoaderData<RootLoadersType>();
608-
// const parsedLoaderOutput: {
609-
// envStuff: { ENV: { PUBLIC_API_URL: string } };
610-
// sessionId: string | null;
611-
// currentUser: CurrentUser;
612-
// } = JSON.parse(JSON.stringify(loaderOutput));
613-
const error = useRouteError();
614-
if (import.meta.env.PROD) {
615-
captureRemixErrorBoundaryError(error);
616-
} else if (import.meta.env.DEV) {
617-
console.log(error);
618-
}
619-
const isResponseError = isRouteErrorResponse(error);
620-
return (
621-
<div className="error">
622-
<div
623-
className="error__glitch"
624-
data-text={isResponseError ? error.status : 500}
625-
>
626-
<span>{isResponseError ? error.status : 500}</span>
627-
</div>
628-
<div className="error__description">
629-
{isResponseError ? error.data : "Internal server error"}
630-
</div>
631-
{!isResponseError && (
632-
<div className="error__flavor">
633-
Beep boop. Server something error happens.
634-
</div>
635-
)}
636-
</div>
637-
);
638-
}
601+
export { RouteErrorBoundary as ErrorBoundary } from "app/commonComponents/ErrorBoundary";
639602

640603
// Temporary solution for implementing ads
641604
// REMIX TODO: Move to dynamic html

apps/cyberstorm-remix/docs/error-boundary.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ export { RouteErrorBoundary as ErrorBoundary } from "app/commonComponents/ErrorB
1414

1515
### TODO
1616

17-
- Consider replacing the error boundary in `root.tsx` with this one
1817
- Use `RouteErrorBoundary` in route components
19-
- Investigate if [error reporting](https://reactrouter.com/how-to/error-reporting) (via Sentry) should be done separately or implement as a part of the error boundary
2018
- Add "retry buttons" (e.g. reloading the page on 500 series of errors)
2119
- As `RouteErrorBoundary` is all-or-nothing solution when it comes to rendering, consider if there's a need for more granular non-route component level error boundaries. We might not need or want to use them, as error boundaries are intended more for render time errors, and any errors caused by user interaction should be handled by the component logic itself
2220
- If it turns out we don't want other error boundaries, consider renaming `RouteErrorBoundary` to just `ErrorBoundary`

0 commit comments

Comments
 (0)