Skip to content

Fix: handle CodeMirror race condition error gracefully - #67

Merged
Tkaixiang merged 1 commit into
Tkaixiang:trunkfrom
mdsakalu:fix/codemirror-race-condition
Jan 14, 2026
Merged

Tkaixiang merged 1 commit into
Tkaixiang:trunkfrom
mdsakalu:fix/codemirror-race-condition

Conversation

@mdsakalu

Copy link
Copy Markdown

Summary

  • Add defensive handling for a known CodeMirror 5 race condition that causes TypeError: Cannot read properties of undefined (reading 'map') errors when clicking in the source code editor during rapid state changes
  • Add null check in adjustCursor() for when cm.getLine() returns null (cursor beyond document bounds)
  • Suppress non-fatal CodeMirror errors instead of showing an error dialog to the user

Root Cause

This is a known Vue/CodeMirror 5 compatibility issue where Vue's reactive proxy system can interfere with CodeMirror's internal line measurement data structures during mouse click handling.

See: codemirror/codemirror5#6886

Error Stack Trace (before fix)

TypeError: Cannot read properties of undefined (reading 'map')
    at prepareMeasureForLine
    at coordsCharInner
    at coordsChar
    at posFromMouse
    at CodeMirror.onMouseDown

Test Plan

  • Build completes successfully
  • Click rapidly in source code editor - should no longer show error dialog
  • Switch between files while clicking - should handle gracefully

Add defensive handling for a known CodeMirror 5 race condition that
causes "Cannot read properties of undefined (reading 'map')" errors
when clicking in the source code editor during rapid state changes.

Changes:
- Add null check in adjustCursor() for when cm.getLine() returns null
- Add isCodeMirrorRaceCondition() to detect and suppress non-fatal
  CodeMirror errors instead of showing an error dialog

This is a known Vue/CodeMirror 5 compatibility issue where Vue's
reactive proxy system can interfere with CodeMirror's internal
line measurement data structures.

See: codemirror/codemirror5#6886
@mdsakalu
mdsakalu force-pushed the fix/codemirror-race-condition branch from b6a1233 to 73fbc9e Compare January 13, 2026 22:39

@Tkaixiang Tkaixiang left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I can't personally re-produce such errors reliably but I have definitely encountered them before. These changes are logically sound defensive checks

@Tkaixiang
Tkaixiang merged commit 05269ea into Tkaixiang:trunk Jan 14, 2026
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.

2 participants