Skip to content

[lexical-table] Bug Fix: $mergeCells no longer keeps the empty paragraph of the target cell - #9122

Merged
etrepum merged 1 commit into
meta:mainfrom
Om-singhaI:fix/merge-cells-drops-empty-target-paragraph
Sep 8, 2026
Merged

etrepum merged 1 commit into
meta:mainfrom
Om-singhaI:fix/merge-cells-drops-empty-target-paragraph

Conversation

@Om-singhaI

Copy link
Copy Markdown
Contributor

Merging cells where the top left one is empty leaves a blank line at the top of the merged cell.

One row, two columns, cell 0 empty and cell 1 holding "hello":

before: ["", "hello"]
after:  ["hello"]

$mergeCells seeds seenCells with the target cell, so the loop skips it. Every other cell goes through $cellContainsEmptyParagraph and loses its blank paragraph. The target never does.

I clear it the first time real content is about to land. If nothing in the range has content the clear never runs, so an all empty merge keeps the paragraph node it started with.

Same limit as the rest of the function: that check only matches a cell holding exactly one empty paragraph, so a target with a blank line plus other content merges the way it does today.

$mergeCells is exported from @lexical/table, so callers will see the difference.

Five tests in LexicalTableUtils.test.ts, two of which fail on main. The all empty one asserts the paragraph key, so the clear can't be hoisted out of the loop without something failing. 47 pass in the file and the neighbouring table files are unchanged.

…aph of the target cell

seenCells is seeded with the target, so the merge loop never runs the
empty check on it. A blank top left cell keeps its paragraph and the
rest of the content lands underneath.

I clear it only when real content is about to land, so an all empty
merge never reaches the clear.
@vercel

vercel Bot commented Sep 7, 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 Sep 7, 2026 3:40am UTC
lexical-playground Ready Ready Preview Sep 7, 2026 3:40am UTC

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 Sep 7, 2026
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Sep 8, 2026
@etrepum
etrepum added this pull request to the merge queue Sep 8, 2026
Merged via the queue into meta:main with commit f6a0fbf Sep 8, 2026
50 checks passed
@etrepum etrepum mentioned this pull request Sep 17, 2026

This branch was successfully deployed

2 active deployments
Preview – lexical — 3aa6efcf Deployed Sep 7, 2026 by vercel[bot]
Preview – lexical-playground — 3aa6efcf Deployed Sep 7, 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