Skip to content

fix(codemirror): ignore stale asynchronous language loads - #1003

Merged
petyosi merged 1 commit into
mdx-editor:mainfrom
huyanxius:fix/codemirror-stale-language-load-20261025
Oct 27, 2026
Merged

petyosi merged 1 commit into
mdx-editor:mainfrom
huyanxius:fix/codemirror-stale-language-load-20261025

Conversation

@huyanxius

@huyanxius huyanxius commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The code-block editor awaits dynamically loaded language support before creating its CodeMirror view. If the block is removed or its language changes while that promise is pending, the old effect still creates a view. An older load finishing last replaces the current editor with stale code, losing newer visible edits; an unmounted block instead receives an orphaned editor.

Changes

  • Mark each effect disposed in cleanup and ignore successful or rejected language loads after disposal.
  • Keep current language loading and fallback behavior unchanged for active effects.
  • Add real EditorView lifecycle regressions for unmount, out-of-order language changes with intervening edits, and rejected loads after unmount.

Validation

Based on main 4d9499a86cb797cb92d2a6a4718619983e5955e3.

  • The unmount and stale-language regressions fail against unchanged main, then pass with this fix.
  • Full Vitest suite: 183 passed; existing 1 skipped and 1 todo unchanged.
  • npm run typecheck and npm run lint: passed.
  • NODE_OPTIONS=--max-old-space-size=1400 npm run build: passed, including declaration rollup. The initial unconstrained build was killed during declaration generation under cloud memory pressure.
  • Independent code review and focused rerun passed. Scoped jsdom geometry shims avoid unsupported browser-measurement errors.
  • Native browser tests were not completed locally; see the CI outcome below.

No dependency, workflow, or public API changes.

CI outcome

CI run 40184410937 completed for head 1e16b00857c1e0d2e178c9d3d109a69ed5604bb7. The overall run is not green.

  • Test (lint, typecheck and unit tests), Build Docs, and Build JS (including packed React consumers and cross-version Markdown replay) passed.
  • Browser compatibility: 127 passed, 2 failed. Both failures are Firefox cases in tests/browser/table-image-dialog.spec.ts:68, for cell/root paste uploads that complete after moving to another cell. They fail at line 82 because window.finishTableImageUpload is not a function.

The failed test and its bug-991 story are byte-identical to base 4d9499a. That story installs only table/image/toolbar plugins and does not mount CodeMirror. The new Vitest mock is confined to src/test/codemirror-lifecycle.test.tsx; Playwright runs tests/browser in a separate job, and Ladle loads src/examples/*.tsx.

The existing #995 head 53887ad239839a53c9128d66098310023032c1de restores Firefox's constructor-dropped synthetic clipboardData in these exact cases and asserts the image payload before dispatch. These facts strongly point to the inherited clipboard fixture issue rather than this CodeMirror change. A pristine-base local rerun was attempted but blocked before page creation by uv_interface_addresses in the Ladle server; it did not execute the baseline assertions. No fixture changes or blind CI reruns were added here.

@petyosi
petyosi merged commit ceb2390 into mdx-editor:main Oct 27, 2026
3 of 4 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 4.3.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants