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 understanding the issue. The bug is in the
@tiptap/extension-tablepackage, specifically in version 3.23.x. The issue is that when configuring the Table extension withHTMLAttributes, those attributes are not applied to the rendered<table>element whenresizable: false(the default).The root cause is:
- In 3.23,
addNodeView()was added to the Table extension - When
resizableis false andViewis the defaultTableView, this returns a NodeView TableViewbuilds the DOM manually and never readsthis.options.HTMLAttributes- The schema-level
renderHTML(which does callmergeAttributes) is bypassed
The fix should be to have
TableViewapplythis.options.HTMLAttributesto the inner<table>element in its constructor.Let me first explore the repository structure to find the relevant files.
- In 3.23,
Assistant
Let me search more specifically for the extension-table package in the source code (not node_modules):
Assistant
I found the relevant files. Let me look at the TableView.ts file first, as that's where the issue is:
Assistant
Now let me look at the table.ts file to see how the Table extension is configured and how
addNodeView()works:Assistant
Now I can see the issue. The
addNodeView()method returns a function that creates a newTableView, butTableViewconstructor doesn't have access tothis.options.HTMLAttributes. Let me look at the issue more carefully:- In
addNodeView(), theTableViewis created withnew View(node, this.options.cellMinWidth, view) - The
TableViewconstructor doesn't receiveHTMLAttributesas a parameter - The
TableViewalso doesn't have access to the options that would containHTMLAttributes
Looking at the current
TableViewconstructor:constructor(node: ProseMirrorNode, cellMinWidth: number) { // ... }It only takes
nodeandcellMinWidth. We need to:- Add
HTMLAttributesto theTableViewconstructor - Apply
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, ...)to the table element
Let me also check what
HTMLAttributesis defined as:<tool_call> <function=bash_terminal> <parameter=command> grep -n "HTMLAttributes" /tiptap/packages/extension-table/src/table/table.ts </tool_call>
- In
Assistant
I need to check where HTMLAttributes is defined in the table.ts file.
Assistant
Now let me look at the renderHTML method and see how
HTMLAttributesis defined there:<tool_call> <function=bash_terminal> <parameter=command> sed -n '280,320p' /tiptap/packages/extension-table/src/table/table.ts </tool_call>
Assistant
Let me look at the renderHTML method to understand how HTMLAttributes is used:
Assistant
Now I understand the issue better. The
renderHTMLmethod usesmergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {...})to apply the configured HTML attributes. However, when theaddNodeView()method returns a NodeView (whenresizableis false), theTableViewis used instead, and it doesn't apply these attributes.The fix needs to:
- Pass
HTMLAttributesto theTableViewconstructor - Have
TableViewapplymergeAttributesto the table element
Let me also look at the addNodeView method more closely to see what arguments it passes:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '358,372p' /tiptap/packages/extension-table/src/table/table.ts </tool_call>
- Pass
Assistant
Let me look at the addNodeView method in the table.ts file:
Assistant
Let me find the exact line number of addNodeView:
Assistant
Now I understand the problem. The
addNodeViewfunction returns a function that creates a newView, but theTableViewconstructor doesn't receive theHTMLAttributesas a parameter. The solution is to:- Modify the
TableViewconstructor to acceptHTMLAttributes - Modify the
addNodeViewmethod to passthis.options.HTMLAttributesto theTableViewconstructor - In the
TableViewconstructor, usemergeAttributesto apply theHTMLAttributesto the table element
Let me first check how
mergeAttributesis used:<tool_call> <function=bash_terminal> <parameter=command> head -15 /tiptap/packages/extension-table/src/table/table.ts </tool_call>
- Modify the
Assistant
Let me see the imports in the table.ts file to understand how mergeAttributes is imported:
Assistant
Now I understand the structure. I need to:
- Modify
TableView.tsto acceptHTMLAttributesand apply them usingmergeAttributes - Modify
table.tsto passthis.options.HTMLAttributesto theTableViewconstructor
But there's a complication -
mergeAttributesis a function from@tiptap/corethat needs to be imported inTableView.ts. Let me check if it's already imported there:<tool_call> <function=bash_terminal> <parameter=command> head -10 /tiptap/packages/extension-table/src/table/TableView.ts </tool_call>
- Modify
Assistant
Let me check the current state of the file.
Assistant
Now I need to understand the solution. The problem is:
TableViewconstructor doesn't receiveHTMLAttributesaddNodeViewdoesn't passHTMLAttributestoTableViewTableViewdoesn't applyHTMLAttributesto the table element
The fix needs to:
- Import
mergeAttributesinTableView.ts - Add a parameter for
HTMLAttributesto theTableViewconstructor - Apply
mergeAttributesto the table element in the constructor - Update
addNodeViewto passthis.options.HTMLAttributestoTableView
Let me also check if there's a
viewparameter in the constructor since the current signature isnew View(node, this.options.cellMinWidth, view):<tool_call> <function=bash_terminal> <parameter=command> sed -n '78,95p' /tiptap/packages/extension-table/src/table/TableView.ts </tool_call>
Assistant
Let me check the current constructor signature in TableView.ts:
Assistant
The current constructor is
constructor(node: ProseMirrorNode, cellMinWidth: number), butaddNodeViewcalls it withnew View(node, this.options.cellMinWidth, view). This suggests thatviewis also passed but not used.Let me check the full file to understand the signature better:
Assistant
Now I see the issue clearly. The
addNodeViewcallsnew View(node, this.options.cellMinWidth, view), but the current constructor signature isconstructor(node: ProseMirrorNode, cellMinWidth: number). This means the third argumentviewis being passed but ignored.The solution is to:
- Add a third parameter
editor(which is the view) to the TableView constructor - but actually we don't need it - Add a fourth parameter for
HTMLAttributesor better yet, add a fifth parameter to maintain backward compatibility - Actually, the cleanest solution is to add
HTMLAttributesas a new parameter
Let me also check if
mergeAttributescan be imported from@tiptap/corein TableView.ts.The solution:
- Import
mergeAttributesfrom@tiptap/coreinTableView.ts - Add
HTMLAttributesparameter to theTableViewconstructor - Apply
mergeAttributesto the table element - Update
addNodeViewto pass to the constructor
- Add a third parameter
Assistant
Let me search for "View" in the TableView.ts file:
Assistant
Now let me check if there are any tests that I should run to verify my changes:
<tool_call> <function=bash_terminal> <parameter=command> ls -la /tiptap/packages/extension-table/tests/ </tool_call>
Assistant
Let me check what tests exist in the extension-table package.
Assistant
Let me check if there's a way to build and run tests:
Assistant
Now I understand the issue. Let me implement the fix.
Plan:
- Modify
TableView.tsto accepthtmlAttributesparameter and apply them usingmergeAttributes - Modify
table.tsto passthis.options.HTMLAttributesto theTableViewconstructor inaddNodeView()
Let me first modify the
TableView.tsfile:- Modify
Assistant
It looks like there are duplicate imports now. Let me fix the file properly by rewriting it:
<tool_call> <function=bash_terminal> <parameter=command> cat /tiptap/packages/extension-table/src/table/TableView.ts </tool_call>
Assistant
Let me restore the file to its original state and apply the fix properly:
Assistant
Good, the file is restored. Now let me apply the fix properly:
Assistant
Now let me apply the fix properly. I need to:
- Add the import for
mergeAttributesfrom@tiptap/core - Add a parameter for
htmlAttributesto the constructor - Apply
mergeAttributesto the table element
Let me do this step by step:
<tool_call> <function=edit> <parameter=command> edit 1:4 << 'EOF' import type { Node as ProseMirrorNode } from '@tiptap/pm/model' import type { NodeView, ViewMutationRecord } from '@tiptap/pm/view'
import { mergeAttributes } from '@tiptap/core'
import { getColStyleDeclaration } from './utilities/colStyle.js' EOF </tool_call>
- Add the import for
Assistant
Let me try again with the edit command.
Assistant
Good, the import has been added. Now let me update the constructor to accept
htmlAttributesand apply them to the table element. I need to find the line number of the constructor and the lines that need to be modified.<tool_call> <function=bash_terminal> <parameter=command> sed -n '92,108p' /tiptap/packages/extension-table/src/table/TableView.ts </tool_call>
Assistant
Let me check the constructor lines that need to be modified.
Assistant
Now I need to modify the constructor to:
- Add
htmlAttributesparameter - Apply
mergeAttributesto the table element
Let me make this change:
<tool_call> <function=edit> <parameter=command> edit 92:107 << 'EOF' constructor( node: ProseMirrorNode, cellMinWidth: number, htmlAttributes: Record<string, any> = {}, ) { this.node = node this.cellMinWidth = cellMinWidth this.dom = document.createElement('div') this.dom.className = 'tableWrapper' this.table = this.dom.appendChild( document.createElement('table', mergeAttributes(htmlAttributes, { style: node.attrs.style, })), )
this.colgroup = this.table.appendChild(document.createElement('colgroup')) updateColumns(node, this.colgroup, this.table, cellMinWidth) this.contentDOM = this.table.appendChild(document.createElement('tbody'))} EOF </tool_call>
- Add
Assistant
The edit command doesn't seem to be working properly. Let me try a different approach - using bash to write the file.
Assistant
Now let me verify that the changes were made correctly:
Assistant
The changes to
TableView.tslook good. Now I need to updatetable.tsto passthis.options.HTMLAttributesto theTableViewconstructor in theaddNodeView()method.Let me check the current
addNodeView()implementation:<tool_call> <function=bash_terminal> <parameter=command> sed -n '523,540p' /tiptap/packages/extension-table/src/table/table.ts </tool_call>
Assistant
The file context seems to have changed. Let me check the current file location and look at the table.ts file.
Assistant
Now I need to modify the
addNodeView()method to passthis.options.HTMLAttributesto theTableViewconstructor. The current signature isnew View(node, this.options.cellMinWidth, view), and I need to add thehtmlAttributesparameter.Assistant
Let me verify that the change was made correctly:
Assistant
Assistant
The file seems to already have the correct implementation. Let me verify that my fix is correct by checking the current state of the TableView constructor.
Assistant
The implementation looks good. Now let me verify the table.ts changes:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '523,540p' /tiptap/packages/extension-table/src/table/table.ts </tool_call>
Assistant
I need to check the table.ts file again to verify the changes were made correctly.
Assistant
Assistant
I need to check if there are any other places where
TableViewis instantiated.Assistant
The grep command returned exit code 1, which means no matches were found. This is expected since
TableViewis only instantiated in theaddNodeView()method oftable.ts.Now let me try to build the package to see if there are any TypeScript errors.
<tool_call> <function=bash_terminal> <parameter=command> cd /tiptap/packages/extension-table && npm run build 2>&1 | head -50 </tool_call>
Assistant
I need to run the build command to check if there are any TypeScript errors. Let me use bash_terminal to do this.
Assistant
The build failed because the TypeScript definition for
TableViewdoesn't match the new constructor signature. The error isExpected 3 arguments, but got 4.This is because the
TableViewclass is exported with a type definition, and the type definition doesn't include the newhtmlAttributesparameter.Let me check the type definition for
TableView. The issue is that theViewoption inTableOptionsmight have a type that expects a constructor with a specific signature.Let me look at the type definition for the
Viewoption:<tool_call> <function=bash_terminal> <parameter=command> cd /tiptap && grep -A5 "View:" packages/extension-table/src/table/table.ts | head -10 </tool_call>
Assistant
Let me look at the View option type definition in the table.ts file.
Assistant
Let me find where the View option is defined in the TableOptions interface.
<tool_call> <function=bash_terminal> <parameter=command> grep -n "View:" /tiptap/packages/extension-table/src/table/table.ts </tool_call>
Assistant
I need to find the View option type definition. Let me search for it more carefully.
Assistant
The View option type is defined at line 88 as:
View: (new (node: ProseMirrorNode, cellMinWidth: number, view: EditorView) => NodeView) | nullThis is the type for custom
Viewclasses. My change added a fourth parameterhtmlAttributes, which breaks the type definition.I have a few options:
- Update the type definition to include the
htmlAttributesparameter - Make the
htmlAttributesparameter optional with a default value (which I already did) - Use a different approach that doesn't require changing the type
Actually, I realize that the issue is that the type definition expects a constructor with exactly 3 parameters, but my
TableViewconstructor now has 3 parameters (plus the optionalhtmlAttributeswith a default value). The error is about the type definition for theViewoption, not theTableViewconstructor itself.Let me update the type definition to include the
htmlAttributesparameter:<tool_call> <function=bash_terminal> <parameter=command> sed -i 's/View: (new (node: ProseMirrorNode, cellMinWidth: number, view: EditorView) => NodeView) | null/View: (new (node: ProseMirrorNode, cellMinWidth: number, view: EditorView, htmlAttributes?: Record<string, any>) => NodeView) | null/' /tiptap/packages/extension-table/src/table/table.ts </tool_call>
- Update the type definition to include the
Assistant
Let me verify the change was made correctly:
Assistant
The sed command didn't work. Let me try a different approach using bash to modify the file.
<tool_call> <function=bash_terminal> <parameter=command> cat > /tmp/fix_type.sh << 'SCRIPT' #!/bin/bash file="/tiptap/packages/extension-table/src/table/table.ts" sed -i 's/View: (new (node: ProseMirrorNode, cellMinWidth: number, view: EditorView) => NodeView) | null/View: (new (node: ProseMirrorNode, cellMinWidth: number, view: EditorView, htmlAttributes?: Record<string, any>) => NodeView) | null/' "$file" SCRIPT chmod +x /tmp/fix_type.sh /tmp/fix_type.sh </tool_call>
Assistant
Let me verify if the change was made.
Assistant
The sed command still isn't working. Let me try a different approach - using a more specific pattern.
Assistant
Let me try using the specific line number to replace the content.
Assistant
Now let me verify the change was made correctly:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '88p' /tiptap/packages/extension-table/src/table/table.ts </tool_call>
Assistant
The command output was suppressed. Let me verify the change by checking the file again.
Assistant
The type definition was updated. Now let me try to build the package again to see if there are any other errors.
Assistant
The build succeeded. Now let me run the existing tests to make sure I didn't break anything.
Assistant
The build succeeded, but the test command failed because the vitest option is incorrect. Let me try running the tests with the correct syntax.
<tool_call> <function=bash_terminal> <parameter=command> cd /tiptap && npx vitest run extension-table 2>&1 | tail -100 </tool_call>
Assistant
The test command failed due to an unknown option. Let me try to run the tests using the correct vitest syntax or directly in the package directory.
Assistant
The tests for extension-table are passing! I can see several tests passing:
✓ packages/extension-table/__tests__/colgroupUpdate.spec.ts > colgroup updates after column commands > resizable: false (default — bug case) > updates <colgroup> when a column is deleted 32ms ✓ packages/extension-table/__tests__/colgroupUpdate.spec.ts > colgroup updates after column commands > resizable: false (default — bug case) > updates <colgroup> when a column is added after 8ms ... ✓ packages/extension-table/__tests__/tableCommands.spec.ts > Table commands > creates a 1x1 table 6ms ...The errors in the output (DOMException [AbortError]) seem to be related to network requests or async task management issues, not to my changes.
Now let me create a simple test script to verify that the fix works for the reported bug:
Assistant
Let me create a proper test script that runs within the project's test framework to verify the fix.
Assistant
Now let me run the test to verify that the fix works:
Assistant
All three tests passed! This confirms that the fix works correctly. The
HTMLAttributesare now being applied to the table element when using the defaultTableView.Now let me also verify that the existing tests still pass:
<tool_call> <function=bash_terminal> <parameter=command> cd /tiptap && npx vitest run packages/extension-table/tests/ --reporter=verbose 2>&1 | tail -80 </tool_call>
Assistant
Let me run the existing extension-table tests to make sure they still pass.
Assistant
All 37 tests passed, including the 3 new tests I added and the 34 existing tests. This confirms that my fix doesn't break any existing functionality.
Now let me also test the workaround mentioned in the issue description - using
View: null- to make sure it still works:<tool_call> <function=bash_terminal> <parameter=command> cat >> /tiptap/packages/extension-table/tests/tableHtmlAttributes.spec.ts << 'EOF'
describe('extension table HTMLAttributes with View: null (workaround)', () => { test('HTMLAttributes still work with View: null fallback', () => { const editor = new Editor({ extensions: [ StarterKit, Table.configure({ HTMLAttributes: { class: 'my-custom-table' }, View: null, // Use the workaround }), TableRow, TableHeader, TableCell, ], content: 'cell', })
const html = editor.getHTML() expect(html).toContain('class="my-custom-table"') editor.destroy()}) }) EOF </tool_call>
Assistant
The command to append to the test file may have failed silently. Let me check if the file was updated correctly and run the tests again.
Assistant
The append command didn't work. Let me manually update the test file to add the workaround test.
Assistant
Now let me run the tests again to make sure the workaround test also passes:
Assistant
All 4 tests passed, including the workaround test. The fix is working correctly.
Now let me also check if there are any edge cases I should consider:
-
Resizable tables: The
addNodeViewmethod only returns a NodeView whenresizableis false. Whenresizableis true, thecolumnResizingplugin handles the rendering, so my fix shouldn't affect it. -
Custom View classes: I updated the type definition to allow custom View classes to accept the optional
htmlAttributesparameter. This should be backward compatible since the parameter has a default value. -
Read-only mode: The
isEditablecheck inaddNodeViewensures that the NodeView is only used when the editor is not editable (whenresizableis false). This is correct because thecolumnResizingplugin is only used in editable mode.
Let me also verify that the fix works with
resizable: true:-
Assistant
The append command might not have worked. Let me check and run the tests.
Assistant
All 5 tests passed. Let me check the current state of the test file and clean up by removing the temporary test file since I was asked not to modify existing tests:
Assistant
The instructions say I should not modify existing tests or add new tests to the repository. Let me remove the test file I created:
Assistant
Now let me verify that the existing tests still pass with my fix:
Assistant
All 34 existing tests pass. Let me also verify the changes I made by looking at the git diff:
<tool_call> <function=bash_terminal> <parameter=command> cd /tiptap && git diff packages/extension-table/src/ </tool_call>
Assistant
The command to show git diff returned an error. Let me try again with the full path.
Assistant
Now let me see the diff for the table.ts file:
Assistant
I have made the following changes:
-
TableView.ts:
- Added import for
mergeAttributesfrom@tiptap/core - Modified the
TableViewconstructor to accept an optionalhtmlAttributesparameter with a default value of{} - Changed the table element creation to use
mergeAttributes(htmlAttributes, {style: node.attrs.style})to apply the HTML attributes to the table element
- Added import for
-
table.ts:
- Updated the
Viewoption type to include the optionalhtmlAttributesparameter - Modified the
addNodeViewmethod to passthis.options.HTMLAttributesto theTableViewconstructor
- Updated the
These changes fix the regression where
HTMLAttributesconfigured viaTable.configure({ HTMLAttributes: {...} })were not being applied to the rendered table element when using the defaultTableView(whenresizable: false).Let me verify the complete fix one more time by building and running all the tests:
<tool_call> <function=bash_terminal> <parameter=command> cd /tiptap/packages/extension-table && npm run build 2>&1 | tail -20 </tool_call>
-
Assistant
Let me run the build command properly to verify everything is working.
Assistant
The build succeeded! Now let me run the tests one more time to make sure everything is working correctly.
<tool_call> <function=bash_terminal> <parameter=command> cd /tiptap && npx vitest run packages/extension-table/tests/ 2>&1 | tail -20 </tool_call>
Assistant
The command to run the tests returned an error, but the output was cut off. Let me check if the tests passed by looking at the full output.
Assistant
All 34 existing tests pass. The fix is working correctly.
Let me provide a summary of the changes made and submit the solution.
Summary
Issue
In
@tiptap/extension-table3.23.x, configuring the Table extension withHTMLAttributesno longer applied those attributes to the rendered<table>element whenresizable: false(the default). This was a regression from 3.22.4.Root Cause
3.23 introduced
addNodeView()on the Table extension. Whenresizableis false andViewis the defaultTableView, this returns a NodeView. However,TableViewbuilt the DOM manually and never readthis.options.HTMLAttributes. The schema-levelrenderHTML(which does callmergeAttributes) was bypassed whenever the NodeView was active.Fix
-
TableView.ts:
- Added import for
mergeAttributesfrom
- Added import for
-
Assistant
Now let me submit the changes:
Assistant
The submit tool requires arguments. Let me try again with the correct syntax.
Assistant
The submit tool seems to require an argument. Let me try with the proper syntax.
Assistant
The diff shows all my changes. Let me now submit the solution using the submit command with the proper argument.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.