Skip to content

[lexical] Bug Fix: Clamp DOM selection offsets to valid lexical TextNode offsets in $internalResolveSelectionPoint#7725

Merged
etrepum merged 6 commits intofacebook:mainfrom
etrepum:validate-resolvedFocusPoint
Jul 24, 2025
Merged

[lexical] Bug Fix: Clamp DOM selection offsets to valid lexical TextNode offsets in $internalResolveSelectionPoint#7725
etrepum merged 6 commits intofacebook:mainfrom
etrepum:validate-resolvedFocusPoint

Conversation

@etrepum
Copy link
Copy Markdown
Collaborator

@etrepum etrepum commented Jul 24, 2025

Description

In some scenarios when IME input is happening, the browser's Text node will have a selection or content that is not represented in the lexical TextNode (a trailing zero-width-space). This changes the $internalResolveSelectionPoint implementation such that it will only resolve valid offsets by clamping to the size of the TextNode.

There were also scenarios where the MutationObserver handles text mutations without updating the lexical selection, so a similar fix was applied to flushMutations

Closes #7715 (superseded by this PR)
Closes #7639

Test plan

e2e tests pass, added new e2e test to exercise flushMutations edge cases

…ode offsets in $internalResolveSelectionPoint
@vercel
Copy link
Copy Markdown

vercel bot commented Jul 24, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 24, 2025 8:18pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 24, 2025 8:18pm

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 24, 2025
@etrepum etrepum added extended-tests Run extended e2e tests on a PR and removed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Jul 24, 2025
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 24, 2025
@etrepum etrepum added this pull request to the merge queue Jul 24, 2025
Merged via the queue into facebook:main with commit 4d21856 Jul 24, 2025
39 checks passed
@etrepum etrepum deleted the validate-resolvedFocusPoint branch July 24, 2025 21:46
@etrepum etrepum mentioned this pull request Aug 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Uncaught Error: $getTextNodeOffset: invalid offset 470 for size 378 at key 48

3 participants