Skip to content

Commit 1933e62

Browse files
Merge pull request #263 from objectstack-ai/claude/issue-261-docs-deploy-worker-size
fix(docs): load MDX bodies on demand so the Worker fits Cloudflare's 64 MiB limit
2 parents 896efd1 + 9d84730 commit 1933e62

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)