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
I'll start by exploring the repository structure to understand the codebase and locate the relevant files for the
@tiptap/extension-table. Let's first check the current directory and see what's there. - Assistant
The extension-table package seems to be in a different location. Let me search more broadly.
- Assistant
The main table extension is likely in
./packages/extension-table. Let me explore its structure. - Assistant
Let me explore the table extension's table directory to find the TableView and the main table extension file.
- Assistant
Let me look at the TableView.ts file to understand the current implementation and see how it handles HTMLAttributes.
- Assistant
Now let me look at the table.ts file to see how
addNodeView()is defined and how HTMLAttributes are handled. - Assistant
Let me see the truncated part of table.ts:
- Assistant
Now let me also see the renderHTML part:
- Assistant
Let me look at the renderHTML part of the Table node to understand how it currently handles HTMLAttributes:
- Assistant
Now I understand the issue. The
renderHTMLmethod in table.ts correctly appliesthis.options.HTMLAttributesviamergeAttributes(this.options.HTMLAttributes, HTMLAttributes, ...). However, when theaddNodeViewmethod creates aTableViewinstance, it doesn't passthis.options.HTMLAttributesto theTableViewconstructor. TheTableViewconstructor only usesnode.attrs.stylebut not the extension-levelHTMLAttributes.The fix is to:
- Update the
TableViewconstructor to accept an optionalHTMLAttributesparameter - Apply those attributes to the
<table>element in the constructor - Update the
addNodeViewmethod in table.ts to passthis.options.HTMLAttributesto the View constructor
Let me first check how other NodeViews in this codebase handle HTMLAttributes, to follow the same pattern.
Now let me check how
mergeAttributesis used in the codebase: - Update the
- Assistant
Let me check how
mergeAttributesworks: - Assistant
Let me check the mergeAttributes function to understand how it merges attributes.
- Assistant
Now let me understand how the column resizing plugin uses the View parameter:
- Assistant
Let me check the prosemirror-tables types to understand the View interface:
- Assistant
Now I have a clear picture of the issue. Let me check the
mergeAttributesimport availability inTableView.ts: - Assistant
Let me look at how other node views in the codebase handle HTMLAttributes:
- Assistant
Now let me understand the full picture. The fix needs to:
- Modify
TableViewconstructor to acceptHTMLAttributes - Apply those attributes to the
<table>element usingmergeAttributes - Pass
HTMLAttributesfrom the Table extension to theTableView
Let me also check if there are tests for the table extension:
- Modify
- Assistant
Let me check if there are any tests related to HTMLAttributes or node views for the table:
- Assistant
Let me look at the existing tests:
- Assistant
Let me check the colgroupUpdate test to understand the testing approach:
- Assistant
Now I have a clear understanding of the issue and the codebase. Let me implement the fix:
- Modify
TableViewconstructor to acceptHTMLAttributes - Apply those attributes to the
<table>element - Pass
HTMLAttributesfrom the Table extension inaddNodeView() - Also handle the resizable case in
addProseMirrorPlugins()by wrapping the View
- Modify
- Assistant
Let me check how columnResizing from prosemirror-tables uses the View parameter:
- Assistant
Now I have a complete picture. Let me also check how
mergeAttributesworks with DOM elements (not just for renderHTML output): - Assistant
Let me check how other extensions handle HTMLAttributes in NodeViews:
- Assistant
Let me look at how the mathematics extension handles HTMLAttributes in its NodeView:
- Assistant
Let me continue looking at the BlockMath extension to see how it handles HTMLAttributes in its NodeView:
- Assistant
Let me look at how BlockMath uses
renderHTMLto understand howHTMLAttributesare applied in the schema: - Assistant
Now I understand the full picture. The
TableViewconstructor creates the table DOM but never appliesHTMLAttributes. The fix needs to:- Pass
HTMLAttributestoTableView - Apply them to the
<table>element in the constructor - Update
addNodeView()to pass them - Handle the resizable case too (where
columnResizinguses View)
Let me implement the fix. I'll start by modifying
TableViewto accept and applyHTMLAttributes: - Pass
- Assistant
Now let me modify the TableView constructor to accept HTMLAttributes and apply them:
- Assistant
I see that the constructor is incomplete - it's missing the colgroup and contentDOM initialization. Let me view the full file and fix it:
- Assistant
I see that the constructor is incomplete - it's missing the closing brace and the colgroup/contentDOM initialization. Let me rewrite the whole file correctly:
- Assistant
Now let me update the
addNodeView()method in table.ts to pass HTMLAttributes to the View constructor: - Assistant
I see there's a problem - the
columnResizingplugin calls the View with(node, cellMinWidth, view)but I changed the TableView constructor to accept(node, cellMinWidth, HTMLAttributes). This would break the resizable case. Let me revert the TableView change and instead use a different approach - apply HTMLAttributes after construction: - Assistant
Actually, let me think about this more carefully. The issue is:
- When
resizable: false(default),addNodeView()creates the View and returns it - When
resizable: true,columnResizingplugin creates the View via itsViewoption
In both cases, HTMLAttributes need to be applied to the table element after construction.
The cleanest approach: modify
addNodeView()to apply HTMLAttributes after construction, and wrap the View class foraddProseMirrorPlugins().Let me implement this:
Now let me update the
addNodeView()method in table.ts to pass HTMLAttributes to the View constructor. I also need to handle the resizable case wherecolumnResizingcreates the View: - When
- Assistant
Good. Now I also need to handle the resizable case where
columnResizingcreates the View. Let me updateaddProseMirrorPlugins()to wrap the View with HTMLAttributes: - Assistant
Now I need to add the missing import for
EditorViewandProseMirrorNodetypes. Let me check the existing imports in table.ts: - Assistant
Good - the imports already include
EditorView,NodeView, andProseMirrorNode. Now let me create a reproduction script to verify the bug exists and then test the fix: - Assistant
Let me check if there's a way to run tests in this repo:
- Assistant
Let me check the package.json to understand the test setup:
- Assistant
Let me check the root package.json for test scripts:
- Assistant
Let me check if there are test commands available:
- Assistant
Let me check if there's a vitest config:
- Assistant
Let me run the existing tests to make sure they pass:
- Assistant
All 34 tests pass. Now let me run the tests again to make sure my changes didn't break anything:
- Assistant
All existing tests still pass. Now let me create a test to verify that my fix actually resolves the issue:
- Assistant
Let me place the test file in the correct location:
- Assistant
Now let me run the test again:
- Assistant
All 7 tests pass! Now let me run all the original tests to make sure my changes didn't break anything:
- Assistant
All 41 tests pass, including:
- 34 original tests (all still passing)
- 7 new tests (all passing)
Now let me clean up the test file I created (the issue says not to modify tests):
- Assistant
Now let me review my changes:
- Assistant
Let me also verify that the TableView.ts file is unchanged (since I reverted it):
- Assistant
Good - TableView.ts has no changes. Let me run all the extension-table tests one more time to confirm everything passes:
- Assistant
All 34 original tests pass. Let me review the final state of my changes:
- Assistant
Now let me also think about whether there's a more elegant approach using
mergeAttributesfrom@tiptap/core(which already handles class and style merging): - Assistant
The
mergeAttributesutility works correctly for merging class and style. My implementation already handles this correctly by:- For
class: usingclassList.addwhich adds without replacing existing classes - For
style: appending to existing style text
This is consistent with how
renderHTMLusesmergeAttributes.Let me now also check if there are any other places in the codebase that might be affected by this change, and then run a broader set of tests:
Let me also verify there are no TypeScript compilation errors with my changes:
- For
- Assistant
Let me check the build system:
- Assistant
Let me run a broader set of tests to make sure nothing is broken:
- Assistant
All 1064 tests pass across 117 test files. My fix is working correctly without breaking anything.
Let me review the final state of my changes:
- Assistant
Let me review the full diff one more time to make sure everything is correct:
- Assistant
The fix looks correct. Let me now summarize my changes and submit.
Summary of Changes
I modified
packages/extension-table/src/table/table.tsto fix the bug whereHTMLAttributesconfigured viaTable.configure({ HTMLAttributes: ... })were not being applied to the rendered<table>element.Root Cause
In version 3.23.x, the Table extension added an
addNodeView()method that creates aTableViewNodeView. This bypasses the schema'srenderHTML(which correctly appliesHTMLAttributesviamergeAttributes). TheTableViewconstructor only appliesnode.attrs.stylebut not the extension-levelHTMLAttributes.Fix Applied
I modified two methods in the Table extension:
-
addProseMirrorPlugins()(for resizable tables): Wraps theViewclass to applyHTMLAttributesto the inner<table>element after construction. This handles the case where the plugin creates the NodeView.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.