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
@tiptap/extension-tableversion 3.23.x where HTMLAttributes configured for the Table extension are not being applied to the rendered<table>element whenresizable: false(the default).The issue says:
- In version 3.23.x,
addNodeView()was added to the Table extension - When
resizableis false andViewis the defaultTableView, it returns a NodeView TableViewbuilds the DOM manually and never readsthis.options.HTMLAttributes- The schema-level
renderHTMLis bypassed whenever the NodeView is active
Let me first explore the repository structure to understand how the codebase is organized.
- In version 3.23.x,
Assistant
Let me look at the TableView.ts file since that's where the bug is:
Assistant
Now let me look at the table.ts file to see how the Table extension is configured and how
addNodeView()is implemented:Assistant
Let me see the full table.ts file since it seems truncated:
<tool_call> <function=bash_terminal> <parameter=command> wc -l /tiptap/packages/extension-table/src/table/table.ts </tool_call>
Assistant
Let me get the line count of the table.ts file:
Assistant
Let me see the renderHTML part of the table.ts file since the issue mentions that
renderHTMLcorrectly appliesHTMLAttributes:<tool_call> <function=bash_terminal> <parameter=command> sed -n '280,380p' /tiptap/packages/extension-table/src/table/table.ts </tool_call>
Assistant
The issue says I need to use special commands in a specific way. Let me run the command correctly.
Assistant
Now I understand the issue better. The
renderHTMLmethod correctly appliesthis.options.HTMLAttributes, but whenaddNodeView()returns a NodeView, it bypassesrenderHTMLand usesTableViewinstead. TheTableViewconstructor doesn't applythis.options.HTMLAttributes.Let me see the full constructor of
TableView:<tool_call> <function=bash_terminal> <parameter=command> cat /tiptap/packages/extension-table/src/table/TableView.ts </tool_call>
Assistant
I need to use the proper format. Let me use bash_terminal with the command as a string argument.
Assistant
Now I understand the issue clearly:
-
The problem: In version 3.23.x, when
resizable: false(the default),addNodeView()returns a NodeView usingTableView. TheTableViewconstructor creates the<table>element but never appliesthis.options.HTMLAttributes. -
Why it worked in 3.22.4: Version 3.22.4 didn't have
addNodeView(), so ProseMirror fell back to the schema'srenderHTML, which correctly appliedmergeAttributes(this.options.HTMLAttributes, ...). -
The fix: We need to modify
TableViewto accept and applyHTMLAttributes, and updateaddNodeView()to pass them to the constructor.
Let me first check if there are any tests for the table extension:
-
Assistant
The command returned exit code 1, which means no test files were found for the table extension using that pattern. Let me search more broadly.
Assistant
Let me look for tests specifically for the extension-table package:
<tool_call> <function=bash_terminal> <parameter=command> ls -la /tiptap/packages/extension-table/ </tool_call>
Assistant
I need to use bash_terminal with the command as a string argument.
Assistant
Let me check the tests directory:
<tool_call> <function=bash_terminal> <parameter=command> ls -la /tiptap/packages/extension-table/tests/ </tool_call>
Assistant
I need to use bash_terminal properly with command as a string. Let me try again.
Assistant
Okay, there are tests. Let me now understand the fix:
- The
TableViewconstructor needs to accept HTMLAttributes as a parameter - The
addNodeViewmethod in table.ts needs to passthis.options.HTMLAttributesto the TableView constructor - The TableView constructor should apply the HTMLAttributes to the table element
Let me first create a test to reproduce the issue, then fix it.
Actually, let me first look at how other extensions handle HTMLAttributes in NodeView to understand the pattern better.
<tool_call> <function=bash_terminal> <parameter=command> find /tiptap/packages -name "*.ts" -type f -exec grep -l "NodeView" {} ; | head -10 </tool_call>
- The
Assistant
I need to use bash_terminal properly. Let me run the command as a string.
Assistant
Let me look at how ResizableNodeView handles attributes:
Assistant
This doesn't help much with how HTMLAttributes are applied. Let me think about the fix more carefully.
The fix needs to:
- Modify the
TableViewclass to accept HTMLAttributes as a parameter - Apply the HTMLAttributes to the table element in the constructor
- Update
addNodeViewto passthis.options.HTMLAttributesto the TableView constructor
Let me now make the fix:
<tool_call> <function=bash_terminal> <parameter=command> cat /tiptap/packages/extension-table/src/table/TableView.ts </tool_call>
- Modify the
Assistant
I need to use bash_terminal properly with the command as a string argument.
Assistant
Now I understand the issue. The
TableViewconstructor doesn't accept HTMLAttributes and doesn't apply them to the table element. Let me fix this:- First, I'll update the
TableViewclass to accept HTMLAttributes and apply them - Then, I'll update the
addNodeViewmethod to pass the HTMLAttributes to the TableView constructor
Let me start by updating the TableView.ts file:
- First, I'll update the
Assistant
Good, the TableView.ts file was updated. Now I need to update the
addNodeViewmethod in table.ts to pass the HTMLAttributes to the TableView constructor:<tool_call> <function=bash_terminal> <parameter=command> sed -n '480,510p' /tiptap/packages/extension-table/src/table/table.ts </tool_call>
Assistant
I need to use bash_terminal properly with the command as a string.
Assistant
Let me find the addNodeView method:
Assistant
Now let me see the addNodeView method:
Assistant
Now I need to modify the addNodeView method to pass the HTMLAttributes to the TableView constructor. Let me update it:
Assistant
Let me verify the changes were made correctly:
Assistant
The changes look correct. Now let me verify the TableView.ts file also has the correct changes:
Assistant
Now let me check if there are any other places where TableView is instantiated. I should search for usages to make sure I'm not breaking anything:
<tool_call> <function=bash_terminal> <parameter=command> grep -r "new TableView" /tiptap/packages/extension-table/src/ </tool_call>
Assistant
The command is not properly formatted. I need to pass the command as a single string.
Assistant
The command returned exit code 1 which means grep didn't find any matches. That's actually good - it means TableView is only instantiated via the
addNodeView()method. Let me also check if TableView is exported and used elsewhere:<tool_call> <function=bash_terminal> <parameter=command> grep -r "TableView" /tiptap/packages/extension-table/src/ | grep -v "node_modules" </tool_call>
Assistant
I need to use bash_terminal properly with command as a string. Let me try again.
Assistant
Good, I can see that:
- TableView is exported from the extension-table package
- TableView is imported and used in table.ts
- TableView is also the default value for the
Viewoption
The change I made should be fine since:
- The new
HTMLAttributesparameter has a default value of{}, so even if someone instantiates TableView directly without it, it won't break - The
addNodeViewmethod now correctly passesthis.options.HTMLAttributes
Now let me run the existing tests to make sure I didn't break anything:
<tool_call> <function=bash_terminal> <parameter=command> cd /tiptap/packages/extension-table && npm test 2>&1 | head -100 </tool_call>
Assistant
The command didn't work. Let me check the package.json for the correct test command.
Assistant
There's no test script in the package.json. Let me check the root package.json for the test command:
Assistant
I can run
pnpm test:unitto run the unit tests. Let me do that:Assistant
The command timed out. Let me try to just run vitest directly:
Assistant
The tests are passing. Let me wait for the table-related tests specifically:
Assistant
All table-related tests pass. Now let me create a test script to verify that the fix actually works for the issue described - HTMLAttributes being applied when
resizable: false:Assistant
I notice I made a syntax error in my script. Let me fix it:
Assistant
The script was created successfully. Now I need to think about how to test this in a Node environment. The issue is that the Tiptap editor requires a DOM environment (like a browser), but Node.js doesn't have a built-in DOM. I'll need to use a library like jsdom to simulate a browser environment.
Let me check if jsdom is available or if we need to install it:
Assistant
Let me check if jsdom is available:
Assistant
jsdom is not installed. Let me try a different approach - let me look at how the existing tests work:
Assistant
Assistant
Let me create the test file properly. The issue is that my heredoc syntax may be causing problems. Let me use a different approach.
Assistant
Now let me run this specific test to verify the fix works:
Assistant
The test file I created is in the root directory of the repository, but vitest is looking for tests in the
packages/directory. Let me move the test to the correct location:<tool_call> <function=bash_terminal> <parameter=command> mv /tiptap/test-htmlattributes.spec.ts /tiptap/packages/extension-table/tests/htmlattributes.spec.ts </tool_call>
Assistant
I need to use bash_terminal properly. Let me run the command to move the test file.
Assistant
The test file has been moved. Now let me run the test again:
<tool_call> <function=bash_terminal> <parameter=command> cd /tiptap && npx vitest run packages/extension-table/tests/htmlattributes.spec.ts --reporter=verbose 2>&1 </tool_call>
Assistant
The command timed out or had issues. Let me try a simpler approach - just run the test without the verbose reporter.
Assistant
The test is failing, which means my fix didn't work. Let me analyze why.
Looking at the test results:
- Test 1 "should apply HTMLAttributes class when resizable: false (default)" - FAILED
- Test 2 "should apply multiple HTMLAttributes when resizable: false" - FAILED
- Test 3 "should still work correctly with resizable: true" - PASSED
Wait, test 3 passes even though
resizable: true. This is surprising because according to the issue, whenresizable: true, the NodeView is handled by thecolumnResizingplugin, not by our TableView.Let me check the logic again. Looking at
addNodeView():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, this.options.HTMLAttributes) }When
editable: false, the conditionthis.editor.isEditablereturns . So becomes even if . This means the NodeView is registered for the case when .Assistant
Let me use bash_terminal to check the current state of the TableView.ts file.
Assistant
Let me see the rest of the constructor to verify the mergeAttributes is called:
<tool_call> <function=bash_terminal> <parameter=command> cat /tiptap/packages/extension-table/src/table/TableView.ts | head -120 | tail -30 </tool_call>
Assistant
I need to use bash_terminal properly to get the file content.
Assistant
The code looks correct. The test is failing, which could mean one of the following:
- The package needs to be rebuilt
- Vitest is caching old results
- The test is using a different path or version of the code
Let me try rebuilding the extension-table package:
Assistant
The pnpm build command is trying to download pnpm. Let me cancel and try a different approach - clear the vitest cache and rebuild the core package first:
I should first verify my changes are correct by looking at the full file content. The issue might be that vitest is using the source files directly (not the built dist files), so the build might not be the issue.
Let me check if vitest is configured to use the source files or the built files:
Assistant
The vitest config shows that it's using the source files directly via aliases. So my changes to TableView.ts should be picked up. Let me clear the vitest cache and try running the test again.
Assistant
Let me check the table.ts file to see if my changes are still there. The test is still failing, which means either:
- The changes weren't saved properly
- There's something wrong with how I'm passing the HTMLAttributes
Let me check the addNodeView function again:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '523,535p' /tiptap/packages/extension-table/src/table/table.ts </tool_call>
Assistant
I need to use bash_terminal properly to view the table.ts file.
Assistant
Assistant
I need to properly use the bash_terminal command to create the test file. Let me do that.
Assistant
Now let me run the test with the console.log output to see what's happening:
<tool_call> <function=bash_terminal> <parameter=command> cd /tiptap && npx vitest run packages/extension-table/tests/htmlattributes.spec.ts 2>&1 </tool_call>
Assistant
The command is not being executed properly. Let me try again with the correct format.
Assistant
I can see from the console output that the table element doesn't have the class applied. The outerHTML shows:
<table style="min-width: 25px;">But it should have
class="my-custom-table". This confirms that my changes to the TableView are not being applied correctly.Let me check if the code is actually being imported correctly. I notice that vitest might be caching or using the built files. Let me check if the extension-table has been built and if the source files are being used correctly.
Wait, looking at the vitest config again:
aliases[`@tiptap/${name}`] = resolve(`${path}/${name}/src/index.ts`)This should resolve to the source files. Let me verify that my changes are actually being loaded.
Actually, I think I see the issue now. Let me check how vitest handles ES modules with exports. The issue might be that the extension-table package exports from
dist/but vitest needs the source files.Let me check the package.json exports:
<tool_call> <function=bash_terminal> <parameter=command> cat /tiptap/packages/extension-table/package.json | grep -A 5 '"exports"' </tool_call>
Assistant
I need to use bash_terminal properly to view the package.json file.
Assistant
The vitest config says it uses
src/for table extension, but maybe there's something wrong with the import. Let me check what the extension-table/index.ts exports:<tool_call> <function=bash_terminal> <parameter=command> cat /tiptap/packages/extension-table/src/index.ts </tool_call>
Assistant
Let me run the command to view the index.ts file.
Assistant
The issue might be related to how vitest handles the import. Let me check if there's a TypeScript cache or if the import path is resolved correctly. Actually, I think the issue might be that my changes to TableView are using a different import pattern that vitest doesn't handle correctly.
Let me check if the
mergeAttributesimport is correct:<tool_call> <function=bash_terminal> <parameter=command> grep "mergeAttributes" /tiptap/packages/extension-table/src/table/TableView.ts </tool_call>
Assistant
Let me run the grep command to check the mergeAttributes import.
Assistant
The import looks correct. Let me check if maybe the vitest config doesn't include the
extension-tablepackage properly or if there's an issue with how vitest handles the@tiptap/coreimport.Actually, let me try a different approach. Let me check if vitest is actually running the modified source code by adding a deliberate error to the TableView.ts file:
Assistant
The code looks correct. Let me check if there's a build output that might be used instead of the source files. Actually, the vitest config says it uses source files, but maybe there's a caching issue.
Let me try adding an error to trigger a cache miss and confirm vitest is actually reading the file:
Assistant
Now let me run the test again to see if the console.log is printed:
Assistant
Now I can see that:
mergeAttributesIS being called with the correct attributes- But the class is NOT being applied to the table element
This means the
mergeAttributesfunction from@tiptap/coreis not properly applying the attributes to the DOM element. Let me check howmergeAttributesworks:Assistant
Let me find the mergeAttributes file:
Assistant
The command exited with exit code 0. Let me use bash_terminal to read the mergeAttributes file.
<tool_call> <function=bash_terminal> <parameter=command> cat /tiptap/packages/core/src/utilities/mergeAttributes.ts </tool_call>
Assistant
I need to use bash_terminal properly to read the mergeAttributes.ts file.
Assistant
The
mergeAttributesfunction is for merging attributes objects, not for applying them to a DOM element. It returns a merged object. The actual DOM element attribute application needs to be done separately usingelement.setAttribute().Looking at the code, I see that:
mergeAttributes(...objects: Record<string, any>[]): Record<string, any>- this returns a merged attributes object- I was incorrectly trying to use
mergeAttributes(this.table, HTMLAttributes)to apply attributes to the DOM element
I need to:
- First merge the attributes using
mergeAttributes - Then apply the merged attributes to the DOM element using
setAttribute
Let me check how other parts of the codebase apply attributes to DOM elements:
<tool_call> <function=bash_terminal> <parameter=command> grep -r "setAttribute" /tiptap/packages/core/src/utilities/ | head -10 </tool_call>
Assistant
The command timed out or had issues. Let me try a different approach - I'll look at how the renderHTML method applies attributes to understand the pattern.
Let me search for how attributes are applied to DOM elements in other parts of the codebase.
Assistant
The command timed out. Let me try a different approach to search for how to apply attributes to DOM elements.
<tool_call> <function=bash_terminal> <parameter=command> grep -r "setAttribute" /tiptap/packages/core/src/ --include="*.ts" | head -20 </tool_call>
Assistant
I need to use bash_terminal properly. Let me run the command to search for setAttribute usage.
Assistant
Let me look for how ProseMirror's
mergeAttributesor similar functions apply attributes to DOM elements. Actually, looking at the renderHTML method in table.ts, I can see it usesmergeAttributesto create a merged attributes object, and then passes it to the HTML array spec. The ProseMirror rendering takes care of applying those attributes.For the NodeView case, I need to manually apply the attributes. Let me check how the
mergeAttributesfunction is supposed to be used with DOM elements. Let me look at the tests for mergeAttributes:Assistant
Assistant
The command to create the TableView.ts file seems to have failed because I didn't use the bash_terminal function correctly. Let me try again with the proper format.
Assistant
Now let me also remove the console.log statement I added earlier for debugging purposes:
<tool_call> <function=bash_terminal> <parameter=command> sed -i 's/console.log("mergeAttributes called with:", HTMLAttributes); // remove the console.log/' /tiptap/packages/extension-table/src/table/TableView.ts </tool_call>
Assistant
The command to remove the console.log didn't work properly because my sed command had a syntax issue. But actually, looking at the file I just wrote, I didn't include the console.log in the first place since I wrote the entire file content from scratch. Let me verify the file is correct:
Assistant
Good, the file looks correct. Now let me run the test again to see if the fix works:
<tool_call> <function=bash_terminal> <parameter=command> cd /tiptap && npx vitest run packages/extension-table/tests/htmlattributes.spec.ts 2>&1 | head -50 </tool_call>
Assistant
The command timed out. Let me try again with the bash_terminal command.
Assistant
The tests are passing now. The HTMLAttributes are being applied correctly. Let me now:
- Clean up the test file to remove the console.log statements
- Remove the test file I created (since it was just for verification)
- Run the existing tests to make sure I didn't break anything
Assistant
Now let me remove the test file I created since it was just for verification:
Assistant
Now let me run the existing table tests to make sure I didn't break anything:
Assistant
All existing table tests pass. Now let me run a broader set of tests to make sure my changes didn't break anything else:
Assistant
All 1064 tests pass! Now let me also check if there are any TypeScript errors by checking the type definitions:
<tool_call> <function=bash_terminal> <parameter=command> cd /tiptap/packages/extension-table && npx tsc --noEmit 2>&1 | head -50 </tool_call>
Assistant
The command timed out. Let me try running the TypeScript check with a shorter timeout.
Actually, the command timed out because TypeScript might take a while to compile all the files. Let me just verify that my changes are syntactically correct by looking at the file again, and then clean up any test files I created.
Let me summarize what I've done:
- Modified
TableView.tsto acceptHTMLAttributesas a parameter and apply them to the table element - Modified
addNodeView()intable.tsto passthis.options.HTMLAttributesto the TableView constructor
Let me verify the changes are complete by reviewing both files:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "HTMLAttributes" /tiptap/packages/extension-table/src/table/TableView.ts </tool_call>
- Modified
Assistant
I need to use bash_terminal to run the grep command.
Assistant
Good, the HTMLAttributes are being used in the TableView. Now let me verify the addNodeView changes:
Assistant
Good, the changes look correct. Let me clean up the test script I created earlier:
<tool_call> <function=bash_terminal> <parameter=command> rm -f /tiptap/test-htmlattributes.js </tool_call>
Assistant
Let me run the command to remove the test script.
Assistant
Now let me review the changes I made to make sure everything is complete and correct. Let me check the git diff to see all the changes:
<tool_call> <function=bash_terminal> <parameter=command> cd /tiptap && git diff --stat </tool_call>
Assistant
The command timed out. Let me try running the git diff command.
Assistant
The command exited with exit code 0. Let me see the full diff of the changes I made.
<tool_call> <function=bash_terminal> <parameter=command> cd /tiptap && git diff </tool_call>
Assistant
Let me run the git diff command properly.
Assistant
The diff shows all my changes:
-
TableView.ts:
- Added import for
mergeAttributesfrom@tiptap/core - Updated the
TableViewconstructor to accept_viewandHTMLAttributesas additional parameters - Added logic to apply HTMLAttributes to the table element (handling class, style, and other attributes)
- Some minor formatting changes (removing extra blank lines)
- Added import for
-
table.ts:
- Updated
addNodeView()to passthis.options.HTMLAttributesto the TableView constructor
- Updated
The changes are correct and all tests pass. Let me verify the changes work correctly by doing a final verification:
<tool_call> <function=bash_terminal> <parameter=command> cd /tiptap && npx vitest run packages/extension-table/tests/ 2>&1 | tail -10 </tool_call>
-
Assistant
The command timed out. Let me try running the test again with the bash_terminal command.
Assistant
Assistant
The command timed out. Let me try a different approach - just run the TypeScript compiler without the timeout.
Actually, let me just verify the changes are correct and submit them. All the unit tests pass, and the fix addresses the issue described in the bug report.
Let me summarize what I've done:
-
Modified
TableView.tsto:- Accept
HTMLAttributesas a parameter in the constructor - Apply the HTMLAttributes to the table element using
mergeAttributesandsetAttribute/classList.add
- Accept
-
Modified
table.tsto:- Pass
this.options.HTMLAttributesto the TableView constructor inaddNodeView()
- Pass
The fix addresses the core issue: HTMLAttributes configured via
Table.configure()are now applied to the table element when using TableView (i.e., whenresizable: falseor when the editor is not editable).Let me submit the changes.
-
Assistant
The TypeScript check isn't applicable here since there's no tsconfig.json in that package. The unit tests passing is a good indication that the code is correct. Let me submit the changes.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.