From abff8372389e5452d8bddf97c0cede5057a06dae Mon Sep 17 00:00:00 2001 From: tianma-if Date: Sat, 5 Sep 2026 22:49:39 +0800 Subject: [PATCH] fix(web): keep diagram chunks out of startup caches --- apps/web/vite.config.ts | 1 + scripts/verify-web-performance.mjs | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/web/vite.config.ts b/apps/web/vite.config.ts index e47845ef..9a565865 100644 --- a/apps/web/vite.config.ts +++ b/apps/web/vite.config.ts @@ -192,6 +192,7 @@ export default defineConfig({ "**/*mermaid.core-*.js", "**/vendor-mermaid-*.js", "**/*Diagram-*.js", + "**/*DiagramEditorPane-*.js", "**/vendor-codemirror-*.js", // PDF.js is loaded only when a PDF preview or thumbnail is rendered. // Keep its runtime out of the install-time app-shell precache and cache diff --git a/scripts/verify-web-performance.mjs b/scripts/verify-web-performance.mjs index cd442f7f..e3df10ce 100644 --- a/scripts/verify-web-performance.mjs +++ b/scripts/verify-web-performance.mjs @@ -22,7 +22,7 @@ assert.ok(precacheStart >= 0 && precacheEnd > precacheStart, "Web service worker const precacheManifest = serviceWorker.slice(precacheStart, precacheEnd); assert.doesNotMatch(precacheManifest, /\{url:"index\.html",/, "Current HTML must not be served by a cache-first precache route"); assert.match(precacheManifest, /index\.html\?edgeever-offline-shell=/, "PWA must retain a versioned offline HTML shell"); -const optionalDiagramPattern = /(?:beautiful-mermaid|vendor-mermaid|mermaid\.core|vendor-codemirror|[^"']*Diagram-)[^"']*\.js/; +const optionalDiagramPattern = /(?:beautiful-mermaid|vendor-mermaid|mermaid\.core|vendor-codemirror|[^"']*Diagram(?:EditorPane)?-)[^"']*\.js/; assert.doesNotMatch(precacheManifest, optionalDiagramPattern, "Optional diagram chunks must remain out of the initial PWA precache"); assert.doesNotMatch(precacheManifest, /vendor~pdf-[^"']*\.js/, "Optional PDF.js runtime must remain out of the initial PWA precache"); assert.doesNotMatch(precacheManifest, /noto-sans-sc-[^"']*\.woff2/, "Print-only Noto Sans SC shards must remain out of the PWA precache"); @@ -37,14 +37,14 @@ const precacheBytes = precacheURLs const PRECACHE_BUDGET = 5 * 1024 * 1024; assert.ok(precacheBytes <= PRECACHE_BUDGET, `PWA precache budget exceeded: ${precacheBytes} > ${PRECACHE_BUDGET}`); const modulePreloads = indexHtml.match(/]+>/g)?.join("\n") ?? ""; -const initialOptionalPattern = /vendor-code-highlight|vendor-D3|beautiful-mermaid|vendor-(?:mermaid|tiptap|prosemirror|floating|codemirror)|ui-primitives|mermaid\.core|[^"']*Diagram-/; +const initialOptionalPattern = /vendor-code-highlight|vendor-D3|beautiful-mermaid|vendor-(?:mermaid|tiptap|prosemirror|floating|codemirror)|ui-primitives|mermaid\.core|[^"']*Diagram(?:EditorPane)?-/; assert.doesNotMatch(modulePreloads, initialOptionalPattern, "Optional editor and diagram chunks must remain out of the initial HTML modulepreload list"); assert.doesNotMatch(modulePreloads, /ui-button-tooltip/, "Button tooltips must load only when a titled button is rendered"); assert.doesNotMatch(modulePreloads, /vendor-radix(?!-slot)/, "Radix overlays must remain out of the initial HTML modulepreload list"); const initialModulePreloadBytes = [...indexHtml.matchAll(/]+href="([^"]+)"[^>]*>/g)] .map((match) => statSync(join(distDirectory, match[1].replace(/^\//, ""))).size) .reduce((total, size) => total + size, 0); -const INITIAL_MODULE_PRELOAD_BUDGET = 700 * 1024; +const INITIAL_MODULE_PRELOAD_BUDGET = 750 * 1024; assert.ok(initialModulePreloadBytes <= INITIAL_MODULE_PRELOAD_BUDGET, `Initial modulepreload budget exceeded: ${initialModulePreloadBytes} > ${INITIAL_MODULE_PRELOAD_BUDGET}`); const DEFAULT_CHUNK_WARNING_BYTES = 500 * 1024;