Skip to content

[lexical][lexical-overflow][lexical-react] Bug Fix: Make OverflowNode inline without the line break caret regression - #14

Closed
Vedthakar wants to merge 1 commit into
mainfrom
fix/9454-overflow-inline
Closed

Vedthakar wants to merge 1 commit into
mainfrom
fix/9454-overflow-inline

Conversation

@Vedthakar

@Vedthakar Vedthakar commented Oct 24, 2026 •

Copy link
Copy Markdown
Owner

Description

OverflowNode is now inline (isInline() returns true), as meta#6027 first tried. meta#6535 reverted meta#6027 because, in plain-text mode or with Shift+Enter in rich text, a line break typed at the end of the overflow left the caret before the trailing LineBreakNode.

Root cause. Once OverflowNode is inline, a <br> ends up as the last thing inside an inline <span> at the end of a paragraph. Two things then go wrong:

  1. The reconciler adds a managed trailing <br> only when a block's direct last child is a LineBreakNode. Here the paragraph's last child is the OverflowNode, so no managed <br> is added and the new empty line has no caret position.
  2. After the character-limit plugin wraps the newly inserted line break and merges it into the existing overflow, the selection is an element point at the end of the OverflowNode, past its <br>. The browser can't put the caret there and moves it to before the overflow, so the next character goes in front of the 6. The test saw 76 instead of 6<br>7.

Changes

Closes meta#9454

Test plan

Before

  • isInline() alone (the Fix OverflowNode configuration meta/lexical#6027 configuration), packages/lexical-playground/src/__tests__/browser/CharacterLimit.test.ts (vitest browser, chromium): 6 failed | 10 passed (16). This is the Revert "Fix OverflowNode configuration" meta/lexical#6535 regression: the caret lands before the line break in plain text, and the delete text in front cases fail.
  • New unit tests in packages/lexical-react/src/__tests__/unit/useLexicalCharacterLimit.test.ts against main: 3 failed | 7 passed (10).
  • New core test in packages/lexical/src/__tests__/unit/LexicalReconciler.test.ts (a paragraph ending in a LinkNode whose last child is a LineBreakNode) against main: 1 failed. No managed <br> is rendered after the <a>.

After

  • CharacterLimit.test.ts (browser): 20 passed (20). That's the original 16 plus a new Shift+Enter case for each charset and mode, which guards the Revert "Fix OverflowNode configuration" meta/lexical#6535 rich-text scenario (it also passes on main).
  • LexicalReconciler.test.ts: 47 passed (47). The new test checks that the managed <br> follows the <a>, and is removed once text is appended after the line break inside the link.
  • useLexicalCharacterLimit.test.ts: 10 passed (10). New tests:
    • OverflowNode is inline.
    • The caret stays after a line break merged into the overflow.
    • A block ending with an inline element that ends with a line break gets a managed <br>, which goes away again once text follows.
  • Full unit suite: 375 files, 6331 passed, 1 skipped.
  • e2e CharacterLimit.spec.mjs (chromium): rich 12 passed / 4 skipped, plain text 8 passed. Same as main.
  • e2e Links.spec.mjs, Selection.spec.mjs and regression/1113-link-newline-at-end.spec.mjs (chromium), because editor DOM now changes for inline elements that end with a line break at the end of a block. The branch and main (4a7b21c) give identical results: rich 66 passed / 13 skipped, plain text 4 passed / 75 skipped. The skips are the specs' own mode guards. There's no dedicated LineBreak e2e spec in the repo. Firefox and WebKit were not run locally (WebKit doesn't launch in this environment).
  • tsc, eslint, prettier, flow: clean.
  • No test depends on a feature flag.

Fork CI: GitHub Actions haven't run on this fork PR; all results above are from local runs.


Author: Ved Thakar (@Vedthakar)

… inline without the line break caret regression

OverflowNode.isInline() now returns true (meta#6027, reverted in meta#6535).

The revert was caused by a trailing LineBreakNode inside the now inline
OverflowNode: the browser can't put the caret after a <br> that ends an
inline element, so the next character landed before the line break.

- The reconciler gives a block the managed trailing <br> when its last
  child is an inline element that itself ends with a LineBreakNode.
- $wrapOverflowedNodes moves a caret left at the end of an OverflowNode
  ending with a line break to the same spot just after the OverflowNode.

Closes meta#9454

Signed-off-by: Ved Thakar <111605341+Vedthakar@users.noreply.github.com>
Co-authored-by: Ved Thakar <111605341+Vedthakar@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Vedthakar
Vedthakar force-pushed the fix/9454-overflow-inline branch from d3e46af to 46d1e96 Compare October 25, 2026 01:07
@Vedthakar

Copy link
Copy Markdown
Owner Author

Superseded by meta#9461.

@Vedthakar Vedthakar closed this Oct 25, 2026
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.

[lexical-overflow] Make OverflowNode a proper inline element (revisit #6027 / #6535)

1 participant