Suppress findPath throw when translating beforeinput target ranges in Editable (#3556)#6080
Open
isachivka wants to merge 1 commit into
Open
Conversation
🦋 Changeset detectedLatest commit: d7cb40e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Editable.onDOMBeforeInputhas twoReactEditor.toSlateRangecall sites that hard-codesuppressThrow: false— theevent.getTargetRanges()branch and the WebKit ShadowRoot branch. When the browser's target range points at a DOM node that is no longer resolvable to a Slate node (stale NODE_MAP entry after a re-render, IME composition, clicking between editors),findPaththrowsUnable to find the path for Slate node: …out of the DOM event handler, reachingwindow.onerrorand crashing the host app. This is the long-standing #3556 family.Every other
toSlateRangecall site in this file already passessuppressThrow: trueand null-checks the result — this PR aligns the last two:getTargetRangesbranch:suppressThrow: true; when the range is unmappable, fall back to slate's synthetic handling at the current selection (native = false) — native handling can't be trusted with a range we couldn't map. Resolvable ranges behave exactly as before.suppressThrow: true; onnullskip only theTransforms.select, stillpreventDefault(letting WebKit native-edit a shadow-root range we couldn't map would diverge the DOM from the model).Context / evidence
In production (slate-react 0.124.2) this is a steady session-killing crash — ~8 users/day, all with the identical stack:
toSlatePoint/toSlateRangealready honorsuppressThrowaround theirfindPathcalls (returningnull), so the change is confined to the two call sites and their degrade paths.Checks
yarn test:jestafteryarn build:rollup: 94/94 pass.yarn lint:typescript: no new errors (the conditional return typeT extends true ? Range | null : Rangemakes the null-narrowing type-safe).slate-reactpatch).Issue
Relates to #3556