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
tsimport { 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 element in its constructor. Assistant
Let me start by understanding the issue. The bug is in the
@tiptap/extension-tablepackage whereHTMLAttributesconfigured on the Table extension are being ignored whenresizable: false(the default). This is a regression from version 3.22.4.The root cause is that in 3.23,
addNodeView()was added to the Table extension, which causes the NodeView to be used and bypasses the schema'srenderHTML. TheTableViewconstructor doesn't applythis.options.HTMLAttributesto the<table>element.Let me first explore the repository structure to understand how it's organized.
Assistant
Let me look for the extension-table package in the packages directory.
<tool_call> <function=bash_terminal> <parameter=command> find packages -name "table" -type d </tool_call>
Assistant
The command was not executed. Let me run it again properly.
Assistant
Found the extension-table package. Let me explore its structure.
Assistant
Let me look at the src directory structure to find the Table extension source code.
<tool_call> <function=bash_terminal> <parameter=command> ls -la packages/extension-table/src/ </tool_call>
Assistant
I need to properly invoke the bash_terminal tool with a command.
Assistant
Now let me look at the table directory, which should contain the main table extension code.
<tool_call> <function=bash_terminal> <parameter=command> ls -la packages/extension-table/src/table/ </tool_call>
Assistant
I need to run a bash command properly. Let me try again with the bash_terminal function.
Assistant
Now let me look at the main table.ts file to understand the Table extension and the
addNodeViewmethod that's causing the issue.Assistant
Now let me look at the TableView.ts file to understand how it constructs the DOM and to see where I need to apply the HTMLAttributes.
<tool_call> <function=bash_terminal> <parameter=command> cat packages/extension-table/src/table/TableView.ts </tool_call>
Assistant
I need to use the bash_terminal function properly to run the cat command. Let me try again.
Assistant
Now I understand the issue. The
TableViewclass doesn't receive or applythis.options.HTMLAttributes. It only applies thenode.attrs.style. Let me first create a reproduction script to confirm the issue.Assistant
Let me look at the tests directory to understand the testing setup.
Assistant
Let me first understand how to reproduce the issue and then fix it. The issue is that
TableViewdoesn't receive or apply theHTMLAttributesfromthis.options. I need to:- First, see how the
addNodeViewmethod is called and how options are passed to theTableViewconstructor - Modify
TableViewto accept and applyHTMLAttributes
Let me look at how the NodeView is being created in the
addNodeViewmethod.- First, see how the
Assistant
Let me see how the tests work and understand how to run them.
Assistant
Now I understand the testing pattern. I need to:
- Create a reproduction script or test that verifies the bug exists
- Fix the issue by modifying TableView to accept and apply HTMLAttributes
Let me first write a test to confirm the issue, then apply the fix. I'll need to:
- Modify the
addNodeViewmethod to pass the options to the TableView constructor - Modify the
TableViewclass to accept and apply HTMLAttributes
Let me look at how to properly pass the options to the TableView constructor.
<tool_call> <function=bash_terminal> <parameter=command> cat packages/extension-table/src/table/table.ts | grep -A 20 "addNodeView" </tool_call>
Assistant
I need to use the bash_terminal tool properly to run this grep command.
Assistant
Now I understand the problem. The
addNodeViewmethod creates a newView(TableView) with onlynode,cellMinWidth, andview. It doesn't pass theHTMLAttributesto the constructor.The fix needs to:
- Modify
TableViewto acceptHTMLAttributesin its constructor - Apply those attributes to the
<table>element - Modify
addNodeViewto pass theHTMLAttributesto the TableView constructor
Let me also check if there are any places where
TableViewis instantiated directly (not throughaddNodeView).<tool_call> <function=bash_terminal> <parameter=command> grep -r "new TableView" packages/extension-table/ </tool_call>
- Modify
Assistant
I need to run the grep command properly to find all places where TableView is instantiated.
Assistant
No direct instantiations of TableView. Now let me apply the fix. First, I'll modify the
TableView.tsfile to accept and applyHTMLAttributesin its constructor.Assistant
Now I need to modify the
TableViewclass to:- Accept
HTMLAttributesin the constructor - Apply them to the
<table>element
Let me also check the mergeAttributes function to see how it's used in the table.ts file for renderHTML.
<tool_call> <function=bash_terminal> <parameter=command> grep -A 10 "renderHTML" packages/extension-table/src/table/table.ts | head -25 </tool_call>
- Accept
Assistant
Let me properly use the bash_terminal tool to search for the renderHTML method in table.ts.
Assistant
Now I understand the issue and the fix needed. Let me apply the fix by modifying the
TableView.tsfile to accept and applyHTMLAttributes.Assistant
Now I need to modify the
addNodeViewmethod intable.tsto pass theHTMLAttributesoption to theTableViewconstructor.Assistant
Now I need to modify the
addNodeViewmethod to pass theHTMLAttributesoption to theTableViewconstructor.Assistant
Now let me verify the change was applied correctly.
Assistant
The change has been applied. Now let me verify the
TableView.tschange as well.<tool_call> <function=bash_terminal> <parameter=command> cat packages/extension-table/src/table/TableView.ts </tool_call>
Assistant
I need to use bash_terminal properly to view the TableView.ts file.
Assistant
The changes look good. Now let me run the existing tests to make sure they still pass. First, let me see how to run the tests.
<tool_call> <function=bash_terminal> <parameter=command> cat packages/extension-table/package.json | grep -A 10 "scripts" </tool_call>
Assistant
I need to run the bash_terminal tool properly to get the scripts from package.json.
Assistant
The package.json doesn't have test scripts. Let me check the root package.json to see how tests are run.
<tool_call> <function=bash_terminal> <parameter=command> cat package.json | grep -A 20 '"scripts"' </tool_call>
Assistant
The bash_terminal tool doesn't seem to be working properly. Let me try a different approach.
Assistant
Let me run the existing tests to verify my changes don't break anything.
Assistant
The command timed out. Let me try a different approach - let me just verify the TypeScript compiles correctly and create a simple test script.
Let me first check if TypeScript compilation works for the modified files.
Assistant
Let me try building the extension-table package:
Assistant
There's a TypeScript error. The issue is that
Table.options.Viewis typed as(new (node: ProseMirrorNode, cellMinWidth: number, view: EditorView) => NodeView) | null, and my modification tries to pass 4 arguments instead of 3.The problem is that the type doesn't allow for an optional 4th argument. I need to change the type definition in the TableOptions to allow the View to accept optional additional options.
Let me look at the current type definition for View in TableOptions:
Assistant
I need to update the type definition for
Viewto accept an optional 4th argument for the options. Let me modify the TableOptions interface:Assistant
Now let me try to build again to see if the TypeScript error is fixed:
Assistant
The build succeeded! Now let me verify that the changes work correctly by examining the generated types and the JavaScript output.
<tool_call> <function=bash_terminal> <parameter=command> grep -A 5 "View:" packages/extension-table/dist/index.d.ts | head -10 </tool_call>
Assistant
Let me verify the changes by viewing the generated type definitions.
Assistant
Let me search specifically for the TableView type:
Assistant
The type definitions look correct. The
Viewoption now accepts an optionalHTMLAttributesparameter. Let me also verify the JavaScript output has the fix:Assistant
The JavaScript output shows the correct fix. Now let me also check the TableView class constructor in the output to make sure the HTMLAttributes are being applied:
Assistant
Let me escape the parentheses properly:
Assistant
Let me try a different search approach without using parentheses:
<tool_call> <function=bash_terminal> <parameter=command> grep -A 30 "constructor" packages/extension-table/dist/index.js | grep -A 30 "HTMLAttributes" </tool_call>
Assistant
The grep command didn't produce output. Let me try a simpler search to find the TableView constructor in the output.
Assistant
The JavaScript output shows the fix is working. The line
const { HTMLAttributes } = options || {};shows the HTMLAttributes are being extracted from the options in the TableView constructor.Now let me create a simple test script to verify the fix works as expected:
Assistant
Let me create a simpler test that doesn't require jsdom:
Assistant
The basic logic test passes. Now let me also verify that my changes handle the case where no HTMLAttributes are provided (to maintain backward compatibility):
Assistant
Let me now check if there are any existing tests for the extension-table that I should run to verify the changes don't break anything:
<tool_call> <function=bash_terminal> <parameter=command> ls -la /tiptap/packages/extension-table/tests/ </tool_call>
Assistant
The bash_terminal tool seems to be working but I need to use it properly. Let me try again to list the tests directory.
Assistant
The tests directory exists with 5 test files. Let me verify the changes I made are correct by looking at them again:
<tool_call> <function=bash_terminal> <parameter=command> git diff packages/extension-table/src/table/TableView.ts </tool_call>
Assistant
The git diff command seems to have not run. Let me try a different approach to see what changes have been made.
Assistant
Now let me also see the diff for table.ts:
<tool_call> <function=bash_terminal> <parameter=command> cd /tiptap && git diff packages/extension-table/src/table/table.ts </tool_call>
Assistant
The git diff command seems to not be working as expected. Let me try to run the command again.
Assistant
The changes look good. Let me now summarize what was fixed:
-
TableView.ts: Modified the constructor to accept an optional
optionsparameter withHTMLAttributes. The HTMLAttributes are then applied to the<table>element usingsetAttribute(). -
table.ts:
- Updated the
Viewtype definition to accept an optional 4th parameter for options. - Modified the
addNodeViewmethod to pass{ HTMLAttributes: this.options.HTMLAttributes }as the 4th argument when creating the TableView instance.
- Updated the
Now let me verify that the fix works properly for all the edge cases:
- HTMLAttributes with class - should be applied
- HTMLAttributes with data attributes - should be applied
- No HTMLAttributes - should not crash, empty attributes
- HTMLAttributes with style - should work alongside node.attrs.style
Let me also verify that the existing tests still pass by looking at them more closely. Since running the tests is problematic, let me at least verify the logic by reviewing the test file:
-
Assistant
The bash_terminal command seems to have some issues with execution. Let me try using bash_terminal with proper formatting.
Assistant
Now let me verify that the build output is correct and that everything is in order:
Assistant
The changes look correct. Now let me also check if there are any edge cases I need to handle, such as when a custom View is provided by the user (which might not accept the additional options parameter). Let me look at the code again to make sure the change is backward compatible.
Actually, looking at the
addNodeViewmethod more carefully:javascriptreturn ({ node, view }) => new View(node, this.options.cellMinWidth, view, { HTMLAttributes: this.options.HTMLAttributes })This assumes that all Views will accept the 4th parameter. But a custom View provided by a user might not accept it. This could break user's code.
Let me modify the code to handle this more gracefully. I should check if the View constructor accepts 4 parameters, or use a try-catch, or make the 4th parameter optional in a way that's backward compatible.
Assistant
Let me run a proper bash command to check the line in the table.ts file.
Assistant
I need to check if the user has provided a custom View, and if so, we should not pass the HTMLAttributes option (since they might not accept it). Let me modify the code to check if the View is the default TableView:
Assistant
I see that the default View is
TableView. Let me check what the default View is set to in the options:Assistant
Now I see that the default View is
TableView. I need to check if the View provided by the user is the same as TableView, and only pass the HTMLAttributes option in that case. Otherwise, if the user provides a custom View, we should not pass the options parameter.Let me modify the
addNodeViewmethod to check if the View is TableView:Assistant
Now I need to modify the
addNodeViewmethod to only pass the HTMLAttributes option when the View is the default TableView. This ensures backward compatibility with custom Views that might not accept the 4th parameter.Assistant
Let me use a different approach to modify the file:
Assistant
Let me view the current state of the file to get the exact text to replace:
Assistant
Now I need to create the modified
addNodeViewmethod. Let me use a here document:Assistant
Now let me use the edit command to replace the
addNodeViewmethod:Assistant
Now I need to also update the type definition for View in TableOptions. Let me check the current state and then update it:
Assistant
Now I need to update the View type to accept the optional 4th parameter. Let me use sed to replace the type definition:
Assistant
Let me verify the changes were applied correctly:
Assistant
I notice there's a duplicate closing brace. Let me fix this:
Assistant
I see there's a duplicate closing brace on line 541. Let me remove it:
Assistant
Let me verify the fix:
Assistant
The code looks correct now. Let me also verify the type definition was updated:
Assistant
The type definition has been updated. Now let me verify the build still works:
Assistant
The build succeeded. Let me verify the JavaScript output now has the correct code:
Assistant
I can see the code now passes
optionsas the 4th parameter. Let me also verify the options object is created correctly:Assistant
The code looks correct. The
optionsvariable is only set whenView === TableView2(TableView), otherwise it'svoid 0(undefined).Now let me also check the TableView class in the output to make sure it handles the options correctly:
Assistant
The command produced empty output, let me try a different approach to verify the TableView constructor.
Assistant
I found the TableView constructor but it's not showing the HTMLAttributes part. Let me search more specifically:
Assistant
I can see the HTMLAttributes code is in the output. Let me verify the complete fix:
Assistant
The fix looks complete. Now let me verify the git diff to see all the changes I made:
Assistant
Now let me clean up the temporary files and submit the changes.
<tool_call> <function=bash_terminal> <parameter=command> rm -f /tmp/test-table-fix.js /tmp/test-table-fix-2.js /tmp/addNodeView_patch.txt </tool_call>
Assistant
Let me clean up the temporary files properly using the bash_terminal tool.
Assistant
The changes have been made successfully. Let me summarize the fix:
Summary of Changes
Problem
In
@tiptap/extension-table3.23.x, configuring the Table extension withHTMLAttributeswas being ignored whenresizable: false(the default). This was a regression from 3.22.4 because 3.23 addedaddNodeView()which bypasses the schema'srenderHTMLmethod that normally applies HTMLAttributes.Solution
Modified the
TableViewclass to accept and applyHTMLAttributesfrom the extension options.Files Changed:
-
packages/extension-table/src/table/TableView.ts:
- Added optional
optionsparameter to the constructor withHTMLAttributes - Applied HTMLAttributes to the
<table>element usingsetAttribute()
- Added optional
-
packages/extension-table/src/table/table.ts:
- Updated the
Viewtype definition to accept an optional 4th parameter
- Updated the
-
Assistant
The changes are ready for submission. Let me submit them.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.