Skip to content

Commit a35d760

Browse files
committed
fix: prerender bailout
1 parent 7f467ed commit a35d760

File tree

4 files changed

+36
-47
lines changed

4 files changed

+36
-47
lines changed

apps/website/src/app/docs/packages/[packageName]/[version]/[item]/page.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Metadata } from 'next';
2+
import { notFound } from 'next/navigation';
23
import { DocItem } from '~/components/DocItem';
34
import { fetchNode } from '~/util/fetchNode';
45

@@ -25,6 +26,10 @@ export default async function Page({
2526
}) {
2627
const node = await fetchNode({ item: params.item, packageName: params.packageName, version: params.version });
2728

29+
if (!node) {
30+
notFound();
31+
}
32+
2833
return (
2934
<main className="flex w-full flex-col gap-8 pb-12 md:pb-0">
3035
<DocItem node={node} packageName={params.packageName} version={params.version} />

apps/website/src/components/Navigation.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { VscGithubInverted } from '@react-icons/all-files/vsc/VscGithubInverted'
22
import { ChevronDown, ChevronUp } from 'lucide-react';
33
import dynamic from 'next/dynamic';
44
import Link from 'next/link';
5+
import { notFound } from 'next/navigation';
56
import { fetchSitemap } from '~/util/fetchSitemap';
67
import { fetchVersions } from '~/util/fetchVersions';
78
import { resolveNodeKind } from './DocKind';
@@ -28,6 +29,11 @@ export async function Navigation({
2829
readonly version: string;
2930
}) {
3031
const node = await fetchSitemap({ packageName, version });
32+
33+
if (!node) {
34+
notFound();
35+
}
36+
3137
const versions = await fetchVersions(packageName);
3238

3339
const groupedNodes = node.reduce((acc: any, node: any) => {

apps/website/src/util/fetchNode.ts

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { readFile } from 'node:fs/promises';
22
import { join } from 'node:path';
3-
import { notFound } from 'next/navigation';
43
import { ENV } from './env';
54

65
export async function fetchNode({
@@ -15,32 +14,22 @@ export async function fetchNode({
1514
const normalizeItem = item.split(encodeURIComponent(':')).join('.').toLowerCase();
1615

1716
if (ENV.IS_LOCAL_DEV) {
18-
try {
19-
const fileContent = await readFile(
20-
join(
21-
process.cwd(),
22-
`../../packages/${packageName}/docs/${packageName}/split/${version}.${normalizeItem}.api.json`,
23-
),
24-
'utf8',
25-
);
17+
const fileContent = await readFile(
18+
join(
19+
process.cwd(),
20+
`../../packages/${packageName}/docs/${packageName}/split/${version}.${normalizeItem}.api.json`,
21+
),
22+
'utf8',
23+
);
2624

27-
return JSON.parse(fileContent);
28-
} catch (error_) {
29-
console.error(error_);
30-
notFound();
31-
}
25+
return JSON.parse(fileContent);
3226
}
3327

34-
try {
35-
const isMainVersion = version === 'main';
36-
const fileContent = await fetch(
37-
`${process.env.BLOB_STORAGE_URL}/rewrite/${packageName}/${version}.${normalizeItem}.api.json`,
38-
{ next: isMainVersion ? { revalidate: 0 } : { revalidate: 604_800 } },
39-
);
28+
const isMainVersion = version === 'main';
29+
const fileContent = await fetch(
30+
`${process.env.BLOB_STORAGE_URL}/rewrite/${packageName}/${version}.${normalizeItem}.api.json`,
31+
{ next: isMainVersion ? { revalidate: 0 } : { revalidate: 604_800 } },
32+
);
4033

41-
return await fileContent.json();
42-
} catch (error_) {
43-
console.error(error_);
44-
notFound();
45-
}
34+
return fileContent.json();
4635
}

apps/website/src/util/fetchSitemap.ts

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { readFile } from 'node:fs/promises';
22
import { join } from 'node:path';
3-
import { notFound } from 'next/navigation';
43
import { ENV } from './env';
54

65
export async function fetchSitemap({
@@ -11,29 +10,19 @@ export async function fetchSitemap({
1110
readonly version: string;
1211
}) {
1312
if (ENV.IS_LOCAL_DEV) {
14-
try {
15-
const fileContent = await readFile(
16-
join(process.cwd(), `../../packages/${packageName}/docs/${packageName}/split/${version}.sitemap.api.json`),
17-
'utf8',
18-
);
13+
const fileContent = await readFile(
14+
join(process.cwd(), `../../packages/${packageName}/docs/${packageName}/split/${version}.sitemap.api.json`),
15+
'utf8',
16+
);
1917

20-
return JSON.parse(fileContent);
21-
} catch (error_) {
22-
console.error(error_);
23-
notFound();
24-
}
18+
return JSON.parse(fileContent);
2519
}
2620

27-
try {
28-
const isMainVersion = version === 'main';
29-
const fileContent = await fetch(
30-
`${process.env.BLOB_STORAGE_URL}/rewrite/${packageName}/${version}.sitemap.api.json`,
31-
{ next: isMainVersion ? { revalidate: 0 } : { revalidate: 604_800 } },
32-
);
21+
const isMainVersion = version === 'main';
22+
const fileContent = await fetch(
23+
`${process.env.BLOB_STORAGE_URL}/rewrite/${packageName}/${version}.sitemap.api.json`,
24+
{ next: isMainVersion ? { revalidate: 0 } : { revalidate: 604_800 } },
25+
);
3326

34-
return await fileContent.json();
35-
} catch (error_) {
36-
console.error(error_);
37-
notFound();
38-
}
27+
return fileContent.json();
3928
}

0 commit comments

Comments
 (0)