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
I'll start by exploring the repository to understand the structure and locate the relevant files. Let's first check the current directory.
- Assistant
Let me explore the repository structure to find the table extension code.
- Assistant
Let me look at the TableView.ts and table.ts files to understand the current implementation.
- Assistant
Now let me look at the table.ts file to see the addNodeView method.
- Assistant
Let me see the full table.ts file, particularly the
addNodeView()andrenderHTML()methods: - Assistant
Let me see the addNodeView and renderHTML methods:
- Assistant
Now I understand the issue. Let me look at the
renderHTMLmethod to see how it handles HTMLAttributes, and then understand how to fix theTableViewto also apply them. - Assistant
Now I understand the issue. The
TableViewconstructor doesn't applyHTMLAttributesfrom the options. TheaddNodeView()method creates a newViewinstance with onlynode,cellMinWidth, andviewarguments, but doesn't passHTMLAttributes. Let me check if there's amergeAttributesutility available: - Assistant
Let me check how other NodeViews in the codebase handle HTMLAttributes:
- Assistant
Let me check the git log to understand the recent changes:
- Assistant
Let me check the exact
addNodeViewimplementation and see how to passHTMLAttributesproperly: - Assistant
Now let me look at the tests for the table extension to understand the testing patterns:
- Assistant
Let me look at the tests directory for extension-table:
- Assistant
Now I have a clear understanding of the issue. The
TableViewclass creates the<table>element in its constructor but never appliesHTMLAttributesfrom the extension options. When theaddNodeView()method returns aNodeViewusingTableView, therenderHTMLmethod (which does applyHTMLAttributes) is bypassed.The fix needs to:
- Update the
TableViewconstructor to acceptHTMLAttributesand apply them to the<table>element - Update the
addNodeView()method to passHTMLAttributesto theViewconstructor
Let me first create a script to reproduce the issue:
- Update the
- Assistant
Now I understand the issue completely. The
TableViewclass needs to:- Accept
HTMLAttributesas a constructor parameter - Apply those attributes to the
<table>element
And the
addNodeView()method needs to passthis.options.HTMLAttributesto the View constructor.Let me also check if there's a
mergeAttributesutility that we can import in the TableView: - Accept
- Assistant
Let me check how other NodeViews apply attributes:
- Assistant
Now let me check if there's a utility for setting attributes on DOM elements:
- Assistant
Let me look at how other NodeViews in the codebase apply HTMLAttributes:
- Assistant
Let me look at how
mergeAttributesworks to understand how to apply HTMLAttributes: - Assistant
Now I understand the issue and the solution. Let me implement the fix:
- Modify
TableViewto accept and applyHTMLAttributesin its constructor - Modify
addNodeView()to passthis.options.HTMLAttributesto the View constructor
Let me also check how
mergeAttributesis used elsewhere to apply attributes to DOM elements: - Modify
- Assistant
Now I understand the issue fully. Let me implement the fix. I need to:
- Modify
TableViewto acceptHTMLAttributesand apply them to the<table>element - Modify
addNodeView()to passthis.options.HTMLAttributesto the View constructor
Let me first check if there's a utility for applying attributes to DOM elements:
- Modify
- Assistant
Now I understand the issue clearly. Let me implement the fix. I need to modify
TableViewto acceptHTMLAttributesand apply them to the<table>element, and modifyaddNodeView()to passHTMLAttributesto the View constructor.Let me first look at the full
TableViewfile to understand its structure: - Assistant
Now I understand the full picture. Let me implement the fix. I need to:
- Modify
TableViewto acceptHTMLAttributesand apply them to the<table>element - Modify
addNodeView()to passthis.options.HTMLAttributesto the View constructor
Let me first create a reproduction script to verify the issue:
- Modify
- Assistant
Let me look at the existing colgroupUpdate spec to understand the test pattern:
- Assistant
- Assistant
Now I have a clear understanding of the issue and the solution. Let me implement the fix. The
TableViewconstructor needs to acceptHTMLAttributesand apply them to the<table>element, andaddNodeView()needs to passthis.options.HTMLAttributesto theViewconstructor. - Assistant
Now I have a clear understanding of the issue and the solution. Let me implement the fix:
- Modify
TableViewto acceptHTMLAttributesand apply them to the<table>element - Modify
addNodeView()to passthis.options.HTMLAttributesto the View constructor
- Modify
- Assistant
Now let me modify the
TableViewconstructor to accept and applyHTMLAttributes: - Assistant
I see there's a duplicate closing brace on line 119. Let me fix that:
- Assistant
I see there's an extra closing brace on line 119. Let me remove it:
- Assistant
The edit command needs to have the EOF marker at the end properly. Let me try a different approach.
- Assistant
Let me verify the file looks correct now:
- Assistant
Now I need to update the
addNodeView()method intable.tsto passthis.options.HTMLAttributesto the View constructor: - Assistant
Now I need to update the
Viewtype inTableOptionsto accept the additionalHTMLAttributesparameter. Let me check the type definition: - Assistant
Now I need to update the
Viewtype inTableOptionsto accept the additionalHTMLAttributesparameter: - Assistant
Good. Now let me also check if the
columnResizingplugin needs to be updated to passHTMLAttributesto the View whenresizable: true: - Assistant
Now I need to also handle the resizable case. When
resizable: true, thecolumnResizingplugin uses theViewoption to create NodeViews. Let me check how that works: - Assistant
The
columnResizingplugin fromprosemirror-tablesalso creates a NodeView with theViewoption. Whenresizable: true, the columnResizing plugin's NodeView is used instead. That's handled by the plugin itself. Looking at theaddProseMirrorPlugins, when resizable is true, the View is passed tocolumnResizing:columnResizing({ handleWidth: this.options.handleWidth, cellMinWidth: this.options.cellMinWidth, defaultCellMinWidth: this.options.cellMinWidth, View: this.options.View, lastColumnResizable: this.options.lastColumnResizable, })The
columnResizingplugin fromprosemirror-tablescallsnew View(node, cellMinWidth, view)too (without HTMLAttributes). So for the resizable case, the same issue exists. However, the issue description mentions this is specifically about theaddNodeView()method for the non-resizable case. - Assistant
Let me check how
columnResizinguses the View parameter: - Assistant
I see! The
columnResizingplugin fromprosemirror-tablesalso creates a NodeView usingnew View(node, defaultCellMinWidth, view)without passingHTMLAttributes. This means the resizable case also has the same issue.To fix this properly for both cases, I should also handle the resizable case. The best approach would be to create a wrapper View class that passes HTMLAttributes.
However, looking at the issue description more carefully:
A minimal fix would have
TableViewapplythis.options.HTMLAttributesto the inner<table>element in its constructor.The issue description suggests a minimal fix. Let me also handle the resizable case by creating a wrapper View class that passes HTMLAttributes.
Actually, let me think about this more carefully. The
columnResizingplugin fromprosemirror-tablescreates its own NodeView. If we want to fix the resizable case too, we need to either:- Create a wrapper View class that passes HTMLAttributes
- Or modify the TableView to accept HTMLAttributes via a different mechanism
Actually, the cleanest approach is to create a wrapper View class in
addProseMirrorPluginsthat passes HTMLAttributes to the original View. This way, both cases are handled. - Assistant
Now let me check if the imports for
ProseMirrorNodeandEditorVieware already present intable.ts: - Assistant
Good,
ProseMirrorNodeandEditorVieware already imported. Now let me run the existing tests to make sure my changes don't break anything: - Assistant
Let me check how to run tests in this repo.
- Assistant
Let me run the unit tests for the extension-table package specifically.
- Assistant
Let me try running the tests differently.
- Assistant
- Assistant
- Assistant
Let me check what values are causing the error. Let me look at the actual mergedAttributes output:
- Assistant
The error is about a value that's an object being passed to
setAttribute. The issue is my approach of usingmergeAttributesis overly complex. Let me simplify the approach to directly applyHTMLAttributesto the table element: - Assistant
Now I should also remove the
mergeAttributesimport since we're no longer using it: - Assistant
Good. Now let me run the tests again to see if my changes pass:
- Assistant
All 9 tests pass. Now let me run all the table extension tests to make sure I haven't broken anything else:
- Assistant
All 34 tests pass. Now let me create a test script to verify the fix resolves the reported issue:
- Assistant
All tests pass. Now let me create a quick script to verify the HTMLAttributes fix works:
- Assistant
Some tests are failing. Let me see the full error output:
- Assistant
The tests are failing - HTMLAttributes are not being applied. Let me debug this. Let me check if
this.options.HTMLAttributesis being passed correctly: - Assistant
Let me fix the debug test and simplify:
- Assistant
The console.log output is not visible. Let me check the full output:
- Assistant
I see the issue! The
TableViewconstructor signature is(node, cellMinWidth, HTMLAttributes)butaddNodeView()calls it asnew View(node, cellMinWidth, view, HTMLAttributes). Theviewis being received as theHTMLAttributesparameter!I need to fix the constructor signature to include
viewas the third parameter (even if unused): - Assistant
Now I need to update the constructor signature to include
viewas the third parameter: - Assistant
I notice the constructor line is missing the opening
{. Let me check: - Assistant
I see the issue! The constructor is missing the opening brace
{. Let me fix that: - Assistant
Good, the file looks correct now. Let me run the tests again:
- Assistant
The fix works! The table element now has
class="my-custom-table". Let me run the full test suite again: - Assistant
All 39 tests pass, including the new HTMLAttributes tests. Now let me clean up the temporary test files:
- Assistant
Now let me verify the original tests still pass:
- Assistant
All original tests pass. Let me also run any other tests that might be affected:
- Assistant
Now let me review the final state of my changes:
- Assistant
The diff looks good. Let me now run a broader set of tests to make sure nothing else is broken:
- Assistant
All tests pass. Let me run a broader set of tests to make sure nothing else is broken:
- Assistant
All 117 test files pass with 1064 tests. The fix is working correctly and doesn't break anything.
Let me verify the final state of the modified files:
- Assistant
Let me also check the relevant parts of table.ts:
- Assistant
Let me verify the addProseMirrorPlugins and addNodeView sections:
- Assistant
The changes look good. Let me now run a quick test to verify edge cases:
- Assistant
All edge cases pass. Let me clean up the temporary test files:
- Assistant
Let me run the original test suite one more time to make sure everything is still working:
- Assistant
All 34 original tests pass. Now let me verify the final state of the changes by looking at the git diff:
- Assistant
The changes look good. Let me now verify the final state of the changes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.