fix: prerender bailout

This commit is contained in:
iCrawl 2024-05-24 02:10:07 +02:00
parent 7f467ed2d1
commit a35d760421
No known key found for this signature in database
4 changed files with 38 additions and 49 deletions

View file

@ -1,4 +1,5 @@
import type { Metadata } from 'next';
import { notFound } from 'next/navigation';
import { DocItem } from '~/components/DocItem';
import { fetchNode } from '~/util/fetchNode';
@ -25,6 +26,10 @@ export default async function Page({
}) {
const node = await fetchNode({ item: params.item, packageName: params.packageName, version: params.version });
if (!node) {
notFound();
}
return (
<main className="flex w-full flex-col gap-8 pb-12 md:pb-0">
<DocItem node={node} packageName={params.packageName} version={params.version} />

View file

@ -2,6 +2,7 @@ import { VscGithubInverted } from '@react-icons/all-files/vsc/VscGithubInverted'
import { ChevronDown, ChevronUp } from 'lucide-react';
import dynamic from 'next/dynamic';
import Link from 'next/link';
import { notFound } from 'next/navigation';
import { fetchSitemap } from '~/util/fetchSitemap';
import { fetchVersions } from '~/util/fetchVersions';
import { resolveNodeKind } from './DocKind';
@ -28,6 +29,11 @@ export async function Navigation({
readonly version: string;
}) {
const node = await fetchSitemap({ packageName, version });
if (!node) {
notFound();
}
const versions = await fetchVersions(packageName);
const groupedNodes = node.reduce((acc: any, node: any) => {

View file

@ -1,6 +1,5 @@
import { readFile } from 'node:fs/promises';
import { join } from 'node:path';
import { notFound } from 'next/navigation';
import { ENV } from './env';
export async function fetchNode({
@ -15,32 +14,22 @@ export async function fetchNode({
const normalizeItem = item.split(encodeURIComponent(':')).join('.').toLowerCase();
if (ENV.IS_LOCAL_DEV) {
try {
const fileContent = await readFile(
join(
process.cwd(),
`../../packages/${packageName}/docs/${packageName}/split/${version}.${normalizeItem}.api.json`,
),
'utf8',
);
return JSON.parse(fileContent);
} catch (error_) {
console.error(error_);
notFound();
}
}
try {
const isMainVersion = version === 'main';
const fileContent = await fetch(
`${process.env.BLOB_STORAGE_URL}/rewrite/${packageName}/${version}.${normalizeItem}.api.json`,
{ next: isMainVersion ? { revalidate: 0 } : { revalidate: 604_800 } },
const fileContent = await readFile(
join(
process.cwd(),
`../../packages/${packageName}/docs/${packageName}/split/${version}.${normalizeItem}.api.json`,
),
'utf8',
);
return await fileContent.json();
} catch (error_) {
console.error(error_);
notFound();
return JSON.parse(fileContent);
}
const isMainVersion = version === 'main';
const fileContent = await fetch(
`${process.env.BLOB_STORAGE_URL}/rewrite/${packageName}/${version}.${normalizeItem}.api.json`,
{ next: isMainVersion ? { revalidate: 0 } : { revalidate: 604_800 } },
);
return fileContent.json();
}

View file

@ -1,6 +1,5 @@
import { readFile } from 'node:fs/promises';
import { join } from 'node:path';
import { notFound } from 'next/navigation';
import { ENV } from './env';
export async function fetchSitemap({
@ -11,29 +10,19 @@ export async function fetchSitemap({
readonly version: string;
}) {
if (ENV.IS_LOCAL_DEV) {
try {
const fileContent = await readFile(
join(process.cwd(), `../../packages/${packageName}/docs/${packageName}/split/${version}.sitemap.api.json`),
'utf8',
);
return JSON.parse(fileContent);
} catch (error_) {
console.error(error_);
notFound();
}
}
try {
const isMainVersion = version === 'main';
const fileContent = await fetch(
`${process.env.BLOB_STORAGE_URL}/rewrite/${packageName}/${version}.sitemap.api.json`,
{ next: isMainVersion ? { revalidate: 0 } : { revalidate: 604_800 } },
const fileContent = await readFile(
join(process.cwd(), `../../packages/${packageName}/docs/${packageName}/split/${version}.sitemap.api.json`),
'utf8',
);
return await fileContent.json();
} catch (error_) {
console.error(error_);
notFound();
return JSON.parse(fileContent);
}
const isMainVersion = version === 'main';
const fileContent = await fetch(
`${process.env.BLOB_STORAGE_URL}/rewrite/${packageName}/${version}.sitemap.api.json`,
{ next: isMainVersion ? { revalidate: 0 } : { revalidate: 604_800 } },
);
return fileContent.json();
}