ISSUE DESCRIPTION [Bug]: extension-table 3.23 TableView NodeView ignores HTMLAttributes…
- User
ISSUE DESCRIPTION
[Bug]: extension-table 3.23 TableView NodeView ignores HTMLAttributes (regression from 3.22.4)
Affected Packages
@tiptap/extension-table
Version(s)
3.23.1 (also 3.23.2, 3.23.4)
Bug Description
Summary
In
@tiptap/extension-table3.23.x, configuring the Table extension withHTMLAttributesno longer applies those attributes to the rendered<table>element whenresizable: false(the default). The class/attributes silently disappear from the DOM.This is a regression from 3.22.4, where the same configuration worked correctly.
TableViewexisted byte-identical in 3.22.4, but the Table extension had noaddNodeView()method, so ProseMirror always fell back to the schema'srenderHTML. 3.23 addedaddNodeView()that wires the NodeView in, bypassingrenderHTML.Reproduction
import { Editor } from '@tiptap/core'; import StarterKit from '@tiptap/starter-kit'; import { Table, TableRow, TableHeader, TableCell } from '@tiptap/extension-table'; new Editor({ extensions: [ StarterKit, Table.configure({ HTMLAttributes: { class: 'my-custom-table' } }), TableRow, TableHeader, TableCell ], content: '<table><tbody><tr><td>cell</td></tr></tbody></table>' });Inspect the rendered DOM. The
<table>element has noclass="my-custom-table".Browser Used
Chrome
Code Example URL
https://codesandbox.io/p/devbox/laughing-glade-n4qh4r
Expected Behavior
The
<table>element should render withclass="my-custom-table"(the documented Table.configure HTMLAttributes behavior), regardless of theresizablesetting.A minimal fix would have
TableViewapplythis.options.HTMLAttributesto the inner<table>element in its constructor.Additional Context (Optional)
Root cause
3.23 introduced
addNodeView()on the Table extension (extension-tabledist/index.jsaround line 645):addNodeView() { const isResizable = this.options.resizable && this.editor.isEditable; const View = this.options.View; if (isResizable || !View) { return null; } return ({ node, view }) => new View(node, this.options.cellMinWidth, view); } Assistant
Let me understand the issue:
- In
@tiptap/extension-table3.23.x, configuring Table withHTMLAttributesno longer applies those attributes to the rendered<table>element whenresizable: false(the default). - The root cause is that
TableViewbuilds the DOM manually and never readsthis.options.HTMLAttributes. - The schema-level
renderHTML(which does callmergeAttributes(this.options.HTMLAttributes, HTMLAttributes, ...)) is bypassed whenever the NodeView is active.
The fix should have
TableViewapplythis.options.HTMLAttributesto the inner<table>element in its constructor.Let me explore the repository structure first.
- In
Assistant
Let me look at the key files:
TableView.tsandtable.ts.Assistant
I need to make one tool call at a time. Let me look at the files one at a time.
Assistant
Now let's look at the table extension:
Assistant
Let me check the
columnResizingplugin to understand how it uses theViewparameterAssistant
Let me check the columnResizing plugin in the pm package.
Assistant
Let me check the prosemirror-tables library to see how
columnResizingusesView.Assistant
Let me look at the columnResizing function in prosemirror-tables to see how it uses View:
Assistant
Now I have a clear understanding of the issue. Let me implement the fix. The
TableViewconstructor needs to accept and applyHTMLAttributes, andaddNodeViewneeds to pass themAssistant
Now let me see the rest of the file:
Assistant
Now let me check the
mergeAttributesutility to understand the proper way to apply HTMLAttributesAssistant
Let me look at the mergeAttributes function.
Assistant
Now I have a clear picture. Let me implement the fix:
- Modify
TableViewconstructor to acceptHTMLAttributesand apply them to the inner<table>element - Update
addNodeViewintable.tsto passHTMLAttributes
First, let me edit `TableView
- Modify
Assistant
Wait, I need to properly handle the merging of attributes, particularly for
classandstyle. Let me use themergeAttributesutility from core. Let me update the implementationAssistant
Now let me update
addNodeViewintable.tsto passthis.options.HTMLAttributesAssistant
Let me find the
addNodeViewmethodAssistant
Let me look at that section.
Assistant
Now let me update
addNodeViewto passHTMLAttributesAssistant
Now let me run the existing tests to make sure nothing
Assistant
Let me run the table tests to verify the changes don't break anything
Assistant
All tests pass. Let me also look at the colgroupUpdate spec to see if it tests the Table
Assistant
Good, all tests pass. Now let me create a quick reproduction script to verify the fix actually works
Assistant
Let me use vitest instead since it has jsdom configured
Assistant
Let me place the test in the right location
Assistant
The
resizable: falsecase passes. Theresizable: truecase fails becausecolumnResizing(from prosemirror-tables) creates the node view without passingHTMLAttributes. That's a separate issue as noted in the description.Let me clean up the test file (not supposed to add tests) and verify the final state
Assistant
Let me run the existing tests again to make sure everything still passes
Assistant
All 34 tests pass. Let me review the final state of both files
Assistant
The changes look correct. Let me verify the full files look right.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.