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 in
@tiptap/extension-tableversion 3.23.x TableViewignoresHTMLAttributeswhen rendering the table- This is a regression from 3.22.4 where
addNodeView()didn't exist - The fix should make
TableViewapplythis.options.HTMLAttributesto the inner<table>element
Let me first explore the repository structure to find the relevant files.
- The bug is in
Assistant
The search didn't show the main tiptap packages. Let me look at the repo structure more carefully.
Assistant
I see the packages directory. Let me find the extension-table package there.
Assistant
The extension-table package is in
/tiptap/packages/extension-table. Let me explore its structure.Assistant
Let me examine the main table source file:
Assistant
Now let me look at the
TableViewclass:Assistant
Now I understand the issue clearly. The
TableViewclass inTableView.tscreates the table DOM element but never appliesthis.options.HTMLAttributesto it. WhenaddNodeView()is called, it passes only(node, cellMinWidth, view)to theTableViewconstructor, but the constructor doesn't receive or useHTMLAttributes.Let me first check if there are any existing tests for HTMLAttributes:
Assistant
Let me look at the current
TableViewimplementation and how it's instantiated viaaddNodeView:Assistant
Now I have a clear understanding of the issue. Let me trace the problem:
addNodeView()intable.tsreturns aTableViewwhenresizableis falseTableViewis called with(node, cellMinWidth, view)but never receivesHTMLAttributesTableViewonly appliesnode.attrs.stylebut never appliesthis.options.HTMLAttributes
The fix needs to:
- Pass
this.options.HTMLAttributestoTableViewinaddNodeView() - Apply those attributes to the
<table>element inTableView
Let me first look at how
mergeAttributesis imported and used:Assistant
Now I understand the issue completely. Let me verify my understanding by looking at the
addNodeViewmethod more closely:Assistant
Now I have a clear understanding. The fix requires two changes:
- In
table.ts: Passthis.options.HTMLAttributestoTableViewinaddNodeView() - In
TableView.ts: Accept and applyHTMLAttributesto the<table>element
Let me implement the fix:
- In
Assistant
Now I understand the full issue. Let me trace through the code:
- In
addNodeView()(line 534 oftable.ts):new View(node, this.options.cellMinWidth, view)- only 3 args passed - In
TableViewconstructor: Only takes(node, cellMinWidth)- doesn't acceptHTMLAttributes renderHTMLmethod (lines 286-312 oftable.ts): UsesmergeAttributes(this.options.HTMLAttributes, ...)but that's bypassed when NodeView is used
The fix requires:
- Pass
HTMLAttributesfromaddNodeView()toTableView - Apply
HTMLAttributesto the<table>element inTableView
Let me first create a test script to reproduce the issue:
- In
Assistant
Let me now implement the fix. First, I'll update the
TableViewclass to accept and applyHTMLAttributes:Assistant
Let me use the bash terminal command instead with proper escaping:
Assistant
Let me use a different approach - I'll use node.js since this is a JS/TS repo:
Assistant
Let me use the edit command properly with the correct format:
Assistant
Now let me verify the changes and then update the
table.tsfile to passHTMLAttributesto theTableViewconstructor:Assistant
Good,
TableView.tsis updated. Now I need to updatetable.tsto passthis.options.HTMLAttributesto theTableViewconstructor inaddNodeView():Assistant
Now I need to update
addNodeView()intable.tsto passthis.options.HTMLAttributes:Assistant
Assistant
Let me verify the change:
Assistant
Now let me verify the changes by looking at both files:
Assistant
Now let me verify if the
mergeAttributesfunction can work with a DOM element as the first argument. Let me check how it's used in other parts of the codebase:Assistant
I see that in the existing codebase,
mergeAttributesis typically called with plain objects/strings as arguments, not DOM elements. Let me check howmergeAttributesis defined to understand if it can work with DOM elements.Looking at the usage patterns:
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)- object + object- In
TableView.tsI wrote:mergeAttributes(this.table, htmlAttributes)wherethis.tableis an HTMLTableElement
Let me check if
mergeAttributesaccepts DOM elements or if it works with object-like specifications. Looking at the typical usage, it seems to work with DOMOutputSpec arrays or plain objects.However, since
mergeAttributesis designed to merge attributes from multiple sources into a single object, it should work with DOM elements since they have anattributesproperty that can be accessed.Actually, let me check the implementation of
mergeAttributesto understand what it does:Assistant
Let me check the implementation of mergeAttributes to understand what it does and whether it can work with DOM elements.
Assistant
I see the issue. The
mergeAttributesfunction returns a plainRecord<string, any>object, not a DOM element. So I can't assign the result tothis.table. I need to apply the attributes directly to the DOM element.Let me fix the
TableView.tsto apply the attributes directly:Assistant
The bash escaping is causing issues. Let me try a different approach:
Assistant
The user wants me to continue. Let me check the current state of the file and verify my fix is correct.
Assistant
The
TableView.tshas been updated but I notice themergeAttributesimport is now unused since I'm applying attributes directly to the DOM element. Let me clean that up:Assistant
The user wants me to continue. Let me verify the current state of the TableView.ts file and then verify the table.ts file to make sure both changes are in place correctly. I should also check if there are any tests I can run to verify the fix works.
Assistant
Good, the unused import is removed. Now let me verify the constructor changes are correct by viewing the full TableView.ts file:
Assistant
Now let me verify the
table.tschanges are correct:Assistant
Good, both files look correct. Now I need to:
- Build to verify TypeScript compiles correctly
- Run existing tests to ensure nothing is broken
Let me first try to build the package:
Assistant
The user wants me to continue. The previous command timed out, likely because pnpm was downloading and installing dependencies. Let me try a different approach - I'll check if the dependencies are already installed and try to build or test.
Assistant
Let me try to build using the installed tools directly instead of pnpm.
Assistant
The user wants me to continue. The previous command failed because there's no tsconfig.json in the extension-table package directory. Let me check what configuration files exist and try to run the tests or build properly.
Assistant
The user wants me to continue. Let me check the package.json to see what build/test commands are available, and then run the tests.
Assistant
Let me try to build the extension-table package first to verify the TypeScript compiles correctly:
Assistant
There's a TypeScript error. The issue is that
htmlAttributeshas a default type of{}which doesn't allow string indexing. Let me fix the type annotation:Assistant
The user wants me to continue. There's a TypeScript error because
htmlAttributeshas a default type of{}which doesn't allow string indexing. I need to change the type annotation toRecord<string, any>. Let me fix this.Assistant
The user wants me to continue. Let me verify the fix and then try to build again.
Assistant
Good, the type is fixed. Now let me try to build again to verify:
Assistant
The TypeScript error indicates that the
Viewtype expectsEditorViewas the third parameter, but I'm passingRecord<string, any>(HTMLAttributes). I need to update theViewtype definition intable.tsto match the new constructor signature.Assistant
The TypeScript error indicates that the
Viewtype definition intable.tsexpectsEditorViewas the third parameter, but I'm passinghtmlAttributes. I need to update the type definition:Assistant
The user wants me to continue. The previous command updated the View type definition in table.ts. Let me verify the change and try to build again.
Assistant
Let me try to build again:
Assistant
The build succeeded. Now let me run the existing tests to verify my changes don't break anything:
Assistant
The tests are failing because some attribute values might be objects that can't be converted to primitive values by
setAttribute. I need to fix the code to properly convert values to strings:Assistant
I need to fix the
setAttributecalls to properly convert values to strings. The error occurs because some attribute values might be objects that can't be converted to primitives:Assistant
Let me run the tests again to verify the fix:
Assistant
The user wants me to continue. The error is still happening because some attribute values can't be converted to strings. Let me look at the failing tests to understand what values are being passed:
Assistant
The user wants me to continue. I see the issue now - the
columnResizingplugin (used whenresizable: true) passes(node, cellMinWidth, editorView)to the TableView constructor, but I changed the constructor to expect(node, cellMinWidth, htmlAttributes). This breaks backward compatibility.I need to make the constructor handle both cases:
- When called from
addNodeView:(node, cellMinWidth, HTMLAttributes) - When called from
columnResizing:(node, cellMinWidth, EditorView)
Let me fix this by detecting which type the third argument is:
- When called from
Assistant
Let me verify the changes and run the tests again:
Assistant
Let me run the tests again:
Assistant
All 44 tests pass now. Let me verify the build also still works:
Assistant
The build succeeded and all tests pass. Now let me create a test script to verify the fix actually resolves the issue described in the bug report:
Assistant
Let me verify the changes I made by viewing the final state of both modified files:
Assistant
Let me review what I've done and verify the changes are complete:
-
TableView.ts changes:
- Added third parameter
htmlAttributesOrViewto constructor - Added logic to detect if third arg is EditorView vs HTMLAttributes
- Apply HTMLAttributes to the table element when not an EditorView
- Added third parameter
-
table.ts changes:
- Updated View type definition to accept
Record<string, any>instead ofEditorView - Updated
addNodeViewto passthis.options.HTMLAttributesas third arg
- Updated View type definition to accept
All tests pass and the build succeeds. The fix addresses the issue where
HTMLAttributeswere being ignored byTableViewwhenresizable: false(the default).Let me verify the changes one more time by looking at the git diff.
-
Assistant
The user wants me to continue. I've made the changes to fix the bug where
HTMLAttributeswere being ignored byTableView. Let me verify the changes are complete by looking at the git diff to see exactly what was changed.Assistant
All tests pass and the build succeeds. The fix is complete. Here's a summary of the changes:
Summary of Changes:
-
packages/extension-table/src/table/TableView.ts:- Added third parameter
htmlAttributesOrView: Record<string, any> = {}to the constructor - Added logic to detect if the third argument is an EditorView (from
columnResizingplugin) vs HTMLAttributes (fromaddNodeView) - When the third arg is HTMLAttributes, applies them to the
<table>element:- Classes are added via
classList.add() - Style is set via
setAttribute('style', ...) - Other attributes are set via
setAttribute(key, value)
- Classes are added via
- Added third parameter
-
packages/extension-table/src/table/table.ts:- Updated the
Viewtype definition to accept (HTMLAttributes) instead of
- Updated the
-
Assistant
The user is asking me to submit my changes. Let me call the submit command properly.
Assistant
The user is asking me to submit my changes. The submit command should be called with no arguments. Let me try again.
Assistant
The user wants me to submit my changes. Let me try the submit command again.
Assistant
The user is trying to submit changes but my tool call isn't being parsed correctly. Let me try submitting my changes. The changes I made fix the bug where HTMLAttributes were being ignored by TableView in the table extension.
Let me review what I've done:
- Modified TableView.ts to accept and apply HTMLAttributes to the table element
- Modified table.ts to pass HTMLAttributes from addNodeView
The fix is complete and all tests pass. Let me try submitting again.
Assistant
The submit command isn't working as expected. Let me check if there's a different syntax needed for the submit command. Looking at the original prompt, it says "Usage: submit [OPTIONS]" with no required parameters. Let me try calling it without any arguments.
Assistant
The user wants me to submit my changes. The submit command should be called with the
submitcommand without any arguments. Let me try that again.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.