-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Expand file tree
/
Copy pathpage.tsx
More file actions
55 lines (47 loc) · 1.52 KB
/
page.tsx
File metadata and controls
55 lines (47 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import {unstable_cache} from 'next/cache';
import {notFound} from 'next/navigation';
import ErrorDecoderPage from '../components/error-decoder-page';
import type {Metadata, ResolvingMetadata} from 'next';
interface ErrorDecoderPageProps {
params: Promise<{errorCode: string}>;
}
export default async function ErrorPage({params}: ErrorDecoderPageProps) {
const {errorCode} = await params;
const errorCodes = await fetchReactErrorCodes();
if (errorCode && !(errorCode in errorCodes)) {
notFound();
}
return <ErrorDecoderPage errorCode={errorCode} errorCodes={errorCodes} />;
}
const fetchReactErrorCodes = unstable_cache(async () => {
return (
await fetch(
'https://raw.githubusercontent.com/facebook/react/main/scripts/error-codes/codes.json'
)
).json() as Promise<{[key: string]: string}>;
}, ['react-error-codes']);
export async function generateStaticParams(): Promise<
Array<{errorCode: string}>
> {
return Object.keys(await fetchReactErrorCodes()).map((code) => ({
errorCode: code,
}));
}
export async function generateMetadata(
{params}: ErrorDecoderPageProps,
parent: Promise<ResolvingMetadata | undefined>
): Promise<Metadata> {
const {errorCode} = await params;
const resolvedParent = await parent;
const parentOpenGraph = resolvedParent ? resolvedParent.openGraph : {};
return {
title: `Minified React error #${errorCode}`,
alternates: {
canonical: `./`,
},
openGraph: {
...parentOpenGraph,
title: `Minified React error #${errorCode}`,
},
};
}