Skip to content

Commit db7f39c

Browse files
committed
Resolve TypeError: Cannot read properties of null (reading 'appendChild') on default error boundary
1 parent cb1040b commit db7f39c

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

app/root.tsx

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
HydrationUtilsPreRender,
2020
} from "~/useHydrated";
2121
import settings from "./settings";
22+
import { ReactNode } from "react";
2223

2324
export const links: LinksFunction = () => [
2425
...(cssBundleHref ? [{ rel: "stylesheet", href: cssBundleHref }] : []),
@@ -37,8 +38,29 @@ export async function loader() {
3738
}
3839

3940
export default function App() {
40-
useGlobalProgress();
4141
const data = useLoaderData<typeof loader>();
42+
return (
43+
<Scaffold>
44+
<div
45+
id="portal"
46+
style={{ position: "fixed", left: 0, top: 0, zIndex: 9999 }}
47+
/>
48+
<script
49+
// load client side env vars
50+
dangerouslySetInnerHTML={{
51+
__html: `window.ENV = ${JSON.stringify(data.ENV)};`,
52+
}}
53+
/>
54+
<HydrationUtilsPreRender />
55+
<Outlet />
56+
<HydrationUtilsPostRender />
57+
<ScrollRestoration />
58+
</Scaffold>
59+
);
60+
}
61+
62+
function Scaffold({ children }: { children?: ReactNode }) {
63+
useGlobalProgress();
4264

4365
return (
4466
<html lang="en">
@@ -53,20 +75,7 @@ export default function App() {
5375
></script>
5476
</head>
5577
<body>
56-
<div
57-
id="portal"
58-
style={{ position: "fixed", left: 0, top: 0, zIndex: 9999 }}
59-
/>
60-
<HydrationUtilsPreRender />
61-
<Outlet />
62-
<HydrationUtilsPostRender />
63-
<ScrollRestoration />
64-
<script
65-
// load client side env vars
66-
dangerouslySetInnerHTML={{
67-
__html: `window.ENV = ${JSON.stringify(data.ENV)};`,
68-
}}
69-
/>
78+
{children}
7079
<Scripts />
7180
<LiveReload />
7281
</body>
@@ -81,18 +90,9 @@ const reloadOnErrors = [
8190
"NetworkError",
8291
];
8392

84-
const ignoreErrors = ["AbortError"];
85-
8693
export function ErrorBoundary() {
8794
const error = useRouteError();
8895

89-
if (
90-
ignoreErrors.some((msg) =>
91-
`${error}`.toLowerCase().includes(msg.toLowerCase())
92-
)
93-
) {
94-
return <></>;
95-
}
9696
if (
9797
reloadOnErrors.some((msg) =>
9898
`${error}`.toLowerCase().includes(msg.toLowerCase())
@@ -106,18 +106,18 @@ export function ErrorBoundary() {
106106
// when true, this is what used to go to `CatchBoundary`
107107
if (isRouteErrorResponse(error)) {
108108
return (
109-
<div>
109+
<Scaffold>
110110
<p>Status: {error.status}</p>
111111
<pre>{JSON.stringify(error.data)}</pre>
112-
</div>
112+
</Scaffold>
113113
);
114114
}
115115

116116
return (
117-
<div>
117+
<Scaffold>
118118
<h1>Uh oh ...</h1>
119119
<p>Something went wrong.</p>
120120
<pre>{`${error}`}</pre>
121-
</div>
121+
</Scaffold>
122122
);
123123
}

0 commit comments

Comments
 (0)