Skip to content

fix(desktop): prevent CodeMirror line tree corruption - #4930

Merged
Jocs merged 1 commit into
marktext:developfrom
Renakoni:fix/codemirror-chunksize-crash
Sep 4, 2026
Merged

Jocs merged 1 commit into
marktext:developfrom
Renakoni:fix/codemirror-chunksize-crash

Conversation

@Renakoni

Copy link
Copy Markdown
Contributor

Closes #4921
Closes #4456

Summary

Prevents Vue from deep-proxying the stateful CodeMirror instance used by Source Code mode. CodeMirror's document tree relies on strict object identity between documents, leaf chunks, and lines; proxying the instance can break those parent relationships and surface as the reported lineNo / chunkSize renderer crash.

The instance is now wrapped with Vue's markRaw, matching the existing Muya integration. A focused Electron e2e regression covers the real file-update path followed by the reported Bash-script paste, verifies the CodeMirror line tree remains consistent, confirms the paste changes the document, and checks for renderer errors.

Type of change

  • Bug fix (non-breaking, fixes an issue)
  • New feature (non-breaking, adds functionality)
  • Breaking change (causes existing functionality to change)
  • Documentation update

Test plan

  • New tests added (or explain why not needed)
  • Manually tested on: Windows (Electron e2e)

The following checks passed: desktop build, TypeScript typecheck, targeted ESLint, and the related Source Code e2e suite (18 passed, 1 existing skip).

Notes for reviewers [optional]

The final regression spec was verified red/green against both implementations: without markRaw, the paste was applied but lineTreeIntact was false; with markRaw, the same test passes. Both linked issues report the same CodeMirror lineNo / chunkSize stack. #4921 supplies the Bash paste case; #4456 has no reproduction steps but hits the same remaining CodeMirror-backed Source Code path.


By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

niyo-oyin added a commit to niyo-oyin/marktext-ja that referenced this pull request Jul 29, 2026
- PR marktext#4946 (includes its base PR marktext#4942): removes the quadratic costs
  that froze large documents and mounts them progressively — a 2.1 MB
  document goes from an indefinite freeze to interactive in seconds.
  Applied verbatim; upstream review addressed 19 findings with 31
  regression tests, all passing here.
- PR marktext#4931 (marktext#4926): deleting at an offset inside a surrogate pair left
  a lone surrogate that crashed text-unicode ("Invalid offset - splits
  unicode bytes"). The content.ts hunk conflicted with our Phase 1
  isComposed guards and was integrated by hand; the new cursor snap
  additionally runs only when no IME composition is open, since moving
  the DOM selection mid-composition would detach the IME anchor.
- PR marktext#4913 (marktext#4899): Shift+Tab outdent with trailing sibling blocks
  corrupted the state tree (paragraphs appended directly into a list),
  crashing the next composed op. muya hunks only — the PR's legacy
  muyajs hunks target the removed engine.
- PR marktext#4911 skipped: the equivalent detached-block guard already exists
  in @muyajs/core's language selector (marktext#4654), verified in source.
- PR marktext#4930 (marktext#4921): CodeMirror instance wrapped in a Vue proxy broke
  source-code mode; markRaw fix applied cleanly.

muya suite 1515/1515, tsc/eslint/madge clean.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ef4yFuXFbyKNTazkwUtygY
niyo-oyin added a commit to niyo-oyin/marktext-ja that referenced this pull request Jul 29, 2026
- PR marktext#4946 (includes its base PR marktext#4942): removes the quadratic costs
  that froze large documents and mounts them progressively — a 2.1 MB
  document goes from an indefinite freeze to interactive in seconds.
  Applied verbatim; upstream review addressed 19 findings with 31
  regression tests, all passing here.
- PR marktext#4931 (marktext#4926): deleting at an offset inside a surrogate pair left
  a lone surrogate that crashed text-unicode ("Invalid offset - splits
  unicode bytes"). The content.ts hunk conflicted with our Phase 1
  isComposed guards and was integrated by hand; the new cursor snap
  additionally runs only when no IME composition is open, since moving
  the DOM selection mid-composition would detach the IME anchor.
- PR marktext#4913 (marktext#4899): Shift+Tab outdent with trailing sibling blocks
  corrupted the state tree (paragraphs appended directly into a list),
  crashing the next composed op. muya hunks only — the PR's legacy
  muyajs hunks target the removed engine.
- PR marktext#4911 skipped: the equivalent detached-block guard already exists
  in @muyajs/core's language selector (marktext#4654), verified in source.
- PR marktext#4930 (marktext#4921): CodeMirror instance wrapped in a Vue proxy broke
  source-code mode; markRaw fix applied cleanly.

muya suite 1515/1515, tsc/eslint/madge clean.
@Jocs
Jocs merged commit 1d3025b into marktext:develop Sep 4, 2026
10 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

2 participants