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 described:
- The bug is in
@tiptap/extension-tableversion 3.23.x - When configuring the Table extension with
HTMLAttributes, those attributes are not applied to the rendered<table>element whenresizable: false(the default) - The root cause is that
TableView(a NodeView) builds the DOM manually and never readsthis.options.HTMLAttributes - The fix would be to have
TableViewapplythis.options.HTMLAttributesto the inner<table>element in its constructor
Let me start by exploring the repository structure to understand the codebase.
- The bug is in
Assistant
Let me look at the key files: TableView.ts and table.ts.
Assistant
I made an error in my function call. Let me use the correct syntax for the open command.
Assistant
Now let me look at the table.ts file to see how addNodeView is implemented and how options are passed:
Assistant
Now I understand the issue clearly. Let me see the full
addNodeViewmethod and understand the problem:- In
addNodeView(), whenresizableis false (default) andViewis the defaultTableView, it returns a NodeView that createsnew View(node, this.options.cellMinWidth, view). - The
TableViewconstructor only takesnodeandcellMinWidth- it doesn't receiveHTMLAttributesfrom the options. - The
TableViewconstructor creates the table element but never appliesthis.options.HTMLAttributesto it.
The fix needs to:
- Pass
HTMLAttributesfrom the Table extension options toTableView - Apply those attributes to the table element in the
TableViewconstructor
Let me also check the
TableOptionsinterface to see theViewtype:- In
Assistant
The
Viewtype is(new (node: ProseMirrorNode, cellMinWidth: number, view: EditorView) => NodeView) | null. So I need to update the signature to also acceptHTMLAttributes.Let me also check how
mergeAttributesworks and if it's available:Assistant
Good. Now I understand the codebase. Let me create a plan:
Plan:
- Update
TableViewto acceptHTMLAttributesas a third parameter (aftercellMinWidth, beforeview) - Apply
HTMLAttributesto the table element in theTableViewconstructor - Update the
Viewtype inTableOptionsto include the new parameter - Update
addNodeView()to passthis.options.HTMLAttributesto the View constructor
Let me also check how the
columnResizingplugin uses the View, since the issue mentions it:- Update
Assistant
I see the prosemirror-tables
TableViewclass signature. Let me check the constructor signature:Assistant
The prosemirror-tables
TableViewconstructor only takesnodeanddefaultCellMinWidth. The tiptap extension has its ownTableViewclass inTableView.tsthat extends this pattern but adds aviewparameter in the type signature.Now let me think about the approach more carefully. The issue is:
TableViewdoesn't receiveHTMLAttributes- The
Viewtype signature is(new (node: ProseMirrorNode, cellMinWidth: number, view: EditorView) => NodeView) - We need to pass
HTMLAttributessomehow
The cleanest approach would be to:
- Add
HTMLAttributesas a parameter to theViewconstructor type and toTableView - Pass
HTMLAttributesinaddNodeView()
Let me also check if there are any tests I should look at:
Assistant
Now I have a good understanding of the codebase. Let me implement the fix:
- Modify
TableView.tsto accept and applyHTMLAttributes - Modify
table.tsto passHTMLAttributesto the View constructor and update the type signature
Let me start by modifying
TableView.ts:- Modify
Assistant
I need to modify the TableView constructor to accept HTMLAttributes and apply them to the table element. I also need to update the table.ts file to pass the HTMLAttributes to the View constructor.
Let me update TableView.ts first to:
- Add a new parameter for HTMLAttributes
- Apply those attributes to the table element
Then I'll update table.ts to pass the HTMLAttributes.
Assistant
Let me try using sed to make the changes instead:
Assistant
I need to use a different approach since python3 is not available. Let me use sed or create the file content directly.
Assistant
I need to use the proper edit command syntax. Let me use the heredoc syntax for multi-line replacement.
Assistant
Now let me update the
table.tsfile to:- Update the
Viewtype to include theHTMLAttributesparameter - Update
addNodeView()to passthis.options.HTMLAttributesto the View constructor
- Update the
Assistant
Now I need to:
- Update line 88 - change the View type signature to include HTMLAttributes
- Update the addNodeView() function to pass HTMLAttributes
Let me first look at the addNodeView function more closely:
Assistant
Now I need to update the
addNodeView()function to passthis.options.HTMLAttributesto the View constructor:Assistant
Let me verify the changes:
Assistant
Now let me verify the TableView.ts changes as well:
Assistant
The changes look correct. Now let me run the existing tests to make sure I didn't break anything:
Assistant
The tests are running. Let me wait for them to complete:
Assistant
I see the issue. There's a type compatibility problem. The
columnResizingfunction from prosemirror-tables expects aViewwith the old signature (3 parameters), but I changed the signature to 4 parameters. I need to look at how the View is passed tocolumnResizing:Assistant
I see. The
Viewis passed tocolumnResizingfromprosemirror-tables, which expects the old 3-parameter signature. This is causing a type error.The problem is that
prosemirror-tables'sColumnResizingOptions.Viewtype expects the signature(new (node: Node, cellMinWidth: number, view: EditorView) => NodeView), but I changed it to includeHTMLAttributes.I have a few options:
- Keep backward compatibility by making
HTMLAttributesan optional parameter with a default value - Use a separate type for the View that doesn't break compatibility with prosemirror-tables
The cleanest approach is to keep the
Viewtype compatible with prosemirror-tables but handle HTMLAttributes differently. Since thecolumnResizingplugin in prosemirror-tables also usesTableView, I need to think about this more carefully.Looking at this more carefully, I realize that:
- When
resizable: true, thecolumnResizingplugin from prosemirror-tables provides its own NodeView
- Keep backward compatibility by making
Assistant
Let me look more specifically at the ColumnResizingOptions interface:
Assistant
I see the issue. The
ColumnResizingOptions.Viewtype in prosemirror-tables expects(new (node: Node, cellMinWidth: number, view: EditorView) => NodeView), but I changed the tiptap type to includeHTMLAttributes.The solution is to:
- Keep the
Viewtype compatible with prosemirror-tables (3 params) - Store
HTMLAttributesseparately and apply it inaddNodeView()by wrapping the View constructor
Let me revert my changes and take a different approach:
- Keep the
Assistant
Let me revert the table.ts changes and take a different approach. The solution is to keep the View type compatible with prosemirror-tables, but handle HTMLAttributes internally in the addNodeView function:
Assistant
Now let me think of a better approach. The
addNodeViewfunction creates the view. Instead of passingHTMLAttributesto the View constructor, I can:- Keep
TableViewacceptingHTMLAttributesas a parameter (with default value for backward compatibility) - In
addNodeView(), after creating the view, manually apply the HTMLAttributes to the table element
But this would be fragile since we'd need to access the internal
tableproperty of the view.A better approach:
- Modify
addNodeView()to wrap the View constructor and apply attributes after construction - Or, use a different pattern where we apply attributes to the
domortableelement after the view is created
Actually, the cleanest approach is to change
addNodeView()to apply attributes directly to the view's table element after construction. Let me implement this:- Keep
Assistant
I'll update
addNodeView()to wrap the View creation and apply HTMLAttributes to the table element after construction. I'll also updateTableViewto accept an optional HTMLAttributes parameter:Assistant
Let me use a JavaScript file instead:
Assistant
Now let me verify the changes:
Assistant
Good. Now let me also revert the TableView.ts changes since we're applying HTMLAttributes in addNodeView() instead. Actually, let me check if I need to keep both approaches or just one.
Looking at the issue description more carefully, the suggested fix was:
A minimal fix would have
TableViewapplythis.options.HTMLAttributesto the inner<table>element in its constructor.But since
TableViewdoesn't have access to the extension options, I think the approach of applying attributes inaddNodeView()is the right approach. However, I should also keep the TableView changes for consistency and future-proofing, since the View constructor could also accept HTMLAttributes if needed.Let me check what the current TableView.ts looks like:
Assistant
Good, the TableView.ts still has my changes. But I think the TableView changes might cause issues if someone uses a custom View with the old signature. Let me reconsider the approach.
The issue is:
- The default
TableViewnow accepts an optionalHTMLAttributesparameter (with default{}) - The
addNodeView()function appliesHTMLAttributesafter creating the view
But wait, the
addNodeView()function creates the view with the old signature (3 params), soTableViewwill get its default value forHTMLAttributes. ThenaddNodeView()applies the attributes afterward.This should work, but there's a small redundancy - if someone uses the default
TableView, the attributes will be applied twice (once with empty object in constructor, once in addNodeView). This is harmless though.Actually, let me think about this more carefully. The current approach applies attributes in after the view is created. This means:
- The default
Assistant
wait, there's still a build error. Let me see what the specific error is.
<tool_call> <function=bash_terminal> <parameter=command> cd /tiptap && npm test -- --filter extension-table 2>&1 | grep -E "(error|Error)" | head -20 </tool_call>
Assistant
I need to properly format my bash command. Let me use the tool call format.
Assistant
The TypeScript errors are about accessing
tableanddom.querySelectoron theNodeViewtype. I need to cast thenodeViewproperly. Let me fix this:Assistant
I need to wait for the response before proceeding. Let me check if the fix was applied.
Assistant
The fix was applied. Now let me run the tests again to see if the build passes.
Assistant
The build succeeded! All 73 tasks passed. The test command failed because of an incorrect
--filteroption for vitest. Let me run the tests correctly for the extension-table package.Assistant
The extension-table package doesn't have a test script. Let me run vitest directly on the tests directory.
Assistant
I see the issue. The
TableViewconstructor is being called with different signatures:- By
addNodeView():new View(node, cellMinWidth, view)- where the 3rd arg isEditorView - By prosemirror-tables
columnResizing: same signature
My change to
TableViewaddedHTMLAttributesas the 3rd parameter, but the actual 3rd parameter being passed isview(EditorView). I need to revert theTableView.tschanges and only apply attributes inaddNodeView().- By
Assistant
Now let me verify the current state of my changes.
Assistant
The diff looks correct. Now let me run the tests again to confirm the fix works:
Assistant
All 34 tests pass. Now let me also run the build to ensure there are no TypeScript errors:
Assistant
Now let me create a test script to verify that the fix works for the reported issue - applying HTMLAttributes to the table element:
Assistant
The test script couldn't find the modules because it's running from
/tmp. Let me create the test script in a different location:Assistant
The test can't run directly in Node.js because it needs a browser-like environment. The existing tests use vitest with happy-dom, which is why they work. Let me check if the existing tests already cover similar scenarios, or if I should just verify the code logic manually.
Looking at the test output, all 34 existing tests pass. Let me verify the fix is correct by reviewing the code change and the logic:
Assistant
The fix looks good. Let me think about edge cases:
-
When
resizable: true: TheaddNodeView()returnsnulland thecolumnResizingplugin from prosemirror-tables handles the NodeView. In this case, HTMLAttributes would not be applied by our code. However, whenresizable: true, the prosemirror-tablescolumnResizingplugin uses the sameTableViewclass, and the issue doesn't report problems withresizable: true. Let me verify this case. -
When
View: null: TheaddNodeView()returnsnulland falls back torenderHTML, which correctly appliesHTMLAttributesviamergeAttributes. -
When using a custom View: The fix looks for
nodeView.tablefirst (which is the property name used byTableView), and falls back tonodeView.dom?.querySelector('table')for custom Views.
Let me also check if the
resizable: truecase needs to be handled:-
Assistant
When
resizable: true, thecolumnResizingplugin is used, which creates its own NodeView using theViewoption. ThecolumnResizingplugin from prosemirror-tables doesn't apply HTMLAttributes to the table element.Let me check if this is also an issue for
resizable: true:Assistant
Looking at the prosemirror-tables code, I see that when
resizable: true, thecolumnResizingplugin also creates the NodeView but doesn't apply HTMLAttributes. However, the bug report specifically mentionsresizable: false. Let me also handle theresizable: truecase by wrapping the View passed tocolumnResizing:Assistant
Now I need to add the helper method
createTableViewWithHTMLAttributes:Assistant
The approach with a helper method is too complex and doesn't fit the Node config structure. Let me simplify by reverting to just fixing
addNodeView()for the non-resizable case (which is what the bug report specifically mentions), and use an inline wrapper for theresizable: truecase.Assistant
The previous approach of using a class extension didn't work because the type system doesn't allow adding new methods to the NodeConfig. Let me take a simpler approach: just fix the
addNodeViewfor the non-resizable case, and for the resizable case, wrap the View inline inaddProseMirrorPlugins.Actually, looking at the error messages more carefully, the issue is that:
createTableViewWithHTMLAttributesis not a valid method in the NodeConfig- In
addProseMirrorPlugins,thisdoesn't have access to the helper method
Let me take a much simpler approach: just fix
addNodeView()for the non-resizable case, which is what the bug report specifically mentions. For the resizable case, I'll wrap the View inline without using a helper method.Assistant
(terminal output was empty or not provided)
Assistant
I need to use a proper tool call format.
Assistant
Let me check the current state of the file since the checkout didn't update anything (0 paths). The file might already be in the original state or my changes were already applied.
Assistant
The user seems to have had some kind of system issue. Let me check the current state of the file and continue with the fix. Since git status shows "nothing to commit, working tree clean", the file is already in its original state. I need to re-apply my fix.
Assistant
Good, the file is back to its original state. Let me apply the fix for
addNodeView()again:Assistant
Now let me verify the changes and run the tests:
Assistant
Good, the fix is applied. Now let me run the build and tests to make sure everything works:
Assistant
Build succeeded. Now let me run the tests to confirm everything works:
Assistant
All tests pass. Let me verify the final diff to confirm the fix is complete:
Assistant
It seems there was a brief interruption. Let me verify the current state of my work and continue:
Assistant
Good, my changes are in place. Let me verify the fix is complete and the tests pass, then go through the checklist:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.