Skip to content
This repository was archived by the owner on Jul 20, 2022. It is now read-only.

Commit 536a773

Browse files
hide dev error boundary on production build
1 parent 551f559 commit 536a773

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

src/ErrorBoundary.tsx

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
useMemo,
88
useState,
99
} from "react";
10-
import { Links, LiveReload, Scripts, ScrollRestoration } from "remix";
10+
import { Links, LiveReload, Meta, Scripts, ScrollRestoration } from "remix";
1111
import codeStyles from "highlight.js/styles/github-dark.css";
1212
// @ts-ignore
1313
import styleInject from "style-inject";
@@ -140,6 +140,54 @@ export const useError = () => {
140140
export function ErrorBoundary({ error }: { error: Error }) {
141141
console.error(error);
142142

143+
if (process.env.NODE_ENV !== "development") {
144+
return <ProdErrorBoundary error={error} />;
145+
}
146+
147+
return <DevErrorBoundary error={error} />;
148+
}
149+
150+
export function ProdErrorBoundary({ error }: { error: Error }) {
151+
return (
152+
<html lang="en">
153+
<head>
154+
<meta charSet="utf-8" />
155+
<meta name="viewport" content="width=device-width,initial-scale=1" />
156+
<Meta />
157+
<Links />
158+
</head>
159+
160+
<body>
161+
<main
162+
style={{
163+
display: "flex",
164+
justifyContent: "center",
165+
alignItems: "center",
166+
width: "100vw",
167+
height: "100vh",
168+
gap: "1rem",
169+
}}
170+
>
171+
<h1>500</h1>
172+
<span
173+
style={{
174+
height: "2.5rem",
175+
width: "2px",
176+
backgroundColor: "rgb(75, 85, 99)",
177+
}}
178+
/>
179+
<span>Internal Server Error.</span>
180+
</main>
181+
182+
<ScrollRestoration />
183+
184+
<Scripts />
185+
</body>
186+
</html>
187+
);
188+
}
189+
190+
export function DevErrorBoundary({ error }: { error: Error }) {
143191
useLayoutEffect(() => {
144192
styleInject(styles);
145193
styleInject(codeStyles);
@@ -160,7 +208,6 @@ export function ErrorBoundary({ error }: { error: Error }) {
160208
<title>{`💥 ${type}: ${message}`}</title>
161209
<meta charSet="utf-8" />
162210
<meta name="viewport" content="width=device-width,initial-scale=1" />
163-
{/* <link rel="stylesheet" href={codeStyles} /> */}
164211
<link rel="preconnect" href="https://fonts.googleapis.com" />
165212
<link
166213
rel="preconnect"
@@ -171,7 +218,6 @@ export function ErrorBoundary({ error }: { error: Error }) {
171218
href="https://fonts.googleapis.com/css2?family=Lato:ital,wght@0,100;0,300;0,400;0,700;0,900;1,100;1,300;1,400;1,700;1,900&display=swap"
172219
rel="stylesheet"
173220
/>
174-
<Links />
175221
</head>
176222

177223
<body

src/endpoints.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ActionFunction, LoaderFunction, json } from "remix";
22
import { SourceMapConsumer } from "source-map";
33
import { CORSResponse } from "./utils";
44

5-
export const loader: LoaderFunction = async ({ request }) => {
5+
export const loader: LoaderFunction = () => {
66
if (process.env.NODE_ENV !== "development") {
77
throw new Response(null, { status: 404 });
88
}
@@ -11,6 +11,10 @@ export const loader: LoaderFunction = async ({ request }) => {
1111
};
1212

1313
export const action: ActionFunction = async ({ request }) => {
14+
if (process.env.NODE_ENV !== "development") {
15+
throw new Response(null, { status: 404 });
16+
}
17+
1418
const { readFile } = await import("fs/promises");
1519

1620
const url = new URL(request.url);

0 commit comments

Comments
 (0)