-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support
global-error.js
(#596)
- Loading branch information
Showing
9 changed files
with
101 additions
and
33 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
36 changes: 36 additions & 0 deletions
36
packages/react-server/examples/basic/src/routes/global-error.tsx
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,36 @@ | ||
"use client"; | ||
|
||
export default function GlobalError() { | ||
return ( | ||
<html> | ||
<body> | ||
<div | ||
style={{ | ||
height: "100vh", | ||
display: "flex", | ||
flexDirection: "column", | ||
placeContent: "center", | ||
placeItems: "center", | ||
gap: "4px", | ||
fontSize: "16px", | ||
}} | ||
> | ||
<h1>Something went wrong. Please try it again later.</h1> | ||
<div style={{ fontSize: "14px" }}> | ||
Back to{" "} | ||
<a | ||
href="/" | ||
style={{ | ||
textDecoration: "underline", | ||
textUnderlineOffset: "2px", | ||
color: "#3451b2", | ||
}} | ||
> | ||
Home | ||
</a> | ||
</div> | ||
</div> | ||
</body> | ||
</html> | ||
); | ||
} |
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 |
---|---|---|
@@ -1,3 +1,8 @@ | ||
export default function Page() { | ||
import type { PageProps } from "@hiogawa/react-server/server"; | ||
|
||
export default function Page(props: PageProps) { | ||
if ("test-error" in props.searchParams) { | ||
throw new Error("boom!"); | ||
} | ||
return <div>Choose a page from the menu</div>; | ||
} |
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
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,30 @@ | ||
import type { ErrorPageProps } from "../../server"; | ||
|
||
// https://github.com/vercel/next.js/blob/677c9b372faef680d17e9ba224743f44e1107661/packages/next/src/build/webpack/loaders/next-app-loader.ts#L73 | ||
// https://github.com/vercel/next.js/blob/677c9b372faef680d17e9ba224743f44e1107661/packages/next/src/client/components/error-boundary.tsx#L145 | ||
export function DefaultGlobalErrorPage(props: ErrorPageProps) { | ||
const message = props.serverError | ||
? `Unknown Server Error (see server logs for the details)` | ||
: `Unknown Client Error (see browser console for the details)`; | ||
return ( | ||
<html> | ||
<title>{message}</title> | ||
<body | ||
style={{ | ||
fontFamily: | ||
'system-ui,"Segoe UI",Roboto,Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji"', | ||
height: "100vh", | ||
display: "flex", | ||
flexDirection: "column", | ||
placeContent: "center", | ||
placeItems: "center", | ||
fontSize: "14px", | ||
fontWeight: 400, | ||
lineHeight: "28px", | ||
}} | ||
> | ||
<h2>{message}</h2> | ||
</body> | ||
</html> | ||
); | ||
} |
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