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, version 3.23.x. The issue is that when configuring the Table extension withHTMLAttributes, those attributes are not being applied to the rendered<table>element whenresizable: false(which is the default).The root cause is that version 3.23 introduced
addNodeView()which bypasses the schema'srenderHTML. TheTableViewclass builds the DOM manually and never readsthis.options.HTMLAttributes.Let me first explore the repository structure to find the relevant files.
Assistant
I found the relevant files. Let me look at the
TableView.tsfile and the maintable.tsfile to understand the current implementation.Assistant
Now let me look at the main table extension file to see how
addNodeView()is implemented:Assistant
Now I understand the issue. The problem is in the
addNodeView()method. Let me trace through the logic:- In
addNodeView(), whenresizable: false(default) andViewis the defaultTableView, it returns a NodeView function. - The
TableViewconstructor doesn't usethis.options.HTMLAttributesat all - it only appliesnode.attrs.style. - The
renderHTMLmethod does correctly mergethis.options.HTMLAttributes, but it's bypassed when the NodeView is active.
The fix needs to be in the
TableViewconstructor to applythis.options.HTMLAttributesto the table element.But wait, I see a potential issue - the
TableViewconstructor doesn't receivethis.optionsas a parameter. Let me check the signature:return ({ node, view }) => new View(node, this.options.cellMinWidth, view)So the
TableViewconstructor receives:node,cellMinWidth, and .- In
Assistant
Let me continue looking at the TableView file and understand the changes needed.
Assistant
Now I need to:
- Modify the
TableViewconstructor to acceptHTMLAttributesas a third parameter - Apply those
HTMLAttributesto the table element - Modify the
addNodeView()method intable.tsto passthis.options.HTMLAttributesto the TableView constructor
Let me first create a test script to reproduce the issue:
<tool_call> <function=bash_terminal> <parameter=command> cd /tiptap && ls -la </tool_call>
- Modify the
Assistant
Let me check the package structure to understand how to run tests or build the project.
Assistant
Now let me look at the existing tests for the table extension to understand the testing setup.
<tool_call> <function=bash_terminal> <parameter=command> find /tiptap/packages/extension-table -name ".spec.ts" -o -name ".test.ts" 2>/dev/null </tool_call>
Assistant
Let me find test files for the extension-table package.
Assistant
Let me look at one of these test files to understand how tests are structured.
Assistant
Assistant
Let me try again with the proper command syntax to modify the TableView.ts file.
Assistant
Now let me update the
table.tsfile to pass theHTMLAttributesto theTableViewconstructor:Assistant
I see the
addNodeView()method. I need to modify it to passthis.options.HTMLAttributesas a third parameter to theViewconstructor. Currently, it passes:node
Assistant
Let me get the line number for addNodeView and then modify it.
Assistant
Now let me view the lines around
addNodeViewto understand the context better:Assistant
Now I need to modify line 534 to pass
HTMLAttributesinstead ofview. Let me use the edit command to make this change.Assistant
Let me verify that the change was made correctly.
Assistant
Now let me check the TableView.ts file and remove the unused import:
Assistant
I added
mergeAttributesimport but I didn't actually use it. Let me remove that unused import:Assistant
Now let me verify the changes by viewing the updated files:
Assistant
Good, the
mergeAttributesimport has been removed. Now let me check the rest of the file to make sure the constructor is correct.Assistant
Let me see the rest of the constructor to verify it's correct:
Assistant
Now let me run the existing tests for the extension-table package to make sure the changes don't break anything:
Assistant
Let me try running the tests directly with vitest instead:
Assistant
Let me check if there's a build step needed first, and try building the extension-table package:
Assistant
Let me check if there's a TypeScript compilation issue with my changes:
Assistant
These errors seem to be from other parts of the codebase, not from the extension-table package. Let me specifically check for errors in the TableView.ts file:
<tool_call> <function=bash_terminal> <parameter=command> cd /tiptap/packages/extension-table && npx tsc --noEmit src/table/TableView.ts 2>&1 </tool_call>
Assistant
Let me run the command to check for TypeScript errors in the TableView.ts file.
Assistant
Assistant
Let me use a simpler approach to update the file - I'll directly write the content using a shell command.
Assistant
Let me wait for the output.
<tool_call> <function=bash_terminal> <parameter=command> npx tsc --noEmit src/table/TableView.ts 2>&1 | grep "src/table/TableView.ts" </tool_call>
Assistant
Let me run the command properly to check the TypeScript compilation errors.
Assistant
The error is still showing. Let me check if the file was actually updated:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '100,115p' /tiptap/packages/extension-table/src/table/TableView.ts </tool_call>
Assistant
The command isn't being recognized. Let me try running it without any additional arguments.
Assistant
Assistant
The terminal seems to have some issue with the commands. Let me try a simpler approach.
Assistant
The command executed successfully. Now let me verify that the file was updated correctly:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '100,120p' /tiptap/packages/extension-table/src/table/TableView.ts </tool_call>
Assistant
The command didn't execute properly. Let me try again with the correct syntax.
Assistant
The file has been updated. Now let me verify the TypeScript compilation for the TableView.ts file:
<tool_call> <function=bash_terminal> <parameter=command> npx tsc --noEmit src/table/TableView.ts 2>&1 | grep -E "TableView.ts" </tool_call>
Assistant
The command seems to not be executing properly. Let me try a different approach - maybe the prompt is waiting for input or there's something wrong with the command.
Assistant
The command executed but there was no output for TableView.ts errors, which is good! It means there are no TypeScript errors in the TableView.ts file. Let me now check if there are any errors in the table.ts file:
<tool_call> <function=bash_terminal> <parameter=command> npx tsc --noEmit src/table/table.ts 2>&1 | grep "table.ts" </tool_call>
Assistant
The command seems to be executing but not showing output properly. Let me try a simpler approach to verify the changes work.
Assistant
These errors are about module resolution, not about the actual changes I made. The module errors are likely because we're running tsc from the wrong directory. Let me verify the changes in table.ts:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "new View" /tiptap/packages/extension-table/src/table/table.ts </tool_call>
Assistant
Let me try the grep command again.
Assistant
The change was applied correctly. Now let me create a test script to verify the fix works:
Assistant
The command has been executed.
<tool_call> <function=bash_terminal> <parameter=command> cd /tiptap && node test-html-attributes.js </tool_call>
Assistant
Let me try running the node command from the tiptap directory.
Assistant
The jsdom module is not available. Let me create a simpler test script that doesn't require jsdom:
<tool_call> <function=bash_terminal> <parameter=command> rm /tiptap/test-html-attributes.js </tool_call>
Assistant
Let me check how the tests are structured and run them:
Assistant
Now I understand how the tests work. Let me create a test file for the HTMLAttributes bug to verify my fix. But first, let me check if there's already a test for HTMLAttributes.
<tool_call> <function=bash_terminal> <parameter=command> grep -r "HTMLAttributes" /tiptap/packages/extension-table/tests/ 2>/dev/null </tool_call>
Assistant
Let me run the grep command properly.
Assistant
The grep returned exit code 1, which means there are no matches for HTMLAttributes in the test files. This confirms that there's no existing test for this issue.
Now let me add a test case to verify that HTMLAttributes are correctly applied. But first, let me look at how the existing tests work to understand the pattern better.
Assistant
Let me first look at the test structure more carefully to understand how to add a test for this fix:
Assistant
Now I have a clear understanding of the test structure. Let me create a new test file for testing the HTMLAttributes fix. I'll add a test that verifies the class and other attributes are applied to the table element.
Actually, instead of adding a new test file, let me first verify that my fix is correct by examining the code and then running the existing tests to make sure I didn't break anything.
Let me check if there's a way to run a single test file or a specific test:
<tool_call> <function=bash_terminal> <parameter=command> cd /tiptap && pnpm test --filter @tiptap/extension-table -- colgroupUpdate 2>&1 | head -50 </tool_call>
Assistant
Let me try running the tests using a different approach:
Assistant
Assistant
The command isn't working correctly. Let me try a different approach to look at the prosemirror-tables source.
Assistant
Let me look at the prosemirror-tables source to understand how it uses TableView.
Assistant
This is not the right section. Let me look for the TableView class specifically in the prosemirror-tables source.
<tool_call> <function=bash_terminal> <parameter=command> grep -n "TableView" node_modules/.pnpm/prosemirror-tables@1.6.4/node_modules/prosemirror-tables/dist/index.js | head -20 </tool_call>
Assistant
The command is not working properly. Let me try a different approach.
Assistant
Let me look at the TableView class definition around line 1895:
Assistant
Interesting! The prosemirror-tables TableView constructor takes
nodeanddefaultCellMinWidthas parameters. It doesn't take a third parameter like thevieweditor. So the error might be coming from somewhere else.Let me check line 1973 where
View = TableViewis defined:Assistant
Assistant
Assistant
The cp command might have executed. Let me verify the file was updated correctly.
Assistant
The file was not updated. Let me try using a different approach - using sed to replace the specific lines.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '85,125p' /tiptap/packages/extension-table/src/table/TableView.ts </tool_call>
Assistant
The command is not being recognized properly. Let me try a simpler approach to update the file.
Assistant
I need to update the TableView constructor to handle both the
addNodeView()case (passing HTMLAttributes) and thecolumnResizingplugin case (passing editor view). Let me write the updated file:Assistant
The file was created successfully. Let me verify the changes:
Assistant
The TableView constructor has been updated. Now let me run the tests again to verify the fix works for both cases:
Assistant
All tests passed. Let me now run all the extension-table tests to ensure I didn't break anything else:
Assistant
All tests pass. Now let me create a test specifically for the HTMLAttributes bug to verify my fix:
Assistant
Now let me run the tests again to verify that my fix works for the HTMLAttributes bug:
Assistant
There's one failing test:
applies HTMLAttributes class when resizable: true. This is expected because whenresizable: true, the columnResizing plugin uses its own TableView that doesn't apply HTMLAttributes.Looking at the test output, when
resizable: false, the HTMLAttributes are correctly applied. But whenresizable: true, they are not. This is because the columnResizing plugin from prosemirror-tables creates its own NodeView that doesn't use Tiptap's HTMLAttributes.To fix this for the
resizable: truecase, I need to make the columnResizing plugin use the Tiptap TableView with HTMLAttributes. Let me check how the columnResizing plugin is configured:<tool_call> <function=bash_terminal> <parameter=command> sed -n '498,520p' /tiptap/packages/extension-table/src/table/table.ts </tool_call>
Assistant
I need to find where the columnResizing plugin is configured and ensure it uses the Tiptap TableView with HTMLAttributes. Let me locate the columnResizing configuration.
Assistant
Let me look at the columnResizing configuration more closely.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '505,520p' /tiptap/packages/extension-table/src/table/table.ts </tool_call>
Assistant
Let me try again to view the columnResizing configuration.
Assistant
Assistant
Assistant
Let me try to view the table.ts file to understand the structure better.
Assistant
I need to modify the
columnResizingplugin configuration to pass a custom View that applies HTMLAttributes. Let me create a wrapper View that applies HTMLAttributes after construction.Assistant
Now let me look at the full table.ts file to understand where to add this helper function and how to modify the columnResizing configuration:
Assistant
I need to import the EditorView type. Let me check the imports and then modify the table.ts file to add the helper function and update the columnResizing configuration.
Assistant
I see that
EditorViewandNodeVieware already imported from@tiptap/pm/view. Now I need to add the helper function and modify the columnResizing configuration.Let me first understand where the columnResizing configuration is in the file. I saw it was around line 508. Let me find the exact location and add the helper function before it.
Assistant
Let me see the full addProseMirrorPlugins method to understand where to add the helper function:
Assistant
Now I understand the structure. I need to:
- Add a helper function before
addProseMirrorPluginsto wrap the View with HTMLAttributes - Modify the columnResizing configuration to use this wrapped View
Let me create the modified table.ts file. First, let me backup and then apply the changes:
- Add a helper function before
Assistant
Now let me modify the table.ts file to add the helper function and update the columnResizing configuration. I'll insert the helper function before the
addProseMirrorPluginsmethod.Assistant
I'll add the helper function after line 500 (after the
addKeyboardShortcutsmethod closes). Let me insert the helper function:Assistant
The sed command might not have worked correctly. Let me check the file:
Assistant
The helper function was added. Now I need to modify the columnResizing configuration to use
getViewWithHTMLAttributes(this.options.View)instead of justthis.options.View.Assistant
I see the line
View: this.options.View,. I need to change it to use the wrapped view. Let me update it:Assistant
Let me verify the change:
Assistant
The change was applied. Now I need to also add the
ViewMutationRecordimport since I'm using it in the helper function. Let me check the imports:Assistant
I need to import
ViewMutationRecordfrom@tiptap/pm/view. Let me update the import:Assistant
Now let me verify the import was updated correctly:
Assistant
Let me check the line after:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '32p' /tiptap/packages/extension-table/src/table/table.ts </tool_call>
Assistant
Let me check the import line more carefully.
Assistant
The import was updated correctly. Now let me run the tests to verify everything works:
Assistant
The error shows that the helper function was inserted in the wrong place - it's inside a class method instead of at the class level. I need to put the helper function outside of the
Node.createblock. Let me look at the structure of the file to understand where to place the helper function.Assistant
I see the problem. The helper function was added inside the
Node.createblock, which is causing a syntax error. I need to move it outside of the class. Let me restore the original file and take a different approach.Assistant
Let me take a different approach. Instead of adding a helper function inside the Node.create block, I'll create a standalone helper function at the module level (before the
Node.createcall) and use it in theaddProseMirrorPluginsmethod.First, let me find where the
Node.createstarts:Assistant
Now let me see what's before line 256 (the imports and type definitions):
Assistant
Now I need to add the helper function before the
export const Table = Node.createcall. Let me add it after theMarkdownTableTokentype definition (around line 44).Assistant
Now I need to update the import to include
ViewMutationRecordand update thecolumnResizingconfiguration to use the helper function.Assistant
Now let me update the
columnResizingconfiguration to use the helper function:Assistant
Let me verify the changes were made correctly. First, let me check the helper function was added at the correct location:
Assistant
I see there's a problem - the helper function was inserted in the middle of the
MarkdownTableTokentype definition. There's an extra closing brace and the structure is broken. Let me restore the file and try a different approach.Assistant
Let me take a simpler approach - I'll create the entire modified file using a heredoc, ensuring the structure is correct.
Assistant
Let me create the modified table.ts file step by step using a more controlled approach. I'll write the file in sections.
First, let me create the modified import section with the ViewMutationRecord import:
Assistant
Now I need to get the rest of the file (from the TableOptions interface to the end) and append it. Let me extract the remaining parts of the original file:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '48,255p' /tmp/table.ts.backup > /tmp/table_part2.ts cat /tmp/table_part2.ts | head -50 </tool_call>
Assistant
The command is not executing properly. Let me try running it again.
Assistant
Now let me get the rest of the file (from line 256 onwards) and modify the columnResizing configuration:
Assistant
Now let me modify part 3 to update the columnResizing configuration:
Assistant
Now let me combine all parts into the final file:
Assistant
Now let me verify the file was created correctly:
Assistant
Let me verify that the columnResizing configuration was updated:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "View:" /tiptap/packages/extension-table/src/table/table.ts </tool_call>
Assistant
Let me run the grep command to check the columnResizing configuration.
Assistant
The columnResizing configuration was updated correctly. Now let me run the tests to verify everything works:
Assistant
All 38 tests pass. Now let me clean up the test file I added and verify the fix works correctly. Let me remove the test for
resizable: truesince it was just to check that the fix works for that case too.Actually, looking at the test output, all tests passed including my new tests for HTMLAttributes. This means both the
resizable: falseandresizable: truecases are now working correctly.Let me verify the changes I made are correct by reviewing the final state of the files:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "new View" /tiptap/packages/extension-table/src/table/table.ts </tool_call>
Assistant
The command is not executing. Let me try again with the correct syntax.
Assistant
Now let me review the changes to the TableView.ts file to make sure it's correct:
<tool_call> <function=bash_terminal> <parameter=command> head -100 /tiptap/packages/extension-table/src/table/TableView.ts </tool_call>
Assistant
The command seems to not be executing. Let me try again.
Assistant
Let me see more of the TableView constructor to verify the HTMLAttributes handling:
<tool_call> <function=bash_terminal> <parameter=command> cat /tiptap/packages/extension-table/src/table/TableView.ts | sed -n '80,130p' </tool_call>
Assistant
The command seems to be having issues. Let me try a simpler approach to verify the file content.
Assistant
The changes look correct. Let me now run the test again to make sure all tests pass:
<tool_call> <function=bash_terminal> <parameter=command> cd /tiptap && timeout 120 npx vitest run packages/extension-table/tests/ 2>&1 </tool_call>
Assistant
The command doesn't seem to be executing. Let me try again.
Assistant
All 38 tests pass. The fix is working correctly. Let me summarize the changes I made:
-
Modified
TableView.ts:- Added a third parameter
argto the constructor that can be eitherHTMLAttributesor anEditorView - Added logic to detect if the third argument is an
EditorView(by checking for the'dom'property) - If it's not an
EditorView, treat it asHTMLAttributesand apply them to the table element
- Added a third parameter
-
Modified
table.ts:
-
Assistant
The git diff command is not executing properly. Let me try again with the correct syntax.
Assistant
The changes look correct. Let me view the actual diff to make sure everything is as expected:
<tool_call> <function=bash_terminal> <parameter=command> cd /tiptap && git diff packages/extension-table/src/table/TableView.ts </tool_call>
Assistant
The git diff command is not working. Let me try a different approach to see the changes.
Assistant
The changes look correct. Now let me also see the changes to the table.ts file:
<tool_call> <function=bash_terminal> <parameter=command> git diff packages/extension-table/src/table/table.ts </tool_call>
Assistant
The git diff command isn't being recognized properly. Let me try running it again.
Assistant
The changes look correct. Let me also see the rest of the diff for table.ts to make sure the addNodeView method was updated correctly:
<tool_call> <function=bash_terminal> <parameter=command> git diff packages/extension-table/src/table/table.ts | tail -20 </tool_call>
Assistant
The command isn't executing properly. Let me try running it again.
Assistant
I see there's an issue with the table.ts file - the interface TableOptions has duplicate property definitions (HTMLAttributes and resizable appear twice). This is because I incorrectly appended the file. Let me fix this by restoring the original file and applying the changes more carefully.
Actually, looking at the diff more carefully, I see that the file has duplicate properties because I accidentally duplicated the interface definition when combining parts. Let me check the current state of the file and fix it.
<tool_call> <function=bash_terminal> <parameter=command> grep -n "HTMLAttributes:" /tiptap/packages/extension-table/src/table/table.ts </tool_call>
Assistant
The git diff command seems to have an issue with execution. Let me try running the grep command directly.
Assistant
I see the issue - the HTMLAttributes property is defined twice in the TableOptions interface (lines 102 and 116). I need to fix this. Let me view the interface definition and remove the duplicate:
Assistant
I see the issue - the interface definition was duplicated. I need to remove lines 110-121 (the duplicate HTMLAttributes and resizable properties). Let me fix this:
Assistant
Now let me verify the fix:
Assistant
I see there's still a duplicate
resizable: booleanline. Let me fix this properly by removing the duplicate:Assistant
I need to remove line 111 which is the duplicate:
Assistant
Let me also remove the extra
*/comment line that was left behind:<tool_call> <function=bash_terminal> <parameter=command> sed -n '108,115p' /tiptap/packages/extension-table/src/table/table.ts </tool_call>
Assistant
Let me try the sed command again.
Assistant
I need to remove the extra
*/lines. Let me fix this properly:<tool_call> <function=bash_terminal> <parameter=command> sed -i '108,111d' /tiptap/packages/extension-table/src/table/table.ts </tool_call>
Assistant
The command seems to have executed. Let me verify the fix:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '105,125p' /tiptap/packages/extension-table/src/table/table.ts </tool_call>
Assistant
The command is not being recognized. Let me try running it again with the correct syntax.
Assistant
I see there's still an extra
*/line at line 110. Let me remove it:<tool_call> <function=bash_terminal> <parameter=command> sed -i '110d' /tiptap/packages/extension-table/src/table/table.ts </tool_call>
Assistant
The command executed. Let me verify the fix.
Assistant
The extra
*/line is still there. It seems the sed command isn't working correctly. Let me try a different approach - I'll restore the original file and apply the changes more carefully using a Python script.Assistant
Now let me use a Python script to apply the changes more carefully:
Assistant
Python3 is not available. Let me use a different approach - I'll use the Node.js that's available in the environment.
Assistant
The changes were applied successfully. Now let me verify the file is correct by checking the interface definition:
Assistant
The HTMLAttributes property is now only defined once. Let me also verify the interface doesn't have any duplicate properties:
Assistant
Now let me verify the changes look correct by viewing the interface:
Assistant
The interface looks correct now. Let me run the tests to make sure everything works:
Assistant
All 38 tests pass. Now let me verify the final changes by checking the git diff:
Assistant
The changes look correct. Let me also verify that the test file changes include the tests for HTMLAttributes:
Assistant
The test file has tests for both
resizable: falseandresizable: truecases. All tests pass, so the fix is complete.Let me now provide a summary of the changes:
Summary of Changes
1.
packages/extension-table/src/table/TableView.ts- Modified the
constructorsignature to accept an optional third parameterarg: Record<string, any> | unknown - Added logic to detect whether the third argument is an
EditorView(by checking for the'dom'property) - If it's not an , treat it as and apply them to the table element
- Modified the
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.