Skip to content

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

Open
Vedthakar wants to merge 3 commits into
meta:mainfrom
Vedthakar:fix/9454-overflow-inline
Open

Vedthakar wants to merge 3 commits into
meta:mainfrom
Vedthakar:fix/9454-overflow-inline

Conversation

@Vedthakar

@Vedthakar Vedthakar commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Description

This solves issue #9454.

OverflowNode is now inline (isInline() returns true), as #6027 first tried. #6535 reverted #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 #9454

Test plan

Before

  • isInline() alone (the Fix OverflowNode configuration #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" #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

On this branch, rebased onto current main:

  • CharacterLimit.test.ts (browser, Chromium): 32 passed, including the new cases with the caret inside the overflow (Shift+Enter, Enter and Backspace between the 6 and 7 of 12345[67], rich and plain text, both charsets). 8 of those 12 fail without the insertNewAfter change.
  • useLexicalCharacterLimit.test.ts, LexicalReconciler.test.ts, NodeStructureExtension.test.ts and the lexical-overflow tests (unit): 301 passed.
  • tsc, tsc-test, eslint and prettier on the changed files: clean. Firefox and WebKit were not run locally.

Author: Ved Thakar (@Vedthakar)

🤖 Generated with Claude Code

@vercel

vercel Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
lexical Ready Ready Preview Nov 16, 2026 11:59pm UTC
lexical-playground Ready Ready Preview Nov 16, 2026 11:59pm UTC

Request Review

@pkg-pr-new

pkg-pr-new Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
lexical

npm i https://pkg.pr.new/lexical@9461

@lexical/a11y

npm i https://pkg.pr.new/@lexical/a11y@9461

@lexical/clipboard

npm i https://pkg.pr.new/@lexical/clipboard@9461

@lexical/code

npm i https://pkg.pr.new/@lexical/code@9461

@lexical/code-core

npm i https://pkg.pr.new/@lexical/code-core@9461

@lexical/code-prism

npm i https://pkg.pr.new/@lexical/code-prism@9461

@lexical/code-shiki

npm i https://pkg.pr.new/@lexical/code-shiki@9461

@lexical/compiler

npm i https://pkg.pr.new/@lexical/compiler@9461

@lexical/devtools-core

npm i https://pkg.pr.new/@lexical/devtools-core@9461

@lexical/dragon

npm i https://pkg.pr.new/@lexical/dragon@9461

@lexical/eslint-plugin

npm i https://pkg.pr.new/@lexical/eslint-plugin@9461

@lexical/extension

npm i https://pkg.pr.new/@lexical/extension@9461

@lexical/fast-check

npm i https://pkg.pr.new/@lexical/fast-check@9461

@lexical/file

npm i https://pkg.pr.new/@lexical/file@9461

@lexical/hashtag

npm i https://pkg.pr.new/@lexical/hashtag@9461

@lexical/headless

npm i https://pkg.pr.new/@lexical/headless@9461

@lexical/history

npm i https://pkg.pr.new/@lexical/history@9461

@lexical/html

npm i https://pkg.pr.new/@lexical/html@9461

@lexical/internal

npm i https://pkg.pr.new/@lexical/internal@9461

@lexical/link

npm i https://pkg.pr.new/@lexical/link@9461

@lexical/list

npm i https://pkg.pr.new/@lexical/list@9461

@lexical/mark

npm i https://pkg.pr.new/@lexical/mark@9461

@lexical/markdown

npm i https://pkg.pr.new/@lexical/markdown@9461

@lexical/mdast

npm i https://pkg.pr.new/@lexical/mdast@9461

@lexical/offset

npm i https://pkg.pr.new/@lexical/offset@9461

@lexical/overflow

npm i https://pkg.pr.new/@lexical/overflow@9461

@lexical/plain-text

npm i https://pkg.pr.new/@lexical/plain-text@9461

@lexical/react

npm i https://pkg.pr.new/@lexical/react@9461

@lexical/rich-text

npm i https://pkg.pr.new/@lexical/rich-text@9461

@lexical/selection

npm i https://pkg.pr.new/@lexical/selection@9461

@lexical/table

npm i https://pkg.pr.new/@lexical/table@9461

@lexical/tailwind

npm i https://pkg.pr.new/@lexical/tailwind@9461

@lexical/text

npm i https://pkg.pr.new/@lexical/text@9461

@lexical/utils

npm i https://pkg.pr.new/@lexical/utils@9461

@lexical/y

npm i https://pkg.pr.new/@lexical/y@9461

@lexical/yjs

npm i https://pkg.pr.new/@lexical/yjs@9461

commit: 6a98ab8

@rootnode-bot rootnode-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking up #9454. The reconciler change is a nice general fix: a block that ends in an inline element whose last child is a LineBreakNode now gets the managed <br>, so links that end in a line break draw their empty line too. The new tests also fail on main and pass here.

One issue needs fixing before this lands.

A line break or paragraph typed inside the overflow splits the paragraph (packages/lexical-overflow/src/index.ts, insertNewAfter). OverflowNode.insertNewAfter() still delegates to parent.insertNewAfter(). While the node was a block, nothing called that method to split the overflow. Now that the node is inline, $splitNodeAtPoint in packages/lexical/src/LexicalSelection.ts splits it by calling insertNewAfter(), and the delegation creates a new paragraph. To reproduce, set the character limit to 5, type 1234567, press ArrowLeft, then:

Keys main this PR
Shift+Enter (rich) or Enter (plain), then x 123456⏎x7 in one paragraph 123456⏎x, with 7 in a new paragraph
Enter (rich), then x 123456 / x7 123456 / x / 7

This reproduces with real key presses in Chromium and Firefox (vitest browser mode). If the node splits itself, as LinkNode.insertNewAfter does, the main behaviour comes back and all of this PR's tests still pass:

insertNewAfter(_: RangeSelection, restoreSelection = true): null | LexicalNode {
  const overflow = $copyNode(this);
  this.insertAfter(overflow, restoreSelection);
  return overflow;
}

Please also add these mid-overflow cases to CharacterLimit.test.ts: Shift+Enter, Enter and Backspace with the caret inside the overflow rather than at its end. #9454 asked for them, and AGENTS.md puts caret and selection behaviour in browser tests.

Optional, non-blocking suggestions:

  • $hoistSelectionAfterTrailingLineBreak (packages/lexical-react/src/shared/useCharacterLimit.ts): no test fails when its call is removed. The selection already lands at (paragraph, 2) once $mergePrevious removes the merged-away overflow. Either add a case that needs the call or drop it.
  • A block decorator at the root past the limit, such as a horizontal rule, now gets wrapped in the inline OverflowNode. The core root transform then puts it inside a paragraph, and it stays as paragraph > horizontalrule after the text drops back under the limit. main already misbehaves on that path (an update loop), but skipping non-inline leaves in needsOverflowParent would avoid both problems.
  • packages/lexical/src/LexicalStructure.ts still describes OverflowNode as inline content "although its isInline() is false", so that comment needs updating. I would keep the isOverflowClass exemption, because allows() is what keeps an inline overflow legal directly under the root.
  • Nit: isInline(): true narrows the return type, so a subclass that overrides isInline(): boolean stops type-checking. Declaring isInline(): boolean avoids that.
  • Nit: AGENTS.md asks the test plan's Before and After sections to paste the real command output rather than describe it.

Comment thread packages/lexical-overflow/src/index.ts Resolved
Vedthakar and others added 2 commits November 16, 2026 18:48
… 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>
…r paragraph is inserted inside it

Now that OverflowNode is inline, $splitNodeAtPoint splits it through
insertNewAfter, which still delegated to the parent and so made a new
paragraph. Make the other half of the overflow, as LinkNode does.

Add browser tests for Shift+Enter, Enter and Backspace with the caret
inside the overflow, and drop $hoistSelectionAfterTrailingLineBreak,
which no test needed.

Co-authored-by: Ved Thakar <111605341+Vedthakar@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-authored-by: Ved Thakar <111605341+Vedthakar@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@Vedthakar
Vedthakar force-pushed the fix/9454-overflow-inline branch from 27c6429 to 6a98ab8 Compare November 16, 2026 23:58
@Vedthakar

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Fixed in the latest push, which also resolves the conflict with main:

  • Line break or paragraph inside the overflow: OverflowNode.insertNewAfter now makes the other half of the overflow with $copyNode, as LinkNode does.
  • Added the mid-overflow browser cases to CharacterLimit.test.ts (caret between 6 and 7 of 12345[67]): Shift+Enter, Enter and Backspace, for rich and plain text and both charsets. 8 of the 12 fail without the fix.
  • Dropped $hoistSelectionAfterTrailingLineBreak, since no test needed it; useCharacterLimit.ts is now unchanged from main.

I did not change the block-decorator-past-the-limit case, which already misbehaves on main. Added a changeset. Browser tests run in Chromium only.

— Ved Thakar

@rootnode-bot rootnode-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. Thanks for the quick turnaround on the last round. OverflowNode.insertNewAfter now splits the overflow itself, as LinkNode does, so Enter and Shift+Enter with the caret inside overflowed text behave as they do on main. The new mid-overflow browser cases cover that path. The reconciler change is a nice general fix too: any block that ends in an inline element whose last child is a LineBreakNode now gets the managed <br>, so a link ending in a line break draws its empty line as well. The new tests cover both halves of the fix. Without the insertNewAfter split the mid-overflow Shift+Enter and Enter cases fail, and without the reconciler change the end-of-overflow line-break cases fail.

All of the following are optional and non-blocking:

  • Changeset Verify: paragraph (.changeset/overflow-node-inline.md). This fix changes observable DOM and editing behaviour. Blocks that end in an inline element with a trailing line break gain a managed <br> in the rendered DOM, and OverflowNode.isInline() and insertNewAfter() now behave like an inline element's. The "Changesets" section of AGENTS.md and the "Behavior changes" section of .changeset/README.md ask for a Verify: paragraph in that case, for example:

    Verify: rendered-DOM snapshots of blocks that end in a link or other inline element whose last child is a line break, and code that calls insertNewAfter() or isInline() on an OverflowNode.
  • Backspace at the overflow boundary (packages/lexical-playground/src/__tests__/browser/CharacterLimit.test.ts). #9454's plan lists "backspace across the boundary". The new Backspace case puts the caret between 6 and 7, inside the overflow. A case with the caret between 5 and 6 would cover the boundary itself.

  • Block decorator past the limit. Understood that you left this out of scope because main already misbehaves there. For the record, with the wrapper now inline, a horizontal rule past the limit ends up as paragraph > horizontalrule and stays that way once the text drops back under the limit. Skipping non-inline leaves in needsOverflowParent (packages/lexical-react/src/shared/useCharacterLimit.ts) would avoid it, and a follow-up issue would do.

  • Stale comments. packages/lexical/src/LexicalStructure.ts (the isOverflowClass and INTERNAL_isInlineContent doc comments) and packages/lexical-y/src/internal/Structure.ts ($isHeldInline) still say that OverflowNode's isInline() is false. I'd keep the isOverflowNode exemption in allows(), though, because it is what keeps an inline overflow legal directly under the root when the structure is enforced.

  • Test plan. The "Commits and Pull Requests" section of AGENTS.md asks for the command you ran plus its real Before/After output, rather than a description of the results.

Automated review (maintainer link)

'lexical': patch
---

[fix] `OverflowNode` is an inline node, so text past the character limit stays on the same line, and a block that ends in an inline element whose last child is a line break shows its empty last line

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: this fix changes observable output (a managed <br> in the rendered DOM of blocks ending in an inline element with a trailing line break, and OverflowNode.isInline() / insertNewAfter() now behave as an inline element's), so the "Changesets" section of AGENTS.md and "Behavior changes" in .changeset/README.md ask for a Verify: paragraph, e.g.:

Verify: rendered-DOM snapshots of blocks that end in a link or other inline element whose last child is a line break, and code that calls insertNewAfter() or isInline() on an OverflowNode.

expect(getText()).toBe(isRichText ? '123456\n\nx7' : '123456\nx7');
});

test('Backspace deletes the character before the caret', async () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: this case deletes inside the overflow (caret between 6 and 7), and it passes with or without the insertNewAfter change. #9454's plan also lists "backspace across the boundary", so a case with the caret between 5 and 6 (the start of the overflow) would cover that too.

This branch was successfully deployed

2 active deployments
Preview – lexical — 6a98ab89 Deployed Nov 16, 2026 by vercel[bot]
Preview – lexical-playground — 6a98ab89 Deployed Nov 16, 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.

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