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); }When
resizableis false (default) andViewis the defaultTableView, this returns a NodeView.TableViewbuilds the DOM manually:constructor(node, cellMinWidth) { this.dom = document.createElement("div"); this.dom.className = "tableWrapper"; this.table = this.dom.appendChild(document.createElement("table")); if (node.attrs.style) { this.table.style.cssText = 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")); }TableViewnever readsthis.options.HTMLAttributes. The schema-levelrenderHTML(which does callmergeAttributes(this.options.HTMLAttributes, HTMLAttributes, ...)) is bypassed whenever the NodeView is active.Workaround
Table.configure({ HTMLAttributes: { class: 'my-custom-table' }, View: null })This disables the NodeView and falls back to the schema's
renderHTML. Side effect: losesTableView's in-placeupdate(node)column-width sync; a full re-render happens on attribute changes instead. Acceptable for most read-only or non-resizable use cases.Related
#6176 reports a similar symptom on Tiptap 2.11.5 with
resizable: true. Different mechanism (noaddNodeViewin 2.x), same user-facing impact.Dependency Updates
- Yes, I've updated all my dependencies.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /tiptap, current file: none) bash-$
- Assistant
I'll start by exploring the repository to understand its structure and locate the relevant files for the issue. The bug is about
@tiptap/extension-tablewhereHTMLAttributesis not being applied to the<table>element whenresizable: false(default) becauseTableViewdoesn't readthis.options.HTMLAttributes. The issue is in theaddNodeView()method and theTableViewconstructor.Let's first check the current directory and see what we have.
- Assistant
Let me look at the relevant files to understand the issue.
- Assistant
Now let's look at the table extension itself to see the
addNodeViewmethod. - Assistant
Let me check how
columnResizingfrom prosemirror-tables uses the View option: - Assistant
Let me check the prosemirror-tables types to see what signature View expects.
- Assistant
Let me find the View type definition in prosemirror-tables.
- Assistant
Let me check the TableOptions defaults and the types:
- Assistant
Now let me see the full
renderHTMLmethod: - Assistant
Now let me check what
mergeAttributesdoes and what's available: - Assistant
Now I have a clear understanding of the issue. Let me check how
mergeAttributesworks: - Assistant
Now I have a complete understanding of the issue. Let me plan the fix:
Root cause:
TableView's constructor manually builds DOM elements but never appliesthis.options.HTMLAttributesto the<table>element. TheaddNodeView()method creates aTableViewwithout passingHTMLAttributes, and since the NodeView bypassesrenderHTML, the HTMLAttributes are lost.Fix plan:
- Update
TableViewconstructor to accept an optionalHTMLAttributesparameter and apply them to the<table>element - Update
addNodeView()intable.tsto passHTMLAttributeswhen creating the NodeView - Update
addProseMirrorPlugins()to wrap the View for the resizable case to also inject HTMLAttributes
Let me start by modifying
TableView: - Update
- Assistant
Now let me check if @tiptap/core is a dependency of extension-table:
- Assistant
Let me look at the package.json.
- Assistant
Now I understand the issue completely. Let me implement the fix:
- The
TableViewconstructor doesn't accept or applyHTMLAttributes - The
addNodeView()method bypassesrenderHTML, so HTMLAttributes are lost - Same issue exists for the resizable case via
columnResizing
I'll fix this by modifying
addNodeView()andaddProseMirrorPlugins()to apply HTMLAttributes to the table element after NodeView construction. - The
- Assistant
Let me look at the
columnResizingtype more closely: - Assistant
Let me look at the columnResizing type more carefully.
- Assistant
Let me understand the full issue now. I need to look at how the
Viewtype is defined and how to properly passHTMLAttributes: - Assistant
Let me look at the whole TableOptions definition and the addNodeView method:
- Assistant
Now I have a full understanding of the issue. Let me implement the fix:
- Modify
TableViewto accept an optionalHTMLAttributesparameter and apply them to the<table>element - Modify
addNodeView()to passHTMLAttributesto the View constructor - Modify
addProseMirrorPlugins()to wrap the View so that HTMLAttributes are passed when using resizable tables
The approach: Since the
Viewtype is(new (node, cellMinWidth, view) => NodeView), I need to handle passing the 4th parameter. The cleanest way is to apply HTMLAttributes inside theaddNodeView()callback after creating the view, and similarly for thecolumnResizingwrapper.Let me implement this:
- Modify
- Assistant
Now I have a full understanding. The fix needs to:
- Modify
TableViewto accept an optionalHTMLAttributesparameter and apply them to the<table>element - Modify
addNodeView()to passHTMLAttributesto the View - Handle the resizable case in
addProseMirrorPlugins()wherecolumnResizingcreates the View
The
Viewtype expects(node, cellMinWidth, view)butTableViewonly uses(node, cellMinWidth). I'll modifyTableViewto acceptHTMLAttributesas an optional parameter and apply them in the constructor. Then I'll update both call sites.Let me implement the fix:
- Modify
- Assistant
I need to use the correct format for the edit command. Let me use the
editcommand with proper syntax. - Assistant
I see the issue - I removed the lines for
this.colgroupandthis.contentDOM. Let me fix this. - Assistant
There's a duplicate block now. Let me fix the file properly by looking at the current state:
- Assistant
I see the duplicate block. Let me fix the file:
- Assistant
Now let me fix the formatting - add a blank line between the constructor and the
updatemethod: - Assistant
Good, now I need to update the
addNodeView()method intable.tsto passHTMLAttributesto the View constructor. I also need to handle the resizable case wherecolumnResizingcreates the View. Let me updatetable.ts: - Assistant
Wait, I realize there's a problem. The
Viewtype passes(node, cellMinWidth, view)as constructor arguments, butTableViewonly takes(node, cellMinWidth). If I addHTMLAttributesas the3rd parameter, it would receiveviewinstead. Let me revert the TableView change and instead take a different approach.The cleanest fix: Apply HTMLAttributes after construction in
addNodeView()and in thecolumnResizingwrapper. Let me revert the TableView change: - Assistant
Now I need to think about the best approach. The
Viewtype takes(node, cellMinWidth, view)- if I addHTMLAttributesas a3rd parameter toTableView, it would receiveviewinstead. So I need a different approach.The cleanest fix: Modify
addNodeView()andaddProseMirrorPlugins()to applyHTMLAttributesafter creating the NodeView. This way:TableViewdoesn't need to change its constructor signature- Both the non-resizable case (via
addNodeView()) and the resizable case (viacolumnResizingplugin) are fixed
Let me implement this in
table.ts: - Assistant
Now I need to:
- Create the
applyHTMLAttributesToTablehelper function - Update
addProseMirrorPlugins()to wrap the View for the resizable case - Make sure everything is properly imported
Let me update
addProseMirrorPlugins()first: - Create the
- Assistant
Now I need to add the
applyHTMLAttributesToTablehelper function. Let me first check what's imported at the top of the file: - Assistant
Good,
mergeAttributesis already imported. Now I need to add theapplyHTMLAttributesToTablehelper function. Let me also check if we need theEditorViewtype: - Assistant
Now I need to add the
applyHTMLAttributesToTablehelper function. Let me find a good place to add it: - Assistant
Let me add the
applyHTMLAttributesToTablehelper function after the imports and before the MarkdownTableToken type: - Assistant
The file has some corruption - there are duplicate imports and the function was inserted in the wrong place. Let me restore the file and start fresh:
- Assistant
Let me take a better approach. Let me first create a helper function, then modify the two methods separately:
- Assistant
Let me first look at the exact lines for addProseMirrorPlugins and addNodeView:
- Assistant
Now I have a clear picture. Let me think about the best approach. I need to:
- Add a helper function
applyHTMLAttributesToTablethat applies HTMLAttributes to a TableView's table element - Modify
addNodeView()to call this helper after creating the node view - Modify
addProseMirrorPlugins()to wrap the View for the resizable case
Let me implement this step by step. First, add the helper function right after the imports, before the MarkdownTableToken type:
- Add a helper function
- Assistant
I see the MarkdownTableToken type is missing its body. Let me fix that:
- Assistant
The MarkdownTableToken type is broken. Let me fix it:
- Assistant
Good. Now let me update the
addNodeView()andaddProseMirrorPlugins()methods. Let me find them: - Assistant
Now let me update
addNodeView(): - Assistant
Now I need to update
addProseMirrorPlugins()to wrap the View for the resizable case: - Assistant
The file looks good. Let me verify the full file to make sure everything is correct:
- Assistant
Now let me try to build to see if there are any TypeScript errors:
- Assistant
Let me try using pnpm instead:
- Assistant
Let me try to build using pnpm directly:
- Assistant
Let me try a TypeScript check instead:
- Assistant
Let me check the build setup:
- Assistant
Let me check for existing tests and verify the fix looks correct:
- Assistant
Let me check if there are tests related to HTMLAttributes or TableView:
- Assistant
Let me look at one of the existing tests to understand the test setup:
- Assistant
Let me look at the full test to understand how tests work:
- Assistant
Let me run the existing tests to make sure my changes don't break anything:
- Assistant
All tests pass. Now let me create a reproduction script to verify the fix works:
- Assistant
The test needs a DOM environment. Let me write a test file and run it with vitest:
- Assistant
Now let me run the test to see if the fix works:
- Assistant
All tests pass, including the new HTMLAttributes test and the resizable case. Let me also run all existing tests to make sure nothing is broken:
- Assistant
All 38 tests pass (34 existing + 4 new). Let me clean up the test file since the instructions say not to add new tests to the repository:
- Assistant
Let me verify the final state of the modified file:
- Assistant
Good, only one file was modified. Let me see the full diff to review:
- Assistant
The diff looks clean and correct. Let me run the existing tests one final time to confirm everything is still passing:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-lunaCompare side by side →
- gpt-5.6-lunaCompare side by side →