fix(editor): paste markdown tables that contain blank cells - #1484
Conversation
Pasting a markdown table with any blank cell inserted nothing at all. The table did not appear, and no error surfaced to the user. A blank cell renders as <td></td>. The ProseMirror tableCell schema requires at least one block child, so it rejects the document with "Invalid content for node tableCell: <>" and insertContent throws. The throw aborts the whole paste, which is why a single blank cell anywhere loses the entire table rather than leaving a gap in it. parse-all-extensions-to-doc already does exactly this for blockquotes, which fail the same schema check for the same reason. Table cells needed the same treatment: give an empty cell one empty paragraph. Verified against a real 29-row table with 16 blank cells. On develop the paste throws and nothing is inserted; with this change all 29 rows land, the blank cells render as empty cells, and the surrounding content is unchanged. Regression specs cover blank cells leading, trailing, in the middle, a fully blank row, a blank header cell and several blank rows, plus the unaffected all-filled case.
|
Warning Review limit reached
Next review available in: 57 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Summary by QodoFix paste for markdown tables with blank cells in the TipTap editor
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo
1.
|
Code Review by Qodo
1.
|
Review follow-up. The blank-cell guard also matches cells holding only whitespace or , which the browser already renders as one paragraph. Appending left that invisible text in place alongside the new empty paragraph, so such a cell rendered as two paragraphs and roughly doubled in height. Only a genuinely empty cell was correct. Measured before this commit: a cell containing just produced <td> <p></p></td> and two paragraphs in the editor, against one on develop. Same for a spaces-only cell. Since the guard has already established the content is invisible, clear it and insert a single empty paragraph. All three blank shapes now normalise to <td><p></p></td> and render as one paragraph. Adds coverage for , plain spaces, a tab and mixed invisible content, an editor-level assertion that such a cell renders as exactly one paragraph, and a case confirming cells with real content are untouched. Also annotates the spec helper and the it.each parameters per review.
|
Confirmed and fixed in 73525ff. Reproduced exactly as described.
Clearing the cell before inserting the paragraph, as suggested, since the guard has already established the content is invisible. Added coverage for One related note, deliberately not changed here. The blockquote guard directly above uses the same predicate and the same append, so |
Pasting a markdown table that contains any blank cell inserts nothing at all. The table does not appear, and no error reaches the user.
Reported from a real case: a 29-row table with blank cells in one column simply would not paste into the publish editor.
Cause
A blank cell renders as
<td></td>. The ProseMirrortableCellschema requires at least one block child, so it rejects the document:insertContentthrows, and the throw aborts the entire paste. That is why one blank cell anywhere loses the whole table rather than leaving a gap in it.Minimal reproduction, all through the real clipboard path:
| A | B |/| 1 | 2 || A | B |/| 1 | |Fix
parse-all-extensions-to-docalready solves exactly this for blockquotes, which fail the same schema check for the same reason:// Ensure empty blockquotes have at least one paragraph to satisfy ProseMirror schema.Table cells needed the same treatment. An empty
<td>or<th>gets one empty paragraph, so the cell renders blank and the document validates.Verification against the reported case
A real 29-row table containing 16 blank cells, pasted through
simpleMarkdownToHTMLthenparseAllExtensionsToDoctheninsertContent:Testing
empty-table-cell-paste.spec.ts: blank cell leading, trailing, in the middle, a fully blank row, a blank header cell, several blank rows, the unaffected all-filled case, and a direct assertion that a blank cell becomes<td><p></p></td>rather than being dropped.Note
This supersedes #1482, which was closed. That PR diagnosed the same report as a Turndown serialization problem, which turned out not to exist: the existing custom
tablerule already preserves tables through the editor losslessly. The actual failure is upstream of serialization, at paste time, and this is a much smaller change.