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 this issue. The bug is about
@tiptap/extension-tableversion 3.23.x whereHTMLAttributesconfigured on the Table extension are not applied to the rendered<table>element when using the defaultTableViewNodeView.Let me start by exploring the repository structure to understand the codebase and then locate the relevant files.
Assistant
Let me also check how the prosemirror-tables package handles TableView and how the
columnResizingplugin uses it:Assistant
Let me look at the full
addNodeViewand the extension options to understand how to properly fix the issue:Assistant
Now I can see the issue clearly. The problem is:
addNodeView()returns aTableViewNodeView whenresizable: false(the default)TableViewcreates the DOM manually but never appliesthis.options.HTMLAttributesfrom the Table extension- When
renderHTMLis bypassed by the NodeView, theHTMLAttributesare lost
The fix needs to:
- Pass the
HTMLAttributesoptions from the Table extension toTableView - Have
TableViewapply those attributes to the table element in its constructor
Let me also check how the prosemirror-tables
columnResizinguses TableView for the resizable case:Assistant
I see that the local
TableViewin the tiptap package is a custom implementation that extends/wraps the prosemirror-tablesTableView. The tiptap'sTableViewconstructor takes(node: ProseMirrorNode, cellMinWidth: number)but doesn't have access to the extension'sHTMLAttributesoptions.Now let me understand the full picture:
- The
addNodeView()method creates aTableViewinstance but doesn't passHTMLAttributesoptions TableViewdoesn't have any mechanism to applyHTMLAttributesto the table element
Let me look at the tests to understand the expected behavior:
- The
Assistant
Now I understand the structure. Let me create a plan:
Root cause:
TableViewintiptap/packages/extension-table/src/table/TableView.tsdoesn't receive or apply theHTMLAttributesoptions from the Table extension when creating the table DOM element.Solution:
- Modify
TableViewto accept anHTMLAttributesparameter - Modify
addNodeView()intable.tsto passthis.options.HTMLAttributestoTableView - Apply the
HTMLAttributesto the table element inTableView's constructor
However, there's a complication: The
TableViewclass is exported and might be used by thecolumnResizingplugin from prosemirror-tables. Let me check:- Modify
Assistant
I notice that
columnResizingfrom prosemirror-tables also usesView: this.options.View. The prosemirror-tablescolumnResizingplugin creates its own TableView instances. Let me check how the prosemirror-tables TableView handles HTMLAttributes:Assistant
Now I can see that both the prosemirror-tables
TableViewand tiptap'sTableViewdon't applyHTMLAttributes. The tiptap's customTableViewis used whenresizable: false(the default) throughaddNodeView().Looking at the type signature in
table.ts:View: (new (node: ProseMirrorNode, cellMinWidth: number, view: EditorView) => NodeView) | nullThe constructor takes
(node, cellMinWidth, view)but the currentTableViewonly uses(node, cellMinWidth). I need to modifyTableViewto acceptHTMLAttributesand apply them.The cleanest approach would be to:
- Add
HTMLAttributesas an optional parameter toTableView - Pass
HTMLAttributesfromaddNodeView() - Apply
HTMLAttributesin theTableViewconstructor
Let me also check how
mergeAttributesworks to apply attributes properly:- Add
Assistant
Now I understand everything. Let me implement the fix. I need to:
- Modify
TableViewto acceptHTMLAttributesand apply them to the table element - Modify
addNodeView()to passHTMLAttributestoTableView
Let me first create a test script to reproduce the bug:
- Modify
Assistant
Let me create a test script to reproduce the issue first:
Assistant
Let me run the existing tests first to understand the current state:
Assistant
Good, the existing tests pass. Now let me create a temporary test script to reproduce the bug:
Assistant
I need to create the test file in the repository directory. }
Assistant
Assistant
The previous command failed because the heredoc syntax wasn't properly handled. Let me try a different approach - I'll use the bash_terminal command properly with a single-line echo command or use a different method to create the file.
Assistant
Good, the file was created. Now let me run the test to confirm the bug exists.
Assistant
The test file needs to be inside the packages directory. Let me move it there.
Assistant
The test file has been moved to the correct location. Now let me run the test again to confirm the bug exists.
Assistant
The bug is confirmed. Both tests fail because
HTMLAttributesare not applied to the table element. Now let me implement the fix.The fix requires:
- Modify
TableViewto acceptHTMLAttributesand apply them to the table element - Modify
addNodeView()intable.tsto passHTMLAttributestoTableView
Let me open the TableView.ts file and make the changes:
- Modify
Assistant
Let me use the edit command to make the necessary changes to fix the bug.
Assistant
Now I need to fix the bug. The issue is that
TableViewdoesn't applyHTMLAttributesfrom the Table extension options. I'll modifyTableView.tsto accept and apply HTMLAttributes, and updateaddNodeView()intable.tsto pass them.Assistant
I see there are duplicate lines at the end of the file. Let me view the full file and fix it.
Assistant
I see there are duplicate lines at the end of the file. Let me fix that by removing the duplicate content.
Assistant
Now I need to update the
addNodeView()method intable.tsto passHTMLAttributestoTableView. Let me first view the current addNodeView method:Assistant
Now I need to update the
addNodeView()method intable.tsto passHTMLAttributestoTableView. Let me do that.Assistant
Let me verify the change was made correctly.
Assistant
The change was made. Now I also need to update the type signature for the
Viewoption inTableOptions. Let me check the current type definition.Assistant
I need to update the type signature for the
Viewoption to include the optionalhtmlAttributesparameter. Let me update line 88.Assistant
Let me verify all the changes are correct.
Assistant
Good, the type has been updated. Now let me run the test to verify the fix works.
Assistant
The error shows that
String(value)fails for object values. I need to handle non-primitive values more gracefully. Let me update theTableViewto only apply primitive values to attributes.Assistant
Let me run the test again to see if the fix works now.
Assistant
The tests are still failing. The error is back to the original assertion error - the attributes are not being applied. Let me check if the changes are actually being used. Maybe the test is using a compiled version or there's caching issue. Let me check what
editor.view.domlooks like in the test.Actually wait - the issue is that the tests are running but still failing. Let me check the current state of the TableView.ts file to make sure my changes are there, and also add some debugging to understand what's happening.
Let me also check if the
addNodeViewis returningnullfor some reason - ifViewis the defaultTableView, then it should be truthy and return the node view.Let me look at the test output more carefully. The error is the same as before - the class is not being applied. This suggests my code changes might not be taking effect, or there's something wrong with the logic.
Let me verify the TableView.ts file has the correct changes. </tool_call>
Assistant
Let me verify the current state of the files to ensure my changes are correct.
Assistant
The TableView.ts file looks correct. Let me check the table.ts file to see if the
addNodeViewmethod is correctly passing theHTMLAttributes.Assistant
Let me check the package exports and whether tests use source or dist files.
Assistant
The tests are importing from the dist folder. Let me check if there's a dist folder and how the tests resolve modules.
Assistant
Let me check how the tests resolve modules.
Assistant
The vitest config shows tests resolve to source files. Let me add a simple debugging test to understand what's happening:
Assistant
Let me run the debug test to see what's happening with the DOM.
Assistant
The debug output shows that the table element does NOT have the
class="my-custom-table"attribute. The table has no classes. This confirms the bug - theHTMLAttributesare not being applied.Looking at the output, I can see the TableView is being used (there's a
tableWrapperdiv), but the class is missing. The issue is that my code inaddNodeView()is passingthis.options.HTMLAttributesbut it seems like the value is an empty object{}by default.Wait, I see the issue now! Looking at the test output, the table element has
style="min-width: 25px;"but no class. ThehtmlAttributesparameter should be receiving{ class: 'my-custom-table' }but it's not being applied.Let me add more debugging to understand what's happening with the
htmlAttributesparameter:Assistant
Let me run this debug test to see if the htmlAttributes are being passed correctly.
Assistant
Let me add debugging directly to the TableView.ts file to see what's being passed:
Assistant
The user is asking me to check the table.ts file to see if the addNodeView method is correctly passing the HTMLAttributes. Let me look at the current state of the table.ts file.
Assistant
The code looks correct. The
addNodeViewmethod is passingthis.options.HTMLAttributesas the 4th argument to theViewconstructor. TheTableViewconstructor is also updated to accept and applyhtmlAttributes.Let me run the debug test to see what's actually being passed.
Assistant
Now I can see the problem! The
htmlAttributesparameter is receiving theEditorViewobject instead of the actual HTML attributes. Looking at the debug output:TableView constructor called with htmlAttributes: EditorView { ... }Assistant
Now let me remove the console.log debug statements from the TableView.ts file and run the test to see if the fix works.
Assistant
There are duplicate lines again. I need to fix the file by removing the duplicate code from line 116 onwards.
Assistant
The file looks clean now. Let me run the test to verify the fix works.
Assistant
The tests pass now! The fix is working. Let me also run the existing table tests to make sure I didn't break anything.
Assistant
All the existing tests pass. The only failure is my debug test file
debug2.spec.tswhich has an invalid import. Let me clean up the debug test files I created.Assistant
I need to use the bash_terminal function to clean up the debug test files.
Assistant
The debug test files were already removed. Let me verify the current state of the tests directory and run the existing tests.
Assistant
Good, the debug test files are already removed. Now let me run the existing tests to make sure everything still works.
Assistant
All 34 existing tests pass. Let me now review the final state of the changes I made to ensure everything is correct.
Assistant
Let me verify the current state of my changes and ensure everything is correct.
Assistant
The changes look good. Let me fix the missing newline at the end of the file and verify everything is correct.
Assistant
Let me verify the file now ends with a newline and run the tests one more time to confirm everything works.
Assistant
All 34 tests pass. Let me review my final changes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.