Skip to content

Commit 1022a87

Browse files
ystemsrxclaude
andcommitted
fix(landing): render hero ER graph on GitHub Pages
Two coupled production-only failures kept the inline module on index.html from ever building the hero graph: 1. prismjs/components/prism-sql references the global Prism at module top level, which is undefined under ESM. The manualChunks rule also bundled core and the language file into a single vendor-prism chunk, so even a dynamic import would still trigger prism-sql synchronously when the chunk evaluated. Import Prism as a value, assign window.Prism, then dynamic-import prism-sql; split prismjs/components/* out of vendor-prism so the language chunk only evaluates after the global is set. 2. Using top-level await for that dynamic import turned the inline module into an asynchronous evaluation, letting window.load fire before addEventListener("load", buildHeroGraph) ran. The handler was never invoked and the canvas stayed blank with no console error. Use fire-and-forget dynamic import so the module finishes evaluating synchronously; syntax highlighting can fail silently without taking the hero down with it. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 981feb2 commit 1022a87

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

index.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,14 +1954,21 @@ <h2 class="cta-title" data-i18n-html="cta_title">
19541954
</div>
19551955
<script type="module">
19561956
import "prismjs/themes/prism.css";
1957-
import "prismjs";
1958-
import "prismjs/components/prism-sql";
1957+
import Prism from "prismjs";
19591958
import G6 from "@antv/g6";
19601959
import { parseSQLTables } from "./src/parser/sql";
19611960
import { parseDBML } from "./src/parser/dbml";
19621961
import * as ERBuilder from "./src/builder";
19631962
import * as Layout from "./src/layout";
19641963

1964+
// prism-sql 在模块顶层引用全局 Prism;ESM 下 prismjs 不会自挂 window,
1965+
// 必须先把核心赋到全局,再动态 import 让语言定义晚于赋值执行。
1966+
// 不要用 top-level await:那会把整个模块变成异步求值,导致下方
1967+
// window.addEventListener("load", ...) 在 load 事件之后才注册,
1968+
// Hero ER 图永远不会被构建。代码高亮失败也不应阻塞主流程。
1969+
window.Prism = Prism;
1970+
import("prismjs/components/prism-sql").catch(() => {});
1971+
19651972
// ───── YEAR ─────
19661973
document.getElementById("year").textContent = new Date().getFullYear();
19671974

vite.config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ export default defineConfig({
4141
) {
4242
return "vendor-editor";
4343
}
44-
if (id.includes("node_modules/prismjs")) {
44+
// prismjs/components/* 在模块顶层访问全局 Prism,必须落在独立 chunk
45+
// 里,等运行时显式 window.Prism = Prism 后再动态加载,否则会和 core 一起
46+
// 被同步求值并抛 ReferenceError。
47+
if (
48+
id.includes("node_modules/prismjs") &&
49+
!id.includes("node_modules/prismjs/components/")
50+
) {
4551
return "vendor-prism";
4652
}
4753
},

0 commit comments

Comments
 (0)