Skip to content

perf(frontend): keep Milkdown out of the desktop shell closure (WI-2144) - #523

Merged
stefan-ernst merged 2 commits into
mainfrom
feat/wi-2144-milkdown-closure
Nov 16, 2026
Merged

stefan-ernst merged 2 commits into
mainfrom
feat/wi-2144-milkdown-closure

Conversation

@stefan-ernst

Copy link
Copy Markdown
Contributor

Summary

  • Stop the desktop shell static closure from pulling in Milkdown: the milkdown manual-chunk group now sets includeDependenciesRecursively: false, so the shared DOMPurify dependency used by the always-loaded sanitizer is no longer absorbed into the editor chunk.
  • Extend scripts/check-entry-assets.js to walk the desktop shell's static import closure, fail if an optional library appears there, and budget the complete closure.

WI-2144.

Root cause

@milkdown/components depends on dompurify. With the default recursive grouping, DOMPurify was emitted inside the milkdown-*.js chunk. sanitize.ts (imported by sso.js → MainApp) imports DOMPurify, so the desktop shell's static closure included the whole editor chunk.

Measurement

Built with bun --bun run build:app; MainApp static closure:

  • Before: 228 chunks, 1,546,472 B raw / 524,344 B gzip, includes milkdown-*.js.
  • After: 228 chunks, 1,030,235 B raw / 365,370 B gzip, no milkdown; DOMPurify stays in its own small shared chunk.
  • Delta: ~516 KB raw / ~159 KB gzip off the desktop cold-start closure. The Milkdown JS/CSS chunks are still emitted and load only with the lazy editor.

Guard

check-entry-assets.js now walks static imports from the MainApp-*.js chunk (dynamic imports are not followed), fails on Excalidraw/Mermaid/Cytoscape/Milkdown/React/SvelteFlow/D3 in that closure, and enforces a closure budget. Run against the pre-fix build it fails with Milkdown: ./milkdown-DN-kA6qv.js; against the fixed build it passes.

Validation

  • bun --bun run build:app: passes; the entry-asset check reports the desktop shell closure (228 chunks, ~1006 KiB raw / ~357 KiB gzip).
  • bun --bun x biome check scripts/check-entry-assets.js vite.config.js: passes.
  • Pre-commit frontend guards pass.
  • Sanitizer and editor suites: 11 files / 91 tests pass (src/lib/utils/sanitize.test.ts src/lib/editors).
  • Companion tests: pending PR in Windshiftapp/core-tests-internal, branch feat/wi-2144-milkdown-closure.

Go/PostgreSQL and browser suites were not run: no backend, schema or browser behavior changed.

@github-actions

Copy link
Copy Markdown

Size Change: 0 B 🆕

Total Size: 0 B

compressed-size-action

@stefan-ernst

Copy link
Copy Markdown
Contributor Author

Reviewed head 914a5811. One finding:

P2 — Static-import parsing skips valid minified identifiers containing $

frontend/scripts/check-entry-assets.js:90–91: the import/export binding character classes use \w, which excludes $. Rolldown emits these identifiers in the current production build, so the new guard silently drops real static edges and can miss both optional-library leaks and budget overruns.

Minimal reproduction against the PR's exported functions:

findStaticImports('import{a as $}from"./milkdown-test.js";')
// Actual: []
// Expected: ["./milkdown-test.js"]

Walking a shell containing that import therefore reports no forbidden Milkdown asset. This also affects the actual build: comparing the guard with es-module-lexer found 228 reported chunks versus 229 actual chunks. The missed MainApp import contains u as $t and points to viewBackgroundContext-BYkXrRqa.js; the reported raw total is 1,030,204 B, versus 1,035,191 B for the complete static closure.

Please use a JS import lexer/bundler metadata, or at minimum handle $ in both import and re-export bindings, with regression coverage for this case.

Validation

Using Node 24.18.0 in a detached checkout of the PR head, with the existing installed dependencies:

  • npm run build:app — passed. An independent lexer-based traversal confirms Milkdown is outside the actual shell closure.
  • npm exec -- biome check scripts/check-entry-assets.js vite.config.js — passed.
  • From core-tests: ./run-overlay-script.sh "$REVIEW_DIR" scripts/run-frontend-tests.sh src/lib/utils/checkEntryAssets.test.js — 20/20 passed (REVIEW_DIR is the detached PR checkout).
  • Direct Node reproduction and lexer comparison above confirm the guard defect.

Full frontend, browser, and backend suites were not run.

@stefan-ernst

Copy link
Copy Markdown
Contributor Author

Re-review: GitHub still shows head 914a58111b1883b492017073b3fa8fe820b60d4f, the same commit reviewed previously. The diff is unchanged, and the P2 finding remains unresolved: findStaticImports still excludes $ from import/re-export bindings, so valid minified static imports are omitted from the closure and budget checks.

Previous reproduction and validation results still apply. Build and tests were not rerun because there are no new commits to validate.

@stefan-ernst

Copy link
Copy Markdown
Contributor Author

Fixed the P2 finding in 5f9a32b0. Both import and re-export binding patterns now accept $, including the production u as $t case. This uses the minimal parser fix requested in the review without adding dependencies or changing lockfiles.

Regression coverage is pushed to companion test PR Windshiftapp/core-tests-internal#58 (23c2ca0b): eight import/re-export binding cases plus a transitive Milkdown-leak regression. All nine failed against the previous implementation before the fix; all now pass.

Validation (Node 24.18.0, selected by scripts/run-with-core-node.sh):

  • From /private/tmp/wi-2144-tests: ./run-overlay-script.sh /private/tmp/wi-2144-core scripts/run-frontend-tests.sh src/lib/utils/checkEntryAssets.test.js — initially 9 failed / 27 passed; after the fix, 36 passed.
  • From the same directory: ./run-overlay-script.sh /private/tmp/wi-2144-core scripts/run-frontend-tests.sh src/lib/utils/checkEntryAssets.test.js src/lib/utils/sanitize.test.ts src/lib/editors — 12 files / 127 tests passed.
  • From /private/tmp/wi-2144-core/frontend: /private/tmp/wi-2144-tests/scripts/run-with-core-node.sh /private/tmp/wi-2144-core npm run build:app — passed; closure is 229 chunks, 1,035,191 raw bytes / ~359.07 KiB gzip, with Milkdown still excluded.
  • Independent es-module-lexer traversal matched the guards complete closure exactly (229 chunks / 1,035,191 raw bytes).
  • From the frontend directory: /private/tmp/wi-2144-tests/scripts/run-with-core-node.sh /private/tmp/wi-2144-core npm exec -- biome check scripts/check-entry-assets.js vite.config.js — passed.
  • From the test checkout: /private/tmp/wi-2144-tests/scripts/run-with-core-node.sh /private/tmp/wi-2144-core npm exec --prefix /private/tmp/wi-2144-core/frontend -- biome check --vcs-enabled=false --config-path=/private/tmp/wi-2144-core/frontend/biome.json frontend/src/lib/utils/checkEntryAssets.test.js — passed. Cross-worktree VCS-enabled invocations initially triggered a Biome path-root panic; disabling VCS discovery for this explicit-file check avoided that tool bug. The reported formatting issue was fixed.
  • Core pre-commit checks passed, including npm run check, npm run typecheck (0 errors, 3 warnings), and the frontend v2 field guard.

Full frontend, browser, Go, and PostgreSQL suites were not run; this follow-up only changes the build-time import guard and its unit coverage. Both branches were pushed successfully to origin.

@stefan-ernst
stefan-ernst merged commit 16397fc into main Nov 16, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant