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 about
@tiptap/extension-tableversion 3.23.x whereHTMLAttributesconfigured on the Table extension are not applied to the rendered<table>element when using the defaultTableViewNodeView.The root cause is:
- In 3.23,
addNodeView()was added to the Table extension - When
resizable: false(default), it returns aTableViewNodeView TableViewbuilds the DOM manually but never reads the extension'sHTMLAttributesoption- This bypasses the schema's
renderHTMLwhich would have appliedHTMLAttributes
Let me start by exploring the repository structure to understand the codebase.
- In 3.23,
Assistant
Let me find the actual extension-table package in the repository.
Assistant
I found the relevant files. Let me look at the key files:
Assistant
Now I can see the issue clearly. The
addNodeView()method creates aTableViewthat builds the DOM manually, but it never passesthis.options.HTMLAttributestoTableView. TheTableViewconstructor only appliesnode.attrs.stylebut not the extension'sHTMLAttributes.Let me also look at the full
table.tsfile to see the complete picture:Assistant
Now I understand the issue. The
TableViewconstructor needs to acceptHTMLAttributesand apply them to the table element. TheaddNodeView()method intable.tspassesnode,cellMinWidth, andviewtoTableView, but it doesn't passHTMLAttributes.Here's my plan:
- Modify
TableViewto accept an optionalHTMLAttributesparameter - Apply those attributes to the table element in the constructor
- Update
addNodeView()intable.tsto passthis.options.HTMLAttributes
Let me also check how
mergeAttributesworks in the core package:- Modify
Assistant
Good. Now I understand how
mergeAttributesworks. I need to:- Update
TableViewto acceptHTMLAttributesas a third parameter (beforeview) - Update
addNodeView()intable.tsto passthis.options.HTMLAttributes - Apply those attributes to the table element in the constructor
But wait - I also notice that
TableViewcurrently accepts(node, cellMinWidth)but theViewtype signature says(new (node: ProseMirrorNode, cellMinWidth: number, view: EditorView) => NodeView). Let me check ifviewis already being passed:- Update
Assistant
I see. The current code passes
(node, cellMinWidth, view)butTableViewonly accepts(node, cellMinWidth). Theviewparameter is being passed but not used. The type signature says it should accept it though.Now let me think about the fix:
- Update
TableViewto accept an additional parameter forHTMLAttributesand apply them to the table element - Update the
Viewtype inTableOptionsto include theHTMLAttributesparameter - Update
addNodeView()to passthis.options.HTMLAttributes
The tricky part is that the
Viewoption type signature needs to be backward compatible. Looking at the issue, the suggestion is to applythis.options.HTMLAttributesto the inner<table>element.Let me first check if there are any existing tests:
- Update
Assistant
Good, let me check how the tests are run:
Assistant
Now let me implement the fix. I need to:
- Update
TableViewto accept and applyHTMLAttributes - Update the type signature for the
Viewoption - Update
addNodeView()to pass the attributes
Let me start by modifying
TableView.ts:- Update
Assistant
Now let me modify the
TableViewclass to accept and applyHTMLAttributes. I'll update the constructor signature and add logic to apply the attributes:Assistant
Wait, I need to reconsider this. The
styleattribute handling is tricky. Looking at the originaltable.ts, therenderHTMLmethod merges styles from multiple sources. But in theTableView, theupdateColumnsfunction setstable.style.minWidthandtable.style.widthdynamically. So I need to be careful not to override those.Let me look at this more carefully. The issue is that
node.attrs.stylefrom the prose mirror node already contains any style that was set via the extension's options. ButHTMLAttributescan also have astyleproperty.Let me check how the
renderHTMLintable.tshandles this:Assistant
I see. The
renderHTMLmethod uses . This means:Assistant
Let me now update the
table.tsfile to passHTMLAttributestoTableViewin theaddNodeView()method:Assistant
I see the current
addNodeViewreturnsnew View(node, this.options.cellMinWidth, view). But nowTableViewexpects(node, cellMinWidth, htmlAttributes). However, theViewtype signature says(new (node: ProseMirrorNode, cellMinWidth: number, view: EditorView) => NodeView).I need to think about this carefully:
- The current signature is
View(node, cellMinWidth, view)- butTableViewonly uses first 2 params - I want to add
htmlAttributesas a parameter - But custom
Viewimplementations might have different signatures
Looking at the bug report again, it mentions the fix would be to have
TableViewapplythis.options.HTMLAttributes. So the cleanest solution would be to:- Change to accept - but this changes the order
- The current signature is
Assistant
I already updated it. Now I need to also update the
addNodeView()method and the type signature for theViewoption. Let me check the type signature:Assistant
I see. The type says the third param should be
view: EditorView. But I changedTableViewto expecthtmlAttributesas the third param. Let me think about this more carefully...The best approach for backward compatibility would be to:
- Keep
viewas the third parameter inTableView - Add
htmlAttributesas a fourth parameter (optional) - Update
addNodeView()to passhtmlAttributesas a fourth parameter
OR, since
TableViewis the default view and internal to this package, I can update the type signature to match:- Change the type to
(new (node: ProseMirrorNode, cellMinWidth: number, htmlAttributes: Record<string, any>, view: EditorView) => NodeView) - Update
TableViewaccordingly - Update
addNodeView()accordingly
Actually, looking at the current code in
addNodeView():return ({ node, view }) => new View(node, this.options.cellMinWidth, view)- Keep
Assistant
I notice
this.node = nodegot removed! Let me fix that:Assistant
I see that
this.dom = document.createElement('div')is missing. Let me fix that:Assistant
Let me verify the full file looks correct:
Assistant
Good. Now I need to update the
addNodeView()method intable.tsto passthis.options.HTMLAttributes:Assistant
Now I need to update the type signature for the
Viewoption. Let me find it:Assistant
Good. Now let me run the existing tests to make sure my changes don't break anything:
Assistant
I see the issue! When
resizable: true, thecolumnResizingplugin fromprosemirror-tablescreates theTableViewwith the old signature(node, cellMinWidth, view). My change broke backward compatibility.I need to make
TableViewdetect whether the third parameter ishtmlAttributes(a plain object) orview(an EditorView). Let me fix this:Assistant
The bash history expansion caused an issue with the
!character. Let me fix the file properly:Assistant
The
ifcondition got removed. Let me fix it properly:Assistant
The
editcommand had a bash history expansion issue with!. Let me try a different approach - I'll write the entire file content using a here document to avoid the issue.Assistant
The bash history expansion is interfering. Let me check if the fix was applied:
Assistant
The
ifcondition is still missing. Let me usesedto fix it:Assistant
Let me check if it worked:
Assistant
The sed command messed up the file. Let me restore it and try a different approach - I'll write the entire file using node:
Assistant
Now let me write the complete fixed file using node.js with a script file to avoid bash escaping issues:
Assistant
Now let me run the tests again:
Assistant
The error is still happening. The issue is that my check
'dispatchTransaction' in htmlAttributesis not catching the EditorView object. Let me check what thecolumnResizingplugin passes:Assistant
Let me look at how the
columnResizingfunction creates the TableView:Assistant
I see the issue. The
columnResizingplugin fromprosemirror-tablespasses(node, defaultCellMinWidth, view)whereviewis an EditorView. My check should detect this, but let me verify what's actually in the file:Assistant
The check looks correct. Let me debug by adding a console.log to see what's happening:
Assistant
Wait, I realize the issue. The
columnResizingplugin creates the node view like this:nodeViews[tableName] = (node, view) => { return new View(node, defaultCellMinWidth, view); };So when
resizable: true, the third parameter is theview(EditorView). But my check for'dispatchTransaction' in htmlAttributesshould work...Let me add some debug output to understand what's happening:
Assistant
I need to check if the packages are built first, or use the source files. Let me first check if there's a dist folder and what's the proper way to run tests.
Assistant
I need to build the packages first or check how vitest runs the tests. The tests use the source files directly via the vitest configuration. Let me look at the vitest config to understand how tests are set up.
Assistant
The tests use source files directly via aliases. So my changes should be picked up. The error message shows the issue is in line 116 of TableView.ts where
String(value)fails becausevalueis an object that can't be converted to a primitive.The problem is that when the third parameter is an
EditorView, my check'dispatchTransaction' in htmlAttributesshould work. But maybe in the test environment (happy-dom), the EditorView doesn't havedispatchTransactionas an enumerable property?Let me look at the error more carefully - it's coming from
Object.entries(htmlAttributes). IfhtmlAttributesis an EditorView, thenObject.entries(editorView)would return its properties, and trying to callString(value)on a method or complex object would fail.Let me check if
dispatchTransactionis an own property or a prototype property:Assistant
The
dispatchTransactionis part ofDirectEditorProps, not directly on theEditorViewclass. Let me check what properties the EditorView has:Assistant
I see. The
EditorViewhas astateproperty and adomproperty. Let me use a more reliable check. Instead of checking fordispatchTransaction, I should check if the object has thestateproperty (which is unique to EditorView):Assistant
All 34 tests pass. Now let me create a test script to verify the fix for the bug:
Assistant
Wait, I need to remove this test file since I'm not supposed to add new tests. Let me delete it and instead verify my fix works using a temporary script:
Assistant
Let me create a temporary test script to verify the fix:
Assistant
The test file needs to be inside the packages directory based on the vitest config. Let me create it there temporarily.
Assistant
The fix works. Now let me clean up the temporary test file and run all the existing tests again to make sure everything still passes:
Assistant
All 34 existing tests pass. Let me also review my changes and verify the final state of the files:
Assistant
Failed
Assistant
I need to provide a properly formatted bash_terminal command. Let me check the git diff to see all changes made.
Assistant
I notice there's an issue with the regex in the diff - the backslashes are being doubled. This happened because of how the heredoc wrote the file. Let me fix that:
Assistant
The regex has double backslashes
\\band\\sinstead of\band\s. This is a bug in how I wrote the file - the template literal escaping caused the double backslashes. Let me fix this:Assistant
Let me fix the regex properly using node:
Assistant
Good, the regex is now correct. Let me verify the full file is correct and run the tests again:
Assistant
All 34 tests pass. Let me verify the final diff to make sure all changes are correct:
Assistant
The changes look correct. Let me submit the solution.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.