Skip to content

Suppress findPath throw when translating beforeinput target ranges in Editable (#3556)#6080

Open
isachivka wants to merge 1 commit into
ianstormtaylor:mainfrom
isachivka:fix/editable-suppress-throw-before-input
Open

Suppress findPath throw when translating beforeinput target ranges in Editable (#3556)#6080
isachivka wants to merge 1 commit into
ianstormtaylor:mainfrom
isachivka:fix/editable-suppress-throw-before-input

Conversation

@isachivka

@isachivka isachivka commented Jul 2, 2026

Copy link
Copy Markdown

Description

Editable.onDOMBeforeInput has two ReactEditor.toSlateRange call sites that hard-code suppressThrow: false — the event.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), findPath throws Unable to find the path for Slate node: … out of the DOM event handler, reaching window.onerror and crashing the host app. This is the long-standing #3556 family.

Every other toSlateRange call site in this file already passes suppressThrow: true and null-checks the result — this PR aligns the last two:

  • getTargetRanges branch: 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.
  • WebKit ShadowRoot branch: suppressThrow: true; on null skip only the Transforms.select, still preventDefault (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:

Error: Unable to find the path for Slate node: {...}
    at Object.findPath
    at Object.toSlatePoint
    at Object.toSlateRange
    at HTMLDivElement.<anonymous>   ← Editable.onDOMBeforeInput, getTargetRanges branch

toSlatePoint/toSlateRange already honor suppressThrow around their findPath calls (returning null), so the change is confined to the two call sites and their degrade paths.

Checks

  • yarn test:jest after yarn build:rollup: 94/94 pass.
  • yarn lint:typescript: no new errors (the conditional return type T extends true ? Range | null : Range makes the null-narrowing type-safe).
  • Changeset added (slate-react patch).

Issue

Relates to #3556

@changeset-bot

changeset-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d7cb40e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
slate-react Patch

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

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.

1 participant