From 764101bc68d38ef206767ba8cce7df6d7a7269db Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Thu, 16 Jan 2025 20:11:37 +0530 Subject: [PATCH 1/2] [lexical-table] Bug Fix: Prevent error if pasted table has empty row --- .../html/TablesHTMLCopyAndPaste.spec.mjs | 54 +++++++++++++++++++ .../lexical-table/src/LexicalTableUtils.ts | 3 ++ 2 files changed, 57 insertions(+) diff --git a/packages/lexical-playground/__tests__/e2e/CopyAndPaste/html/TablesHTMLCopyAndPaste.spec.mjs b/packages/lexical-playground/__tests__/e2e/CopyAndPaste/html/TablesHTMLCopyAndPaste.spec.mjs index c0ef411ca34..bf61c484ccc 100644 --- a/packages/lexical-playground/__tests__/e2e/CopyAndPaste/html/TablesHTMLCopyAndPaste.spec.mjs +++ b/packages/lexical-playground/__tests__/e2e/CopyAndPaste/html/TablesHTMLCopyAndPaste.spec.mjs @@ -818,4 +818,58 @@ test.describe('HTML Tables CopyAndPaste', () => { `, ); }); + + test('Copy + paste table with empty row', async ({ + page, + isPlainText, + isCollab, + }) => { + test.skip(isPlainText); + + await focusEditor(page); + + const clipboard = { + 'text/html': html` + + + + +
1
2
+ `, + }; + + await pasteFromClipboard(page, clipboard); + + await assertHTML( + page, + html` + + + + + + + + + + + + + +
+

+ 1 +

+
+

+
+

+
+

+ 2 +

+
+ `, + ); + }); }); diff --git a/packages/lexical-table/src/LexicalTableUtils.ts b/packages/lexical-table/src/LexicalTableUtils.ts index 84e4ab3f5a7..ec5c9ac170d 100644 --- a/packages/lexical-table/src/LexicalTableUtils.ts +++ b/packages/lexical-table/src/LexicalTableUtils.ts @@ -856,6 +856,9 @@ export function $computeTableMapSkipCellCheck( $isTableRowNode(row), 'Expected TableNode children to be TableRowNode', ); + if (row.getChildrenSize() === 0) { + tableMap[rowIdx] = []; + } for ( let cell = row.getFirstChild(), colIdx = 0; cell != null; From 5c5132bdf4f9fcd93a52df32637e14ccf18b80c8 Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Thu, 16 Jan 2025 22:31:56 +0530 Subject: [PATCH 2/2] Change initialization logic --- packages/lexical-table/src/LexicalTableUtils.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/lexical-table/src/LexicalTableUtils.ts b/packages/lexical-table/src/LexicalTableUtils.ts index ec5c9ac170d..b3d148ed238 100644 --- a/packages/lexical-table/src/LexicalTableUtils.ts +++ b/packages/lexical-table/src/LexicalTableUtils.ts @@ -856,9 +856,7 @@ export function $computeTableMapSkipCellCheck( $isTableRowNode(row), 'Expected TableNode children to be TableRowNode', ); - if (row.getChildrenSize() === 0) { - tableMap[rowIdx] = []; - } + const startMapRow = getMapRow(rowIdx); for ( let cell = row.getFirstChild(), colIdx = 0; cell != null; @@ -869,7 +867,6 @@ export function $computeTableMapSkipCellCheck( 'Expected TableRowNode children to be TableCellNode', ); // Skip past any columns that were merged from a higher row - const startMapRow = getMapRow(rowIdx); while (startMapRow[colIdx] !== undefined) { colIdx++; }