-
Notifications
You must be signed in to change notification settings - Fork 15
Description
Problem
In src/components/Editor/Editor.tsx (line 24), SourceEditor is imported eagerly:
import { SourceEditor } from "./SourceEditor";SourceEditor.tsx in turn eagerly imports the full CodeMirror dependency tree:
@codemirror/state@codemirror/view@codemirror/commands@codemirror/lang-markdown@codemirror/language-data@codemirror/autocomplete@codemirror/search- Plus
sourceEditorExtensions.tswhich pulls in more modules
This means the entire CodeMirror bundle (~200–400KB) is loaded on every app start, even when the user stays in WYSIWYG mode (the default).
Context
The project already correctly lazy-loads other large dependencies:
- Mermaid:
import("mermaid")insrc/plugins/mermaid/index.ts:48 - KaTeX:
import("katex")insrc/plugins/latex/katexLoader.ts:13 - Markmap: lazy-loaded similarly
CodeMirror is the last major eagerly-loaded optional dependency.
Impact
Slower initial page load and higher initial memory usage for all users, regardless of whether they use source mode.
Suggested fix
Wrap SourceEditor in React.lazy():
const SourceEditor = lazy(() =>
import("./SourceEditor").then(m => ({ default: m.SourceEditor }))
);Then wrap the <SourceEditor> usage in a <Suspense> boundary. The keepAlive path would need the Suspense wrapper too, but CodeMirror would only load when source mode is first activated.
File: src/components/Editor/Editor.tsx:24