Skip to content

[lexical-list] Bug Fix: Treat whitespace-only list items as empty when pressing Enter#8068

Merged
etrepum merged 7 commits intofacebook:mainfrom
mike-atticus:ms/empty-list-item-behaviour
Jan 11, 2026
Merged

[lexical-list] Bug Fix: Treat whitespace-only list items as empty when pressing Enter#8068
etrepum merged 7 commits intofacebook:mainfrom
mike-atticus:ms/empty-list-item-behaviour

Conversation

@mike-atticus
Copy link
Copy Markdown
Contributor

Description

Current behavior:
When a list item contains only whitespace (e.g., a trailing space that was carried over when pressing Enter mid-line), pressing Enter does not exit the list. The user perceives the list item as empty and expects pressing Enter to exit the list, but because it contains an invisible space character, Lexical treats it as non-empty and creates new list items indefinitely. This can lead to a frustrating impression the automatic list behaviour is broken.

Reproduction steps:

  1. Create a bullet list item with text followed by a trailing space: "Some text "
  2. Position cursor before the trailing space: "Some text| "
  3. Press Enter - the trailing space moves to the new list item
  4. The new list item appears empty but contains the space
  5. Press Enter again - instead of exiting the list, another list item is created
  6. This continues indefinitely

Changes in this PR:

  • Modified $handleListInsertParagraph() in formatList.ts to detect whitespace-only list items
  • A list item is now treated as empty if:
    • All its children are TextNodes, AND
    • The combined text content is only whitespace
  • Added unit tests covering: empty list items, whitespace-only list items, non-whitespace content, and decorator nodes

Test plan

Before

CleanShot.2026-01-08.at.11.38.25.mp4

After

CleanShot.2026-01-08.at.11.40.28.mp4

Unit tests added:

  • exits list when list item is completely empty
  • exits list when list item contains only whitespace
  • extends list when list item contains non-whitespace content
  • extends list when list item contains a decorator node

@vercel
Copy link
Copy Markdown

vercel bot commented Jan 8, 2026

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

Project Deployment Review Updated (UTC)
lexical Ready Ready Preview, Comment Jan 11, 2026 7:09pm
lexical-playground Ready Ready Preview, Comment Jan 11, 2026 7:09pm

@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 Jan 8, 2026
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Jan 8, 2026
@etrepum etrepum added this pull request to the merge queue Jan 11, 2026
Merged via the queue into facebook:main with commit 7d38868 Jan 11, 2026
36 checks passed
@etrepum etrepum mentioned this pull request Jan 31, 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. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants