mirror of
https://github.com/davidkaya/aryx.git
synced 2026-08-08 04:38:45 +02:00
fix: move Prism global setup to entry-point module
The previous approach imported prismjs component files directly in MarkdownComposer.tsx. In Vite dev mode, each component is served as a separate ESM module whose IIFE references a bare 'Prism' global that doesn't exist yet, crashing the app. Fix: create a dedicated prismSetup module that imports prismjs and assigns globalThis.Prism, then import it from the renderer entry point (main.tsx) before any component that loads @lexical/code-prism. ESM evaluation order guarantees the global is set before the tokenizer captures its reference. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -21,29 +21,6 @@ import {
|
||||
$convertToMarkdownString,
|
||||
} from '@lexical/markdown';
|
||||
import { $isCodeNode, $createCodeNode, CodeNode } from '@lexical/code';
|
||||
|
||||
// Prism must be on `globalThis` before @lexical/code-prism initializes its
|
||||
// tokenizer reference. Vite's dev-mode esbuild CJS shim can race the global
|
||||
// assignment, so we force it here before importing the module.
|
||||
import Prism from 'prismjs';
|
||||
import 'prismjs/components/prism-clike';
|
||||
import 'prismjs/components/prism-javascript';
|
||||
import 'prismjs/components/prism-markup';
|
||||
import 'prismjs/components/prism-markdown';
|
||||
import 'prismjs/components/prism-c';
|
||||
import 'prismjs/components/prism-css';
|
||||
import 'prismjs/components/prism-objectivec';
|
||||
import 'prismjs/components/prism-sql';
|
||||
import 'prismjs/components/prism-python';
|
||||
import 'prismjs/components/prism-rust';
|
||||
import 'prismjs/components/prism-swift';
|
||||
import 'prismjs/components/prism-typescript';
|
||||
import 'prismjs/components/prism-java';
|
||||
import 'prismjs/components/prism-cpp';
|
||||
if (typeof globalThis !== 'undefined') {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(globalThis as any).Prism = Prism;
|
||||
}
|
||||
import { registerCodeHighlighting } from '@lexical/code-prism';
|
||||
import {
|
||||
$isListNode,
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Ensures the PrismJS global is available before @lexical/code-prism
|
||||
* captures its tokenizer reference.
|
||||
*
|
||||
* @lexical/code-prism reads `globalThis.Prism` at module-evaluation time.
|
||||
* In Vite dev mode the esbuild CJS shim may not have set the global yet,
|
||||
* so we force it here. This module must be imported before any module
|
||||
* that transitively loads @lexical/code-prism.
|
||||
*/
|
||||
import Prism from 'prismjs';
|
||||
|
||||
if (typeof globalThis !== 'undefined' && !globalThis.Prism) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(globalThis as any).Prism = Prism;
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { StrictMode } from 'react';
|
||||
import { createRoot } from 'react-dom/client';
|
||||
|
||||
import '@renderer/lib/prismSetup';
|
||||
import App from '@renderer/App';
|
||||
import '@renderer/styles.css';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user