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 exploring the repository structure to understand the codebase.
Assistant
Let me look at the extension-table package.
Assistant
Now let me look at the table.ts file:
Assistant
Let me see the full file:
Assistant
Let me look at the existing tests to understand how to test the fix:
Assistant
Now let me look at the index.ts for the table extension:
Assistant
Let me look at related history. Let me also check the tests for existing functionality:
Assistant
Let me check the table schema for the style attribute:
Assistant
Now I understand. Let me now look at how renderHTML merges HTMLAttributes and figure out the best approach. Let me see what
mergeAttributesdoes:Assistant
Let me look at existing tests for HTMLAttributes in tables:
Assistant
Now let me first reproduce the issue. Let me create a test script:
Assistant
Let me create a test reproduction script:
Assistant
Now I've confirmed the bug. Let me look at the relevant code once more and plan the fix:
Assistant
Let me check how
node.attrs.styleis set:Assistant
Let me check if the table extension defines any addAttributes:
Assistant
Let me check how
Viewis used elsewhere:Assistant
Let me check the columnResizing plugin signature:
Assistant
Let me look at how columnResizing plugin uses the View:
Assistant
Let me look at how columnResizing uses the View in the JS code:
Assistant
Now I have a clear understanding of the issue. Let me implement the fix. The fix involves modifying
TableViewto applyHTMLAttributesto the inner<table>element.Assistant
Now let me modify the TableView to accept HTMLAttributes:
Assistant
Let me try the edit command with the proper syntax:
Assistant
Let me use the replace command instead, which uses heredoc format:
Assistant
Let me use a different approach and rewrite the file:
Assistant
Now let me update table.ts to pass HTMLAttributes:
Assistant
Let me update the View type signature to include HTMLAttributes as an optional 4th param.
Assistant
I'll use sed to update the View type signature:
Assistant
Sed got confused with the special characters. Let me use a different separator:
Assistant
Now let me update the addNodeView method to pass HTMLAttributes:
Assistant
Let me use python to makethis replacement more reliable:
Assistant
Let me use a different approach using awk or sed:
Assistant
Let me use perl for this replacement:
Assistant
Now let me run the tests to see if this fixes the non-resizable case:
Assistant
Now I need to also fix the resizable case. The columnResizing plugin instantiates the View. Let me wrap the View for the resizable case:
Assistant
Now I need to update addProseMirrorPlugins to wrap the View for the resizable case:
Assistant
Let me check what was actually changed:
Assistant
Wait, there's an issue with my wrapper. The
thisin the constructor'ssuper(...)call is referring to the subclass instance, not the parent extension. Let me fix this:Assistant
Let me check what was changed:
Assistant
Now let me run the tests to see if both cases pass:
Assistant
All 3 tests pass. Now let me run all the existing tests for the extension-table package to make sure I haven't broken anything:
Assistant
All 37 tests pass. Let me also run all tests in the repository to make sure I haven't broken anything elsewhere:
Assistant
Let me check what happens with the markdown path:
Assistant
Let me now think about edge cases and run the complete test suite once more:
Assistant
Let me verify this is a pre-existing issue by checking with the original code:
Assistant
Let me restore my fix:
Assistant
Let me check the actual behavior of TableView when renderWrapper is false:
Assistant
Let me clean up my temporary test files:
Assistant
Let me check if the type change is a breaking change for custom Views:
Assistant
Let me check if any TypeScript errors are from my changes:
Assistant
That error is not from my changes - it's an existing issue. Let me check if there are any TypeScript errors inthe extension-table package:
Assistant
Let me check with the actual tsconfig:
Assistant
Good, no TypeScript errors from my changes. Let me clean up and do a final test run:
Assistant
Let me now run all tests in the repository to make sure nothing is broken:
Assistant
Let me check the git status to see what's been changed:
Assistant
Let me run a more thorough test with style combination:
Assistant
Let me clean up the test file and verify everything once more:
Assistant
Let me look at the final diff to verify the changes:
Assistant
Let me run all the tests one final time to confirm everything works:
Assistant
Let me check the test count discrepancy:
Assistant
Both before and after my fix have 1064 tests. So my fix doesn't break anything. Let me verify the final state of the modified files:
Assistant
Let me verify the original issue example works correctly:
Assistant
The original issue example now works correctly. Let me clean up and submit:
Assistant
Let me do a final test run to verify everything works:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.