Skip to content

fix(extension-table): omit default colspan and rowspan when rendering cells - #8183

Open
rawsun007 wants to merge 2 commits into
ueberdosis:mainfrom
rawsun007:fix/table-default-spans
Open

fix(extension-table): omit default colspan and rowspan when rendering cells#8183
rawsun007 wants to merge 2 commits into
ueberdosis:mainfrom
rawsun007:fix/table-default-spans

Conversation

@rawsun007

@rawsun007 rawsun007 commented Aug 12, 2026

Copy link
Copy Markdown

Fixes #8176

colspan and rowspan default to 1 in TableCell and TableHeader, and both were rendered unconditionally, so every cell came out as:

<td colspan="1" rowspan="1"><p>Cell</p></td>

Besides the extra markup, it means parsing existing table HTML and serializing it back changes the document. (Input that spells out colspan="1" now loses the attribute instead of keeping it, which is the same cell either way.)

Added a small renderSpanAttribute helper that returns {} when the value is 1 (or missing) and used it for both attributes on TableCell and TableHeader. Cells that actually span still render the attribute. This matches how prosemirror-tables serializes them.

Only the rendering changes, the schema defaults and parsing are untouched.

Verification

New tests in tableCell.spec.ts cover both directions, plain cells and spanning cells:

Test Files  10 passed (10)
     Tests  94 passed (94)

Reverting just packages/extension-table/src turns them red, along with the two existing markup assertions this fix updates:

× should not serialize the default colspan and rowspan
  AssertionError: expected '<table style="min-width: 50px;"><colg…' to contain '<th><p>Name</p></th>'
× should keep colspan and rowspan when a cell actually spans
× generates correct markup for a 1x1 table
× generates correct markup for a 1x1 table with header

The two tableCommands.spec.ts expectations were pinned to the old colspan="1" rowspan="1" output and are updated here.

Full unit suite: 176 files, 1819 passed. oxlint and oxfmt --check clean on packages/extension-table.

Changeset included (patch).

… cells

Both attributes default to 1 in the schema and were rendered unconditionally,
so every cell serialized as <td colspan="1" rowspan="1">. That is redundant
markup, and it rewrites table HTML on a parse and serialize round trip.

Render them only when the value differs from 1, which is what
prosemirror-tables does.

Fixes ueberdosis#8176

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@rawsun007
rawsun007 requested a review from a team as a code owner August 12, 2026 08:16
@changeset-bot

changeset-bot Bot commented Aug 12, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c79b1fe

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 74 packages
Name Type
@tiptap/extension-table Patch
@tiptap/extension-table-cell Patch
@tiptap/extension-table-header Patch
@tiptap/extension-table-row Patch
@tiptap/core Patch
@tiptap/extension-audio Patch
@tiptap/extension-blockquote Patch
@tiptap/extension-bold Patch
@tiptap/extension-bubble-menu Patch
@tiptap/extension-bullet-list Patch
@tiptap/extension-code-block-lowlight Patch
@tiptap/extension-code-block Patch
@tiptap/extension-code Patch
@tiptap/extension-collaboration-caret Patch
@tiptap/extension-collaboration Patch
@tiptap/extension-color Patch
@tiptap/extension-details Patch
@tiptap/extension-document Patch
@tiptap/extension-drag-handle-react Patch
@tiptap/extension-drag-handle-vue-2 Patch
@tiptap/extension-drag-handle-vue-3 Patch
@tiptap/extension-drag-handle Patch
@tiptap/extension-emoji Patch
@tiptap/extension-file-handler Patch
@tiptap/extension-find-and-replace Patch
@tiptap/extension-floating-menu Patch
@tiptap/extension-font-family Patch
@tiptap/extension-hard-break Patch
@tiptap/extension-heading Patch
@tiptap/extension-highlight Patch
@tiptap/extension-horizontal-rule Patch
@tiptap/extension-image Patch
@tiptap/extension-invisible-characters Patch
@tiptap/extension-italic Patch
@tiptap/extension-link Patch
@tiptap/extension-list Patch
@tiptap/extension-mathematics Patch
@tiptap/extension-mention Patch
@tiptap/extension-node-range Patch
@tiptap/extension-ordered-list Patch
@tiptap/extension-paragraph Patch
@tiptap/extension-ruby-text Patch
@tiptap/extension-strike Patch
@tiptap/extension-subscript Patch
@tiptap/extension-superscript Patch
@tiptap/extension-table-of-contents Patch
@tiptap/extension-text-align Patch
@tiptap/extension-text-style Patch
@tiptap/extension-text Patch
@tiptap/extension-twitch Patch
@tiptap/extension-typography Patch
@tiptap/extension-underline Patch
@tiptap/extension-unique-id Patch
@tiptap/extension-youtube Patch
@tiptap/extensions Patch
@tiptap/html Patch
@tiptap/markdown Patch
@tiptap/pm Patch
@tiptap/react Patch
@tiptap/starter-kit Patch
@tiptap/static-renderer Patch
@tiptap/suggestion Patch
@tiptap/vue-2 Patch
@tiptap/vue-3 Patch
@tiptap/extension-character-count Patch
@tiptap/extension-dropcursor Patch
@tiptap/extension-focus Patch
@tiptap/extension-gapcursor Patch
@tiptap/extension-history Patch
@tiptap/extension-list-item Patch
@tiptap/extension-list-keymap Patch
@tiptap/extension-placeholder Patch
@tiptap/extension-task-item Patch
@tiptap/extension-task-list Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify

netlify Bot commented Aug 12, 2026

Copy link
Copy Markdown

Deploy Preview for tiptap-embed ready!

Name Link
🔨 Latest commit c79b1fe
🔍 Latest deploy log https://app.netlify.com/projects/tiptap-embed/deploys/6a7c305db883e300083d03d3
😎 Deploy Preview https://deploy-preview-8183--tiptap-embed.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: b45c3701-582f-45ea-be75-b0a2d7c99a38

📥 Commits

Reviewing files that changed from the base of the PR and between d5b734a and c79b1fe.

📒 Files selected for processing (1)
  • .changeset/omit-default-table-cell-spans.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • .changeset/omit-default-table-cell-spans.md

📝 Walkthrough

Summary

  • Omit default colspan="1" and rowspan="1" attributes from rendered table cells and headers.
  • Keep these attributes when cells span multiple rows or columns.
  • Add tests and update table markup expectations.
  • Add a patch release changeset.

Walkthrough

Table cell and header serialization now omits default colspan="1" and rowspan="1" attributes. Non-default span values remain serialized. Tests and a patch changeset document the behavior.

Changes

Table span serialization

Layer / File(s) Summary
Conditional span renderer
packages/extension-table/src/utils/renderSpanAttribute.ts
Adds renderSpanAttribute, which omits missing or default span values and preserves non-default values.
Table serialization integration
packages/extension-table/src/cell/table-cell.ts, packages/extension-table/src/header/table-header.ts, packages/extension-table/__tests__/*, .changeset/omit-default-table-cell-spans.md
Applies conditional rendering to table cells and headers. Updates expected HTML, adds coverage for default and non-default spans, and documents the patch.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • ueberdosis/tiptap#8153: Both PRs modify handling of table colspan and rowspan attributes, but use different code paths.
  • ueberdosis/tiptap#8177: Both PRs omit default table cell and header span attributes while preserving non-default spans.

Suggested labels: area: core, complexity: medium, impact: medium

Suggested reviewers: bdbch

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The implementation meets issue #8176 by omitting default span attributes while preserving non-default spans for cells and headers.
Out of Scope Changes check ✅ Passed The changes are limited to the requested rendering helper, cell and header integration, tests, expectations, and patch changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Title check ✅ Passed The title clearly summarizes the main change: omitting default colspan and rowspan attributes when rendering table cells.
Description check ✅ Passed The description explains the issue, implementation, verification steps, tests, lint results, and changeset, and it includes the required checklist sections.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot added area: core Core editor engine and ProseMirror integration complexity: medium Moderate change, possibly multiple files impact: medium Affects some users or workflows labels Aug 12, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.changeset/omit-default-table-cell-spans.md:
- Line 5: Rewrite the changeset body as one short, accurate sentence describing
that table cells and headers omit default colspan="1" and rowspan="1" attributes
when serialized. Remove the incorrect claim that existing markup remains
unchanged, and preserve the required changeset frontmatter.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 566764a5-90e2-4a24-978a-8274604e9a7f

📥 Commits

Reviewing files that changed from the base of the PR and between 3c929ad and d5b734a.

📒 Files selected for processing (6)
  • .changeset/omit-default-table-cell-spans.md
  • packages/extension-table/__tests__/tableCell.spec.ts
  • packages/extension-table/__tests__/tableCommands.spec.ts
  • packages/extension-table/src/cell/table-cell.ts
  • packages/extension-table/src/header/table-header.ts
  • packages/extension-table/src/utils/renderSpanAttribute.ts

Comment thread .changeset/omit-default-table-cell-spans.md Outdated
The old text claimed a parse and serialize round trip leaves markup
unchanged, which is not true for input that spells out colspan="1".

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Core editor engine and ProseMirror integration complexity: medium Moderate change, possibly multiple files impact: medium Affects some users or workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TableCell and TableHeader serialize default colspan="1" and rowspan="1" attributes

1 participant