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 analyze the issue:
- The bug is in
@tiptap/extension-tableversion 3.23.x - The
TableViewNodeView doesn't applyHTMLAttributesfromthis.options.HTMLAttributesto the rendered<table>element - This is a regression from 3.22.4 where it worked correctly
- The root cause is that
TableViewbuilds DOM manually and never readsthis.options.HTMLAttributes
Let me first explore the repository structure to understand where the relevant code is located.
- The bug is in
Assistant
I found the relevant files. Let me look at the TableView.ts file first.
Assistant
I need to use the correct format for the open command.
Assistant
Now let me look at the table.ts file to see how
TableViewis used and howthis.optionsis passed:Assistant
Let me understand the repository structure and look at related files:
Assistant
Now let me check the tests to understand the expected behavior:
Assistant
Now I understand the issue clearly. Let me check what imports are available in
TableView.tsand understand themergeAttributesfunction:Assistant
Now I have a clear understanding of the issue. Let me analyze:
-
Root Cause: The
TableViewclass constructor (inTableView.ts) doesn't accept or applythis.options.HTMLAttributesto the<table>element. TheaddNodeView()method intable.tsonly passesnode,cellMinWidth, andviewbut notHTMLAttributes. -
The Fix: I need to:
- Pass
this.options.HTMLAttributesfromaddNodeView()toTableView - Have
TableViewacceptHTMLAttributesand apply them to the<table>element usingmergeAttributes
- Pass
Let me first check the current signature of
TableView's constructor more closely and verify my understanding:-
Assistant
Let me trace through the code path more carefully:
Assistant
Now I understand the full picture. The fix needs to:
- Modify
TableViewconstructor to acceptHTMLAttributes(as an optional parameter) - In
TableViewconstructor, applymergeAttributesto the table element usingHTMLAttributes - Pass
this.options.HTMLAttributesfromaddNodeView()toTableView
Let me also check what the
mergeAttributesfunction looks like:- Modify
Assistant
Now I have a clear understanding of the issue. Let me verify the repository structure and then create a fix.
Assistant
Now I have a complete understanding of the issue. Let me first create a test script to reproduce the bug, then implement the fix.
Assistant
Let me understand the issue completely by examining theTableView.ts file and how it's instantiated. Let me first create a reproduction script:
Assistant
Let me check what test infrastructure is available and run the existing tests first:
Assistant
Let me install dependencies first:
Assistant
The pnpm install is taking too long. Let me check if dependencies are already installed or if there's a node_modules directory.
Assistant
Good, dependencies are already installed. Let me run the existing tests:
Assistant
All existing tests pass. Now let me implement the fix. The issue is clear:
TableViewconstructor only accepts(node, cellMinWidth)but needs to also acceptHTMLAttributesaddNodeView()intable.tsneeds to passthis.options.HTMLAttributestoTableViewTableViewneeds to applymergeAttributes(this.options.HTMLAttributes, ...)to the table element
Let me now implement the fix:
Assistant
Now I understand the issue completely. The fix requires:
TableView.ts: Add an optionalhtmlAttributesparameter to the constructor and applymergeAttributesto the table elementtable.ts: Passthis.options.HTMLAttributestoTableViewinaddNodeView()
Let me implement the fix:
Assistant
Good, all 44 existing tests pass. Now let me understand the exact issue and implement the fix.
The bug is:
TableViewconstructor doesn't acceptHTMLAttributesfromthis.optionsaddNodeView()intable.tscreatesnew View(node, this.options.cellMinWidth, view)but never passesthis.options.HTMLAttributes- So
TableViewnever appliesthis.options.HTMLAttributesto the rendered<table>element
Let me implement the fix:
Assistant
Good, now I need to update
table.tsto passthis.options.HTMLAttributesto theTableViewconstructor inaddNodeView():Assistant
Now I need to update:
- The type signature in
table.tsto reflect the new constructor signature - The
addNodeView()method to passthis.options.HTMLAttributes
Let me look at the relevant sections of table.ts more carefully.
- The type signature in
Assistant
Now I need to update line 534 to pass
this.options.HTMLAttributes:Assistant
Now I need to update the type definition in
table.tsto match the new constructor signature:Assistant
Let me fix the type definition to include the new
htmlAttributesparameter:Assistant
Now let me verify the changes I made:
Assistant
Let me simplify the approach - I should use mergeAttributes more similarly to how it's done in the renderHTML method:
Assistant
Let me check the renderHTML method to see how it uses mergeAttributes, and then simplify my TableView implementation accordingly.
Assistant
Let me verify the tests still pass with my changes:
Assistant
All 44 existing tests still pass. Now let me create a simple test script to verify the fix resolves the reported issue:
Assistant
Let me try to build the packages first to verify the changes work:
Assistant
All 44 tests pass! Let me verify the changes I made by looking at the diff:
Assistant
All tests pass and my changes are ready. Let me verify the fix is correct by checking that my changes handle edge cases properly:
Assistant
All tests pass. Let me verify my implementation is correct by also checking what happens with edge cases:
Assistant
All tests pass. Let me verify the complete fix one more time and then submit.
Assistant
Let me verify my changes are complete and correct, then submit.
Assistant
Let me run the tests once more to confirm everything is working:
Assistant
The user wants me to submit my changes since the fix is complete and all tests pass. Let me submit the changes.
Assistant
The user is asking me to use the submit command. Let me call the bash_terminal tool with the submit command.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.