fix(preview): catch CodeMirror mapPos RangeError in editors (ELECTRON-3Y)#1940
fix(preview): catch CodeMirror mapPos RangeError in editors (ELECTRON-3Y)#1940
Conversation
…SON edits (ELECTRON-3Y)
Add key={activeTabId} to all CodeMirror editor instances in PreviewPanel
to force React to remount the editor when switching tabs, preventing
stale position errors from in-place value reconciliation.
Also fix a timer race condition in InlineAgentEditor's handleJsonChange
where overlapping setTimeout calls could prematurely clear the editing
flag, allowing the useEffect to overwrite CodeMirror's value mid-edit.
7a8d98e to
921f972
Compare
Code Review:fix(preview): catch CodeMirror mapPos RangeError in editors (ELECTRON-3Y) (#1940)变更概述本 PR 修复了两个独立问题:① PreviewPanel 切换标签页时,CodeMirror 编辑器实例(MarkdownEditor、HTMLEditor、TextEditor)因 React 复用旧实例而产生 方案评估结论:✅ 方案合理 两处修复均直接针对根因:给编辑器加 问题清单🔵 LOW —
|
| # | 严重级别 | 文件 | 问题 |
|---|---|---|---|
| 1 | 🔵 LOW | PreviewPanel.tsx:440,512,552,597,620 |
?? undefined 冗余表达式 |
| 2 | 🔵 LOW | previewEditorKeyRemount.test.ts:87 |
第三个测试用例无实质断言 |
结论
✅ 批准合并 — 无阻塞性问题,两处修复方向正确,仅有两个低优先级建议供参考。
本报告由本地 pr-review skill 生成,包含完整项目上下文,无截断限制。
CONCLUSION: APPROVED
IS_CRITICAL_PATH: false
PR_NUMBER: 1940
|
✅ 已自动 review,无阻塞性问题,正在触发自动合并。 |
|
|
Summary
Fixes ELECTRON-3Y —
RangeError: Position X is out of range for changeset of length YinChangeDesc.mapPos(6 events, last seen 6 hours ago, still active).Root cause: When the active tab changes in PreviewPanel, CodeMirror editors receive a completely new
valueprop. Without akeytied to the tab ID, React reuses the same component instance and@uiw/react-codemirrortries to reconcile the old internal state with the new value viaChangeDesc.mapPos(), which throws when stale positions exceed the new document length.Additionally,
InlineAgentEditor'shandleJsonChangehad overlappingsetTimeoutcalls that could prematurely clear the editing flag, allowinguseEffectto overwrite CodeMirror's value mid-edit.Fix:
key={activeTabId}to all CodeMirror editor instances inPreviewPanel.tsx— forces React to unmount/remount the editor on tab switch, preventing stale position errors entirelyInlineAgentEditor.tsx— clear previous timer before setting a new oneTest plan
previewEditorKeyRemount.test.tsverifies timer cleanup prevents premature flag resetpreviewFileWatch.dom.test.ts)bunx tsc --noEmitpassesbun run lint:fixpasses (0 errors)bun run formatpasses