Skip to content

[lexical][lexical-rich-text] Bug Fix: Show block cursor before block decorators regardless of preceding sibling - #8888

Merged
etrepum merged 2 commits into
meta:mainfrom
ochevallier:ochevallier/fix-block-cursor-placement
Jul 30, 2026
Merged

etrepum merged 2 commits into
meta:mainfrom
ochevallier:ochevallier/fix-block-cursor-placement

Conversation

@ochevallier

Copy link
Copy Markdown
Contributor

Description

The block cursor was not displayed before a block-level decorator node (e.g. HorizontalRuleNode) when the preceding sibling was an editable element such as a ParagraphNode. The native browser cursor would appear on the decorator's DOM element (e.g. directly on the <hr>), which is visually misleading — the cursor appears below the element rather than at a meaningful insertion point, and typing inserts a new paragraph above the decorator.

The root cause was in $updateDOMBlockCursorElement (LexicalUtils.ts): when the collapsed element-type selection pointed at a child that needs a block cursor, the code required the previous sibling to also need a block cursor (or be null). The sibling check was intended to avoid showing a block cursor when the native cursor could naturally sit at the end of the preceding editable element, but for DecoratorNode instances (which are contenteditable="false"), the native cursor cannot meaningfully sit on them, making the block cursor necessary regardless of the sibling.

This PR removes the sibling check so the block cursor is displayed whenever the adjacent child needs one ($needsBlockCursorBeside returns true), independently of the preceding sibling. The $needsBlockCursorBeside function itself is unchanged — the shadow root guard introduced in #8758 (which prevents block cursors between sibling shadow roots inside a shadow root parent) remains intact.

Test plan

Before

  • With an editor containing paragraph("text") → horizontalrule → paragraph("text"), placing the collapsed selection at root offset 1 (before the HorizontalRuleNode) did not render the block cursor (data-lexical-cursor). The native cursor appeared directly on the <hr> element, visually positioned below it, and typing created a new paragraph above the decorator without any visual indication of the insertion point.
Enregistrement.de.l.ecran.2026-07-29.a.13.41.30.mov

After

  • Unit tests (RichTextBlockCursorShadowRoot.test.ts): 3 new tests verify the block cursor DOM element ([data-lexical-cursor]) is rendered before a block decorator when preceded by an editable paragraph, between two block decorators, and as the first child → all passing.
  • E2E test (HorizontalRule.spec.mjs): New test "Shows block cursor before a horizontal rule preceded by a paragraph" verifies in a real browser that the PlaygroundEditorTheme__blockCursor div appears in the DOM between the paragraph and the <hr> after navigating with arrow keys.
  • All existing block cursor tests pass with no regression.
  • ESLint and TypeScript checks pass with no new errors.
Enregistrement.de.l.ecran.2026-07-29.a.13.40.59.mov

@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 Jul 29, 2026
@vercel

vercel Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview Jul 30, 2026 7:22am
lexical-playground Ready Ready Preview Jul 30, 2026 7:22am

Request Review

@ochevallier

Copy link
Copy Markdown
Contributor Author

need to fix e2e tests...

@ochevallier

Copy link
Copy Markdown
Contributor Author

e2e fixed :

Problem : The original e2e test used keyboard.press('Enter') after typing "Before", which created an extra empty paragraph. This produced a DOM structure (paragraph → paragraph → hr → paragraph) that didn't match the expected HTML (paragraph → hr → paragraph), causing the assertHTML to fail.

Solution : Fixed by removing the Enter keypress and instead setting the block cursor position programmatically via root.select(1, 1) in an editor.update() call. The same approach used by the "ArrowDown from block cursor between shadow root and decorator" test later in the file (Line 923).

@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Jul 30, 2026
@etrepum
etrepum added this pull request to the merge queue Jul 30, 2026
Merged via the queue into meta:main with commit e6de549 Jul 30, 2026
48 checks passed
@etrepum etrepum mentioned this pull request Aug 31, 2026
psoldunov added a commit to ensemblr-hq/ensemblr-electron that referenced this pull request Sep 12, 2026
Bumping `lexical` alone left `@lexical/react` on ^0.49.0, which pins its own
nested `[email protected]` — 23 duplicate copies across the `@lexical/*` tree. Two
copies of the package means two structurally identical but nominally distinct
`EditorState` types, so `npm run typecheck` failed on every call that passes
one across the boundary, and the composer editor tests failed with it.

Move the React bindings in step. The lockfile drops all 23 nested copies.

Lexical 0.50 also wraps a block decorator in zero-size decorator boundary
anchors (`<img data-lexical-decorator-boundary>`, absolutely positioned at
0x0, meta/lexical#8888), so the two tests that assert the editable root's
children now skip them. They contribute no line box, so the composer's layout
is unchanged.

Co-authored-by: Ensemblr <[email protected]>
psoldunov added a commit to ensemblr-hq/ensemblr-electron that referenced this pull request Sep 12, 2026
* chore(deps): bump lexical from 0.49.0 to 0.50.0

Bumps [lexical](https://github.com/facebook/lexical/tree/HEAD/packages/lexical) from 0.49.0 to 0.50.0.
- [Release notes](https://github.com/facebook/lexical/releases)
- [Changelog](https://github.com/facebook/lexical/blob/main/CHANGELOG.md)
- [Commits](https://github.com/facebook/lexical/commits/v0.50.0/packages/lexical)

---
updated-dependencies:
- dependency-name: lexical
  dependency-version: 0.50.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* fix(deps): move @lexical/react to 0.50.0 with lexical

Bumping `lexical` alone left `@lexical/react` on ^0.49.0, which pins its own
nested `[email protected]` — 23 duplicate copies across the `@lexical/*` tree. Two
copies of the package means two structurally identical but nominally distinct
`EditorState` types, so `npm run typecheck` failed on every call that passes
one across the boundary, and the composer editor tests failed with it.

Move the React bindings in step. The lockfile drops all 23 nested copies.

Lexical 0.50 also wraps a block decorator in zero-size decorator boundary
anchors (`<img data-lexical-decorator-boundary>`, absolutely positioned at
0x0, meta/lexical#8888), so the two tests that assert the editable root's
children now skip them. They contribute no line box, so the composer's layout
is unchanged.

Co-authored-by: Ensemblr <[email protected]>

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Philipp Soldunov <[email protected]>
Co-authored-by: Ensemblr <[email protected]>

This branch was successfully deployed

2 active deployments
Preview – lexical — 5f07d886 Deployed Jul 30, 2026 by vercel[bot]
Preview – lexical-playground — 5f07d886 Deployed Jul 30, 2026 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.

2 participants