Skip to content

Commit 79fd669

Browse files
ra3orbladeclaude
andcommitted
fix: actually emit lazy Prism language chunks via import.meta.glob
The previous attempt removed /* @vite-ignore */ expecting Rollup to glob the bare-specifier template `prismjs/components/prism-${lang}.js` and emit one chunk per language. Rollup only globs template-literal dynamic imports with a relative prefix (./ or ../), so the import was left unresolved in production — `Prism.languages.<lang>` stayed undefined for every language not statically pulled in by @lexical/code (bash, splunk-spl, ruby, go, yaml, …) and code blocks rendered without highlighting. Switched to import.meta.glob, Vite's officially supported mechanism for variable-keyed dynamic imports. Rollup now emits one lazy chunk per language (verified: dist/js/chunks/prism-splunk-spl.js etc., bundled call site rewrites to import("./chunks/prism-X.js") via __vitePreload). Excluded *.min.js siblings to avoid emitting unused duplicates. Reported on community for splunk-spl after 0.55.1 patch: https://community.anytype.io/t/bash-code-snipped-highlight-broke/30673 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 9d9ae7f commit 79fd669

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

src/ts/component/block/text.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,21 @@ import { focus } from 'Lib/focus';
1010
// Prism language plugins expect `Prism` on the global scope
1111
(window as any).Prism = Prism;
1212

13-
// Do not mark this import /* @vite-ignore */ — Rollup needs to glob
14-
// prismjs/components/prism-*.js and emit a lazy chunk per language, otherwise
15-
// nothing loads in production and Prism.languages.<lang> stays undefined.
13+
// Use import.meta.glob so Rollup emits one lazy chunk per language. A plain
14+
// dynamic import with a template literal works only for relative paths —
15+
// bare-specifier templates like `prismjs/components/prism-${lang}.js` are
16+
// left unresolved in production and Prism.languages.<lang> stays undefined.
17+
const prismLangModules = import.meta.glob([
18+
'/node_modules/prismjs/components/prism-*.js',
19+
'!/node_modules/prismjs/components/prism-*.min.js',
20+
]);
21+
1622
(async () => {
1723
for (const lang of U.Prism.components) {
18-
try { await import(`prismjs/components/prism-${lang}.js`); } catch (e) {};
24+
const loader = prismLangModules[`/node_modules/prismjs/components/prism-${lang}.js`];
25+
if (loader) {
26+
try { await loader(); } catch (e) {};
27+
};
1928
};
2029
})();
2130

0 commit comments

Comments
 (0)