1
0
mirror of https://github.com/alexandrev/xslt-lab.git synced 2026-09-13 08:43:16 +00:00
Files
claude-code 9c6f81a043 Perf: hand-rolled CodeMirror to slim the critical editor chunk (-29KB gz)
@uiw/react-codemirror's basicSetup statically imports @codemirror/lint,
/autocomplete and /search, so they landed in the critical codemirror
chunk regardless of the runtime basicSetup flags. Since lint and
autocomplete are already loaded on demand via useEditorExtras, they were
being shipped twice — once eager, once deferred.

Replace the @uiw wrapper with a thin EditorView binding (controlled
value with an ExternalChange annotation to avoid onChange echo, plus
compartments for theme / base options / deferred extras) and hand-pick
only the primitives the critical path needs: state, view (lineNumbers,
highlightActiveLine, drawSelection, keymap), commands (history), and
language (syntaxHighlighting, indentOnInput, bracketMatching). lint,
autocomplete and the completions table stay in useEditorExtras.

Critical codemirror chunk 448KB/147KB gz -> 361KB/118KB gz. The
autocomplete + lint code moves to deferred chunks, off first paint.

Behaviour verified in a headless browser: typing/onChange, undo/redo,
auto-close tags, deferred autocomplete (65 options), XML lint markers,
and light/dark theme switch (oneDark applied) all work; no page errors.

LCP/FCP/CLS unchanged (already gated by the static skeleton since the
prior commit). Time-to-interactive-editor on throttled mobile improves
from 2111ms to 1821ms median, with far tighter run-to-run variance.

Drops the @uiw/react-codemirror dependency; promotes the four
@codemirror/* primitives to direct dependencies. @monaco-editor/react
stays (only referenced by a test mock).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JDk5guu51FjFxQMjgrrekW
2026-07-21 15:49:37 +00:00

46 lines
1.0 KiB
JavaScript

import { readFileSync } from "fs";
import { execSync } from "child_process";
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
const pkg = JSON.parse(
readFileSync(new URL("./package.json", import.meta.url), "utf-8"),
);
let gitCommit = "";
try {
gitCommit = execSync("git rev-parse --short HEAD").toString().trim();
} catch {}
export default defineConfig({
plugins: [react()],
server: {
port: 3000,
},
define: {
__APP_VERSION__: JSON.stringify(pkg.version),
__GIT_COMMIT__: JSON.stringify(gitCommit),
},
build: {
rollupOptions: {
output: {
manualChunks: {
react: ["react", "react-dom"],
codemirror: [
"@codemirror/state",
"@codemirror/view",
"@codemirror/commands",
"@codemirror/language",
"@codemirror/lang-xml",
"@codemirror/theme-one-dark",
],
},
},
},
},
test: {
environment: "jsdom",
setupFiles: "./src/setupTests.js",
},
});