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
I'll start by exploring the repository structure to understand the codebase and locate the relevant files. Let's first get an overview.
- Assistant
Let me explore the TableView file first, as that's where the issue is according to the bug report.
- Assistant
Now let me look at the table.ts file to see the addNodeView method and how HTMLAttributes are used.
- Assistant
Let me see the full table.ts file:
- Assistant
Let me look at the
addNodeView()method more closely and theViewtype: - Assistant
Let me check how
columnResizinguses the View option: - Assistant
Let me look at the prosemirror-tables types to see how the View is used there.
- Assistant
Let me first create a reproduction script to verify the bug:
- Assistant
Now I need to understand how
columnResizingplugin also uses the View. Let me check how it creates the NodeView: - Assistant
Let me check if
columnResizingplugin also creates its own views when resizable is true. Let me look at how it's configured in table.ts: - Assistant
Now I understand the issue completely. Let me also check how
TableViewis exported and used elsewhere: - Assistant
Let me look at how
addNodeViewis used in the core: - Assistant
Let me look at the Node.ts file to understand the type definition for addNodeView:
- Assistant
Now I understand the issue. Let me create a reproduction script to verify the bug:
- Assistant
Now I understand the issue. Let me look at what the
columnResizingplugin fromprosemirror-tablesdoes when it creates the View: - Assistant
Now I have a clear understanding of the issue. Let me check if there are existing tests for the table extension:
- Assistant
Let me check the test files to understand the testing patterns:
- Assistant
Now I understand the issue clearly. Let me create a reproduction script first to verify the bug:
- Assistant
Now let me understand how
columnResizingfrom prosemirror-tables creates the View. Let me look at its source: - Assistant
Now I see the issue clearly. The
columnResizingplugin fromprosemirror-tablescreates Views with the signaturenew View(node, defaultCellMinWidth, view)and we can't change that. The tiptapaddNodeView()also creates Views with the same signature.The solution is to:
- Modify
TableViewconstructor to accept an optionalHTMLAttributesparameter - Apply those attributes to the
<table>element in the constructor - Update
addNodeView()intable.tsto passthis.options.HTMLAttributesto the View constructor - Update the
Viewtype inTableOptionsto accept the 4th parameter
Since
columnResizingwon't passHTMLAttributes, we need to make it optional with a default of{}. Let me now implement the fix. - Modify
- Assistant
Now let me check what
mergeAttributesdoes so I know how to properly apply the attributes: - Assistant
Let me see the full
TableViewclass: - Assistant
Now I have a clear understanding of the issue and the fix needed. Let me implement the fix:
- Modify
TableViewconstructor to accept an optionalHTMLAttributesparameter and apply it to the<table>element - Update
addNodeView()intable.tsto passthis.options.HTMLAttributesto the View constructor - Update the
Viewtype inTableOptionsto accept the optionalHTMLAttributesparameter
Let me start with the
TableViewfix: - Modify
- Assistant
Wait, I need to reconsider the approach. The issue is that
columnResizingplugin fromprosemirror-tablesalso creates the View withnew View(node, defaultCellMinWidth, view). The prosemirror-tables source shows it callsnew View(node, defaultCellMinWidth, view)with only 3 args. We can't change that.Let me check how
columnResizingcreates the View: - Assistant
Let me understand the full picture. Let me check the
addProseMirrorPluginsto see how the View is passed to columnResizing: - Assistant
Now I understand the full picture. Let me implement the complete fix:
- The
TableViewconstructor now accepts an optionalHTMLAttributesas a 4th argument - I need to update
addNodeView()to passthis.options.HTMLAttributes - I need to update the
Viewtype inTableOptions
Let me also apply
HTMLAttributesto thedomwrapper (thediv.tableWrapper) since that's also part of the rendered output. Actually, looking at therenderHTMLintable.ts, theHTMLAttributesare only applied to the<table>element, not the wrapper. So my fix is correct.Now let me update the
addNodeView()method: - The
- Assistant
Now I need to update the
Viewtype inTableOptionsto accept the optionalHTMLAttributesparameter: - Assistant
Now I need to update the
Viewtype inTableOptionsto accept the optionalHTMLAttributesparameter. Let me update the type: - Assistant
Now I need to also handle the resizable case. When
resizable: true, thecolumnResizingplugin creates the View with only 3 args(node, cellMinWidth, view), not passingHTMLAttributes. I need to wrap the View inaddProseMirrorPluginsto pass HTMLAttributes: - Assistant
Now I need to also handle the resizable case. When
resizable: true, thecolumnResizingplugin creates the View with only 3 args. I need to wrap the View inaddProseMirrorPluginsto pass HTMLAttributes: - Assistant
Actually, the class wrapper approach is fragile. Let me use a simpler factory function approach for the resizable case:
- Assistant
Actually, the wrapper class approach for the resizable case is too complex and might break other methods. The issue report specifically mentions the non-resizable case as the regression. Let me revert the
addProseMirrorPluginschange and keep it simple: - Assistant
Now let me run the existing tests to make sure I haven't broken anything:
- Assistant
Let me wait for the build to complete and then check the test results:
- Assistant
Good, the build succeeded. Now let me run the tests for the extension-table package:
- Assistant
Let me find the correct way to run tests:
- Assistant
Let me check where the test files are located:
- Assistant
Let me run the tests from the root directory:
- Assistant
All tests pass. Now let me verify my fix by creating a temporary test script to reproduce the issue and confirm the fix:
- Assistant
Let me verify the current state of both files to make sure my changes are correct:
- Assistant
Wait, I need to reconsider the resizable case. The
columnResizingplugin creates the View with only 3 args, soHTMLAttributeswon't be passed. Let me wrap the View properly for the resizable case: - Assistant
Now let me rebuild and run the tests again to make sure everything works:
- Assistant
Build succeeded. Let me run the tests again to make sure everything still passes:
- Assistant
All tests pass. Let me verify my changes by looking at the diff:
- Assistant
Let me check if there are any edge cases I should consider. Let me verify the changes one more time:
- Assistant
Let me run all existing tests one more time to confirm everything passes:
- Assistant
All 44 tests pass. Let me do a final review of my changes:
- Assistant
Let me now do a final review of the changes I made to ensure they're correct and complete:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.