Files
oh-my-opencode/web/app/[locale]/docs/page.tsx
T
YeonGyu-Kim 57b9d42537 fix(web): bundle docs sources at build time so the worker has no fs
The worker deploy from #3859 returned HTTP 500 on /docs with
`Error: [unenv] fs.readFile is not implemented yet!` (captured via
`wrangler tail`). `loadDocSource` was calling `node:fs/promises`
`readFile` inside an RSC; even though the page is generated as SSG
(`●`), Cloudflare Workers' unenv shim does not implement filesystem
reads, so any code path that reaches the worker (cache miss, prerender
fallback) fails.

Move the read to a prebuild step that emits a TypeScript module:

- `web/scripts/generate-docs-content.mjs` reads each section's source
  from `<repo-root>/docs/` and writes
  `web/lib/docs-content.generated.ts` containing
  `export const DOC_SOURCES: Record<string, string>`.
- `web/scripts/prepare-build.mjs` invokes the generator after the
  cache prune, so every `bun run build` and `bunx opennextjs-cloudflare
  build` regenerates the constant module from the live `docs/`.
- `web/lib/docs-source.ts` now reads `DOC_SOURCES[file]` synchronously
  with no Node I/O.
- `web/app/[locale]/docs/page.tsx` drops the `Promise.all` since reads
  are synchronous.
- `web/.gitignore` excludes the generated file (kept generated, not
  source-of-truth).

Effect: the bundle ships every doc as a string literal. The worker has
no `fs.readFile` call to fail. `docs/` remains the only place an
editor needs to touch.
2026-05-08 16:38:14 +09:00

30 lines
976 B
TypeScript

import { getTranslations } from "next-intl/server"
import { MDXRemote } from "next-mdx-remote/rsc"
import { DocsShell } from "@/components/docs/docs-shell"
import { mdxComponents } from "@/components/docs/mdx-components"
import { DOC_SECTIONS } from "@/lib/docs-sections"
import { loadDocSource } from "@/lib/docs-source"
export default async function DocsPage() {
const t = await getTranslations("docs")
const sectionsWithSource = DOC_SECTIONS.map((section) => ({
...section,
source: loadDocSource(section.file),
}))
return (
<DocsShell
mobileHeader={t("mobileHeader")}
searchPlaceholder={t("searchPlaceholder")}
sections={DOC_SECTIONS.map((s) => ({ id: s.id, title: s.title }))}
>
{sectionsWithSource.map((section) => (
<section key={section.id} id={section.id} className="scroll-mt-24">
<MDXRemote source={section.source} components={mdxComponents} />
</section>
))}
</DocsShell>
)
}