fix(docs): pre-bundle mermaid deps so the dev server resolves dayjs/cytoscape #157
Reference in New Issue
Block a user
Delete Branch "fix/docs-site-mermaid-dayjs-esm"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
pnpm docs:devrendered a blank page with this thrown by the browser on the first navigation:Root cause: Mermaid 11 (transitive dep of
vitepress-plugin-mermaidshipped in #154) pulls indayjs,cytoscape,debug,@braintree/sanitize-url— each ships a CommonJSmainfield with nodefaultESM export. Vite's dev server resolves these modules eagerly as ESM and the browser blows up before the home page renders.The production build was unaffected — Rollup's plugin pipeline already wraps CJS deps for ESM consumers.
docs:buildshipped clean HTML in #154 and the CI Mermaid-fence (grep class="mermaid"in ADR-0009's HTML) passed precisely because it inspects the prod bundle, not the dev-server output.What lands
docs/.vitepress/config.mts— adds a singlevite.optimizeDeps.includeblock:optimizeDeps.includetells Vite to pre-bundle those modules through esbuild at dev-server boot, applying the same CJS→ESM interop wrapper Rollup uses in prod. The dev server now serves a workinglocalhost:5173and Mermaid diagrams render.Notes for the reviewer
'mermaid'alone is sometimes enough because Vite walks the dep tree, but the plugin's own README + a handful of upstream issue threads recommend listing the leaf CJS modules explicitly so the optimizer doesn't miss them on a cold cache. Cheap, defensive.Assert Mermaid rendersstep in.gitea/workflows/docs-site.ymlgrepsdocs/.vitepress/dist/— the production-build output. The bug only manifests on the dev server's runtime-pre-bundling path. Catching it in CI would require bootingdocs:devheadlessly and curling the page; not worth the workflow weight for a once-per-major-upgrade class of issue. Manualpnpm docs:devsmoke is the right gate for now.mainpoints at the UMD/CJS bundle); fixing it upstream would be a breaking change for non-bundler consumers. Mermaid upstream is aware; their fix has historically been "tell your bundler to pre-bundle us", which is exactly whatoptimizeDeps.includedoes.Test plan
rm -rf docs/.vitepress/cache && pnpm docs:dev— server boots,curl http://localhost:5173/returns 200.rm -rf docs/.vitepress/{cache,dist} && pnpm docs:build— clean prod build in ~10 s, Mermaid SVG still present in ADR-0009's HTML (regression fence passes).localhost:5173→ home →/decisions/0009-…→ confirm the OIDC sequence diagram renders inline, no console errors. Toggle dark mode, confirm diagrams flip theme.