docs: improve references loading (#13761)

* docs: improve references loading

* remove comment

* try remove generate metadata

* improvements and fixes
This commit is contained in:
Shahed Nasser
2025-10-16 14:25:01 +03:00
committed by GitHub
parent 4eb9628514
commit e36c054780
11 changed files with 379 additions and 107 deletions
@@ -0,0 +1,33 @@
"use client"
import { MDXClientLazy, SerializeResult } from "next-mdx-remote-client/csr"
import MDXComponents from "../MDXComponents"
import { Loading, swrFetcher } from "docs-ui"
import useSWR from "swr"
import { config } from "../../config"
import { notFound } from "next/navigation"
type ReferenceMDXProps = {
slug: string[]
}
export const ReferenceMDX = ({ slug }: ReferenceMDXProps) => {
const {
data: serializedResult,
error,
isLoading,
} = useSWR<SerializeResult | { error: { name: string; message: string } }>(
`${config.basePath}/api/references/${slug.join("/")}`,
swrFetcher
)
if (isLoading || !serializedResult) {
return <Loading />
}
if ("error" in serializedResult || error) {
return notFound()
}
return <MDXClientLazy {...serializedResult} components={MDXComponents} />
}