Skip to content

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

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

etrepum merged 6 commits into
facebook:mainfrom
etrepum:validate-resolvedFocusPoint

Conversation

@etrepum

@etrepum etrepum commented Jul 24, 2025 •

Copy link
Copy Markdown
Collaborator

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

vercel Bot commented Jul 24, 2025 •

Copy link
Copy Markdown

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

This branch was successfully deployed

2 active deployments
Preview – lexical-playground — 8fad3886 Deployed Jul 24, 2025 by vercel[bot]
Preview – lexical — 8fad3886 Deployed Jul 24, 2025 by vercel[bot]
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