Skip to content

Commit 9d84730

Browse files
fix(docs): load MDX bodies on demand so the Worker fits Cloudflare's 64 MiB limit
`Deploy Docs` has been rejected by the Cloudflare API on every run since #106 (2026-08-25T21:05Z) with `code: 10027` — the Worker exceeds the 64 MiB uncompressed limit. Version creation fails, so no new Worker version exists and the previously accepted one keeps being served: nothing 500s, the site just stops changing. The bytes were not the corpus. All 397 `.mdx` files are 2.50 MiB of source; `handler.mjs` measured 100.93 MiB locally on 94a4126. The multiplier was the bundling. `fumadocs-mdx:collections/server` imports every page eagerly, so each server entrypoint that touches `source` — the docs page, and also `/llms.txt`, `/llms-full.txt`, `/llms.mdx/*`, `/og/*`, `/api/search` and `/sitemap.xml` — pulled the whole corpus into its own chunk, and the bundler inlined the set five times over. Measured on one probe sentence that occurs once, in one English page: 15 copies in `handler.mjs` before, 6 after. `async: true` on the docs collection makes each page's compiled body a dynamic import, so Turbopack emits per-page chunks (27 chunk files before, 971 after) instead of one corpus-sized chunk per entrypoint. handler.mjs 100.93 MiB -> 48.47 MiB (-52.0%) The only consumer this changes is the docs page, which now awaits `page.data.load()` for `body` and `toc`. Frontmatter stays eager, so `title`, `description`, `seoTitle` and `full` are untouched, and `getText('processed')` — what the llms.txt routes call — remains a method on the entry, so the generated `llms` bodies are byte-identical. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GkauAsZBEemRbco2rEX9Lx
1 parent 94a4126 commit 9d84730

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

‎apps/docs/app/[lang]/docs/[[...slug]]/page.tsx‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,11 @@ export default async function Page(props: {
240240
const page = source.getPage(params.slug ?? [], params.lang);
241241
if (!page) notFound();
242242

243-
const MDX = page.data.body;
243+
// `async: true` on the docs collection makes the compiled body and toc
244+
// load on demand instead of being statically imported, so they are awaited
245+
// here. Frontmatter (`title`, `description`, `full`) stays eager.
246+
const loaded = await page.data.load();
247+
const MDX = loaded.body;
244248

245249
// Resolved once and handed to both controls, so they cannot drift apart and
246250
// so a third control added below inherits the locale-independent URL instead
@@ -283,7 +287,7 @@ export default async function Page(props: {
283287
dangerouslySetInnerHTML={{ __html: jsonLdHtml(item) }}
284288
/>
285289
))}
286-
<DocsPage toc={page.data.toc} full={page.data.full}>
290+
<DocsPage toc={loaded.toc} full={page.data.full}>
287291
<DocsTitle>{page.data.title}</DocsTitle>
288292
<DocsDescription className="mb-0">{page.data.description}</DocsDescription>
289293
<div className="flex flex-row gap-2 items-center border-b pb-6">

‎apps/docs/source.config.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,29 @@ import path from 'node:path';
55
export const docs = defineDocs({
66
dir: path.resolve(process.cwd(), '../../content/docs'),
77
docs: {
8+
/**
9+
* Load each page's compiled body on demand instead of statically importing
10+
* all of them into every server entrypoint.
11+
*
12+
* Without this, `fumadocs-mdx:collections/server` eagerly imports all 397
13+
* `.mdx` files, so every route that touches `source` — the docs page, but
14+
* also `/llms.txt`, `/llms-full.txt`, `/llms.mdx/*`, `/og/*`, `/api/search`
15+
* and `/sitemap.xml` — pulls the entire corpus into its own chunk. The
16+
* bundler then inlined the whole set five times over into one worker:
17+
* 2.50 MiB of authored MDX became a 100.93 MiB `handler.mjs`, and
18+
* Cloudflare rejects any Worker over 64 MiB uncompressed (`code: 10027`).
19+
*
20+
* The multiplier, not the corpus, was the problem: measured on the same
21+
* tree, one probe sentence from a single English page appeared 15 times in
22+
* the bundle before this flag and 6 times after, taking `handler.mjs` from
23+
* 100.93 MiB to 48.47 MiB.
24+
*
25+
* The cost is that `page.data.body` and `page.data.toc` become
26+
* `page.data.load()`. Frontmatter stays eager, so `title`, `description`,
27+
* `seoTitle` and `full` are unaffected, and `getText('processed')` — what
28+
* the llms.txt routes call — is still a method on the entry.
29+
*/
30+
async: true,
831
schema: pageSchema.extend({
932
/**
1033
* Optional SEO title: what the `<title>` tag should say, when that is not

0 commit comments

Comments
 (0)