Skip to content

feat(flame): page-specific assets, stable mdx chunks, and deploy alignment - #378

Merged
gitfromwildan merged 3 commits into
mainfrom
feat/page-specific-assets
Sep 10, 2026
Merged

gitfromwildan merged 3 commits into
mainfrom
feat/page-specific-assets

Conversation

@gitfromwildan

@gitfromwildan gitfromwildan commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

Summary

Page-specific assets + stable MDX chunk names + deploy/plugin alignment for @docubook/flame.

Split the single { js, css } client bundle into per-page-family bundles (docs / home / notFound), stabilize MDX chunk filenames across Bun and Vite, run plugin hooks for home + standalone 404, and align Docker/nginx deploy output with the new manifest contract.

Why

  • Single global client.css / client.js loaded docs-specific JS/CSS on home and 404, and vice versa.
  • Vite MDX chunk names diverged from Bun (docubook-mdx-page-*), breaking cross-runtime asset parity.
  • Plugin hooks (injectHead, injectBody, transformHtml, onEnd, handleRequest) only covered docs pages; home/404 bypassed plugins.
  • Deploy output (Dockerfile tag, nginx cache rules, 404 handling) was stale relative to the new asset layout.

What changed

1. Page-specific assets + stable MDX chunks (37f66fb)

  • AssetManifest in node/types.ts:
    {
      docs: { css: "docs-HASH.css", js: "client-HASH.js" },
      home: { css: "site-HASH.css", js: "home-client-HASH.js" },
      notFound: { css: "site-HASH.css" }
    }
  • Split client entrypoints: node/client.ts (docs) vs new node/home-client.ts (landing).
  • Split styles: styles/base.css (shared) + styles/site.css (home/404) vs docs bundle; Theme.tsx, pages/index.tsx, pages/404.tsx updated to use the right bundle.
  • Stable hash-based MDX virtual IDs for Bun (hydrate.node.ts / hydrate.ts) and Vite, keeping lazy per-route chunks without encoded-slash filenames.
  • Per-route manifest.json, cache-key.ts, paths.ts, html.shared.ts / html.ts updated for depth-aware asset URLs.
  • 404 standalone page no longer wrapped in DocsLayout.

2. Deploy alignment across runtimes (903eb48)

  • Normalize Vite MDX chunk names to Bun-compatible docubook-mdx-page-*.
  • deploy.shared.ts:
    • Dockerfile builder pinned to installed @docubook/flame version (FLAME_VERSION) instead of major-only tag, and builds with flame build --bun.
    • nginx.conf: error_page 404 /404.html, location = /404.html, try_files $uri $uri.html $uri/ =404.
    • Cache tiers: manifest.json + search-index.json → revalidate (no-cache); only content-hashed client-*, home-client-*, docs-*, site-*, chunks/*, assets/* → immutable.
    • Same tiers mirrored in _headers file for Cloudflare/Pages-style hosts.
  • deployment.mdx updated to match.

3. Plugins migrated to page-specific assets (6171ec4)

  • PageContext now requires:
    {
      pageType: "docs" | "home" | "notFound",
      assets: { css: string, js?: string },
      slug: string, // "" for home, "404" for notFound
      filePath: string,
      frontmatter: Record<string, unknown>,
      content?: string, // docs only
      config: DocuConfig
    }
  • injectHead / injectBody / transformHtml now run for docs, home, and standalone 404 in both build.ts and build.impl.ts (Node/Deno + Bun paths).
  • onEnd(config, pages, context) — new 3rd arg:
    { assetManifest: Readonly<AssetManifest>, outDir: string }
  • DevServerContext gains assetManifest, refreshed after HMR rebuilds; passed to dev handleRequest handlers.
  • Bun server (server.ts / server.impl.ts, server-routes.ts) simplified 404 fallback.
  • plugin.ts re-exports AssetEntry, AssetManifest, PageType; package.json publishes plugin types.
  • plugins.mdx rewritten: new PageContext table, onEnd example with { outDir, assetManifest }, warning not to parse manifest.json as single { js, css } and to treat js as optional.

Migration notes for plugin authors

  • Read ctx.assets / ctx.pageType instead of assuming a global bundle:
    build.injectBody((ctx) =>
      ctx.assets.js ? `<script>...</script>` : []
    );
  • onEnd:
    - build.onEnd(async (config, pages) => {
    -   const out = join(DIST_DIR, "sitemap.xml");
    + build.onEnd(async (config, pages, { outDir }) => {
    +   const out = join(outDir, "sitemap.xml");
  • manifest.json shape changed from { js, css } → { docs, home, notFound }. Look up by pageType.

Affected packages

  • @docubook/flame — runtime, build, dev server, deploy, plugin API, docs (deployment.mdx, plugins.mdx).

Validation

  • pnpm --filter @docubook/flame run test (updated: deploy.test.ts, hydrate.test.ts, html.test.ts, plugin.test.ts, plugin-integration.test.ts, security-pentest.test.ts, helpers.ts)
  • pnpm --filter @docubook/flame run lint
  • pnpm --filter @docubook/flame run compile:lib (Node/Deno path)
  • Manual: flame build (Bun + Node), flame dev home/docs/404 plugin hooks, flame deploy --docker Dockerfile/nginx output

CI (ci.yml, commitlint, docker-builder) will be the source of truth — checklist above to be ticked after local run.

Commits

  • 37f66fb — feat(flame): add page-specific assets and stable mdx chunk names
  • 903eb48 — fix(flame): align deploy assets across runtimes
  • 6171ec4 — feat(flame): migrate plugins to page-specific assets

Follow-up

  • Changeset missing for this user-facing @docubook/flame change — run pnpm changeset before merge (linked packages are in beta prerelease mode).
  • Base: main ← Head: feat/page-specific-assets. No linked issue.

- split docs/home client bundles with per-route styles and manifest

- map mdx slugs to stable hash-based virtual ids for bun and vite

- keep lazy per-route mdx chunks without encoded slash filenames
- normalize Vite MDX chunk names to Bun-compatible docubook-mdx-page-*
- pin Docker builder image to installed Flame version, build with --bun
- serve generated 404.html and revalidate stable manifest/search JSON
- cache only content-hashed JS, CSS, and chunk assets as immutable
Expose PageType and page assets through PageContext. Run plugin hooks for home and standalone 404 pages in build and dev, pass assetManifest to dev handlers, and deliver onEnd context with outDir. Simplify Bun server 404 fallback, align docs, and publish plugin types.
@pullfrog

pullfrog Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Pullfrog  | Review this ➔

@vercel

vercel Bot commented Sep 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docu Ignored Ignored Sep 10, 2026 6:24am UTC

@gitfromwildan
gitfromwildan merged commit 0aefadd into main Sep 10, 2026
13 checks passed
@gitfromwildan
gitfromwildan deleted the feat/page-specific-assets branch October 5, 2026 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant