Skip to content

[lexical-utils] Bug Fix: Pass editor context to editorState.read() in markSelection#8411

Merged
etrepum merged 4 commits into
mainfrom
fix/mark-selection-editor-context
Apr 29, 2026
Merged

[lexical-utils] Bug Fix: Pass editor context to editorState.read() in markSelection#8411
etrepum merged 4 commits into
mainfrom
fix/mark-selection-editor-context

Conversation

@potatowagon
Copy link
Copy Markdown
Contributor

@potatowagon potatowagon commented Apr 28, 2026

Summary

  • PR [lexical][lexical-html] Feature: Extensible DOM create/update/export #8353 renamed rangeTargetFromPoint to $rangeTargetFromPoint, which now calls $getEditor() to use the extensible DOM API. However, the editorState.read() call in markSelection's compute() function was not updated to pass {editor}, so $getEditor() returns null and throws when the selection's anchor/focus is on an element node (not text).
  • This fix passes the editor reference to editorState.read(() => { ... }, {editor}) so that $getEditor() can find the active editor inside $rangeTargetFromPoint.

Test plan

pnpm run test-unit
all test pass, including
✓ unit packages/lexical-utils/src/tests/unit/markSelection.test.tsx (4 tests) 193ms

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Apr 28, 2026 6:31pm
lexical-playground Ready Ready Preview, Comment Apr 28, 2026 6:31pm

Request Review

@meta-cla meta-cla 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 Apr 28, 2026
@potatowagon potatowagon marked this pull request as draft April 28, 2026 17:08
@etrepum
Copy link
Copy Markdown
Collaborator

etrepum commented Apr 28, 2026

A simpler fix would be to make $rangeTargetFromPoint take an editor argument since it's already available all the way up the stack

… markSelection

PR #8353 renamed rangeTargetFromPoint to $rangeTargetFromPoint, which
now requires an active editor context via $getEditor(). However, the
editorState.read() call in markSelection's compute() was not updated
to pass {editor}, causing $getEditor() to return null and throw when
the selection's anchor/focus is on an element node.
Adds tests covering both text-type and element-type selection points.
The element-type test verifies the fix for the missing {editor} context
in editorState.read(), which caused $getEditor() to throw.
…tead of using $getEditor()

Simpler fix per review feedback: thread the editor argument through
$rangeTargetFromPoint since it's already available in $rangeFromPoints,
removing the need for $getEditor() and the {editor} option on
editorState.read().
@potatowagon
Copy link
Copy Markdown
Contributor Author

A simpler fix would be to make $rangeTargetFromPoint take an editor argument since it's already available all the way up the stack

good point, thankyou! simplified it accordingly

@etrepum etrepum added this pull request to the merge queue Apr 29, 2026
Merged via the queue into main with commit 716a08f Apr 29, 2026
44 checks passed
@etrepum etrepum mentioned this pull request May 28, 2026
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants