@@ -31,11 +31,13 @@ export default defineConfig({
3131 return "vendor-plotly"
3232 }
3333
34- // Mermaid and its rendering graph (d3, dagre, khroma, cytoscape,
35- // elkjs) must stay in ONE chunk. Splitting this tightly-coupled,
36- // circular dependency graph across chunks reorders module init and
37- // triggers a "Cannot access 'x' before initialization" TDZ error in
38- // mermaid's theme code on load.
34+ // Let mermaid and its rendering graph (d3, dagre, khroma, cytoscape,
35+ // elkjs, lodash-es) auto-chunk. Mermaid lazy-loads each diagram type
36+ // via internal dynamic import(); forcing the graph into one manual
37+ // chunk collapses those async boundaries into synchronous circular
38+ // references, which throw "Cannot access 'x' before initialization"
39+ // TDZ errors during theme setup and rendering. Returning undefined
40+ // lets Rollup preserve mermaid's internal async chunk boundaries.
3941 if (
4042 id . includes ( "mermaid" ) ||
4143 id . includes ( "/d3-" ) ||
@@ -44,17 +46,24 @@ export default defineConfig({
4446 id . includes ( "khroma" ) ||
4547 id . includes ( "cytoscape" ) ||
4648 id . includes ( "elkjs" ) ||
47- id . includes ( "non-layered-tidy-tree-layout" )
49+ id . includes ( "non-layered-tidy-tree-layout" ) ||
50+ id . includes ( "lodash-es" )
4851 ) {
49- return "vendor-mermaid"
52+ return undefined
5053 }
5154
55+ // react-ipynb-renderer, mathjax and katex form an interdependent
56+ // graph that also cross-imports the markdown/syntax chunks (and katex
57+ // is pulled in by mermaid). Force-merging them into one chunk creates
58+ // circular chunk dependencies whose const/class bindings evaluate out
59+ // of order, throwing "Cannot access 'x' before initialization" TDZ
60+ // errors on load. Let Rollup auto-chunk this graph instead.
5261 if (
5362 id . includes ( "react-ipynb-renderer" ) ||
5463 id . includes ( "mathjax" ) ||
5564 id . includes ( "katex" )
5665 ) {
57- return "vendor-notebooks"
66+ return undefined
5867 }
5968
6069 if (
0 commit comments