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 start by exploring the repository structure to understand the codebase.
Assistant
Now let me check the table extension index.ts to understand how
addNodeViewis configured.Assistant
Now I understand the structure. Let me check the rest of the
table.tsfile to understand the full renderHTMLmethod.Assistant
Now let me look at the existing tests for the table extension:
Assistant
Let me check the mergeAttributes function from
@tiptap/core:Assistant
Let me look at the existing utility files and helpers for understanding existing utility structure:
Assistant
Now let me check the
columnResizingand how the View constructor is invoked:Assistant
Let me look at the actual
TableViewclass fromprosemirror-tablesfor reference:Assistant
Let me check the schema/parseHTML and renderHTML for the table:
Assistant
Now let me look at what packages/core exports for utilities:
Assistant
Let me check the
__tests__directory for more context:Assistant
Now let me check the test setup files:
Assistant
Let me first create a small reproduction script to verify the bug. Let me first see how tests are run:
Assistant
Let me first write a reproduction script that mimics the bug:
Assistant
Let me look at how prosemirror-tables
columnResizinguses the View:Assistant
Let me check the differences between
updateColumnsandupdateColumnsOnResize:Assistant
OK so
updateColumnsOnResizefrom prosemirror-tables and ourupdateColumnsare very similar. The main difference is thatupdateColumnsOnResizedirectly setscol.style.width, while ourupdateColumnsusesgetColStyleDeclarationto determine the property/value.Let me check
getColStyleDeclaration:Assistant
Let me check the current state of all relevant files:
Assistant
Now I have a complete understanding of the issue. Let me implement the fix.
Plan:
- Modify
TableViewconstructor to acceptHTMLAttributesand apply them to the inner<table>element. - Update
TableOptions.Viewtype to includeHTMLAttributesas an optional 4th argument. - Update
addNodeViewto passHTMLAttributesto the View constructor. - Update
addProseMirrorPluginsto wrap the View (used bycolumnResizingplugin) so HTMLAttributes are also applied in the resizable case.
Let me start with the
TableView:- Modify
Assistant
Let me use node.js to do the edit instead.
Assistant
Now let me add the
applyHTMLAttributeshelper function to the TableView.ts file:Assistant
Now let me add the
applyHTMLAttributeshelper function. I'll add it just before theTableViewclass definition:Assistant
Now let me update the
table.tsfile to:- Update the
Viewtype to acceptHTMLAttributes. - Update
addNodeViewto passHTMLAttributes. - Update
addProseMirrorPluginsto wrap the View for the resizable case.
- Update the
Assistant
Now let me also add the import for
applyHTMLAttributesin table.ts:Assistant
Let me verify the changes:
Assistant
Now let me run the reproduction script to verify my fix:
Assistant
I see - I used an arrow function but it needs to be a regular function because
columnResizingcallsnew View(...). Let me fix this:Assistant
Let me run the tests again:
Assistant
Both tests pass now. Let me run the existing tests to make sure I haven't broken anything:
Assistant
All tests pass. Now let me also check if there are other places that test tables or use table view:
Assistant
Let me run the static-renderer tests too since they use the table extension:
Assistant
Let me verify the full table.ts file looks correct:
Assistant
Let me also check if there's a
kit/index.tsfile that might need updating:Assistant
Let me extend the reproduction script to test more edge cases:
Assistant
Let me now run the entire test suite to make sure nothing else is broken:
Assistant
Let me also do a final check to ensure my code compiles correctly:
Assistant
Let me try running with the project's tsconfig:
Assistant
Let me filter for errors specific to my changes:
Assistant
Let me fix the TypeScript errors in my code:
Assistant
Let me run the tests once more to confirm everything still works:
Assistant
Now let me delete the reproduction spec file since I shouldn't add new tests to the repository:
Assistant
Let me verify the extension-table tests still pass:
Assistant
All tests pass. Now let me review the changes I made:
Assistant
Let me also check if my changes break anything in the broader test suite by running all tests:
Assistant
All 1064 tests pass. Now let me also verify my changes are correct by reviewing them once more:
Assistant
Let me create a quick verification script to test all scenarios:
Assistant
Let me delete the verify file - the custom view test failure is acceptable because it requires explicit user opt-in to update their View constructor signature. This is documented behavior:
Assistant
Let me run the tests once more to confirm everything still works:
Assistant
Let me look at the final state of all my changes:
Assistant
Let me create a final verification test in /tmp to verify the bug is fixed (since I shouldn't add tests to the repo):
Assistant
The bug is fixed. Let me delete the temporary verification file:
Assistant
Let me also clean up the temporary helper files:
Assistant
Now let me run all the tests once more to make sure nothing is broken:
Assistant
All 1064 tests pass. Let me also check the git status to see all my changes:
Assistant
Let me improve the fix to be more backward-compatible with custom Views. I'll move the HTMLAttributes application entirely to the wrapper layer (in
addNodeViewandaddProseMirrorPlugins), so even custom Views that don't accept HTMLAttributes will benefit:Assistant
Now let me update
table.tsto apply HTMLAttributes in the wrapper for the non-resizable case:Assistant
Now let me also revert the View type to keep the original 3-arg signature (or keep the optional 4th arg for forward compat). Let me check:
Assistant
Let me check the current state of the code:
Assistant
Let me verify the fix by running tests:
Assistant
All tests pass. Let me delete the verification file:
Assistant
Now let me run all the tests to make sure nothing is broken:
Assistant
All 1064 tests pass. Let me also verify the final state of the changes:
Assistant
Let me clean up the temporary helper files:
Assistant
Let me do a final review of my changes:
Assistant
Let me verify all tests still pass:
Assistant
All 1064 tests pass. Let me also do a final TypeScript check on the relevant files:
Assistant
The only TypeScript error is pre-existing in
extension-collaboration-caretand not related to my changes. Let me confirm this is pre-existing:Assistant
The TypeScript error is pre-existing and not caused by my changes. My fix is complete and all tests pass.
Let me now go over the checklist:
Checklist review:
-
If an error was reported in the issue description, I have successfully reproduced it.
- Yes, I created a reproduction script and verified that the
<table>element did not get theclass="my-custom-table"attribute when usingTable.configure({ HTMLAttributes: { class: 'my-custom-table' } }).
- Yes, I created a reproduction script and verified that the
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.