fix(core): 修复 #892 divider 撤销后输入报错#894
Conversation
beforeinput targetRange 映射改为容错模式 补充回归测试覆盖映射失败与 stale DOM 场景 增加 core patch changeset Closes: #892
🦋 Changeset detectedLatest commit: 2a7b8a3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 8 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📝 WalkthroughWalkthroughThis PR hardens the beforeInput event handler to tolerate stale DOM target ranges that occur after undo operations. The fix wraps range conversion in try/catch with error suppression, skips DOM-based selection when conversion fails, and includes tests verifying both null-return and exception paths still allow text insertion to proceed. ChangesbeforeInput stale DOM tolerance fix
Sequence Diagram(s)(No diagram generated; the change is a defensive guard condition, not a multi-component control-flow or state-transition sequence.) Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
背景
修复 issue #892:在默认 demo 中执行“插入分割线 -> 撤销 -> 重新输入”时,偶发抛出
Cannot resolve a Slate node from DOM node。变更
在
beforeinput中将targetRange -> Slate range的映射改为容错模式:suppressThrow: true\n - 对 stale DOM 导致的映射异常进行兜底(跳过重选区,不中断输入)@wangeditor-next/corepatch)验证
pnpm --filter @wangeditor-next/core test -- __tests__/text-area/event-handlers/before-input.test.tspnpm --filter @wangeditor-next/core test -- __tests__/text-area/event-handlers/composition.test.ts __tests__/text-area/syncSelection.test.tspnpm --filter @wangeditor-next/core exec eslint src/text-area/event-handlers/beforeInput.ts __tests__/text-area/event-handlers/before-input.test.tspnpm --filter @wangeditor-next/core buildCloses #892
Summary by CodeRabbit
Bug Fixes