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
Let me start by exploring the repository structure to understand the codebase.
Assistant
Let me look at the packages directory to find the table extension.
Assistant
Now let me look at the table.ts extension file to understand the addNodeView method.
Assistant
Let me also look at the renderHTML method more closely and the tests directory:
Assistant
Let me look at how the table kit defines the extension and related details:
Assistant
Let me look for similar implementations and how other tiptap view types handle HTML attributes:
Assistant
Now let me look at how the tests are structured to make sure I can write a test for my fix:
Assistant
Let me understand the available mergeAttributes API:
Assistant
Let me look at how other tiptap extensions handle NodeViews with HTMLAttributes:
Assistant
Let me look at the extension-code-block or similar to understand how they apply attributes in NodeViews:
Assistant
Now I have a good understanding. Let me set up a reproduction script and verify the bug first.
Assistant
Now let me write a quick reproduction script to confirm the bug:
Assistant
Now I've confirmed the bug. Let me check what other places construct TableView:
Assistant
Let me look at the renderHTML method, the addNodeView method, and the TableView to understand all the pieces:
Assistant
Let me check git log to see what commits have been made to the TableView:
Assistant
Let me check the relevant type signature for the View option:
Assistant
Now let me implement the fix. I'll go with modifying
TableViewto accept HTMLAttributes and updating the relevant places. Let me start with the TableView:Assistant
Now let me implement the fix. I'll modify
TableViewto acceptHTMLAttributesand apply them to the inner<table>element:Assistant
Let me think about this more carefully and simplify the fix:
Assistant
Now let me update
table.tsto:- Update the View type to accept the 4th parameter
- Pass
this.options.HTMLAttributesto the View constructor
Assistant
Let me use the replace command:
Assistant
Let me run the reproduction test:
Assistant
There's a bug in my fix - some attributes might be objects. Let me fix the helper function:
Assistant
Let me add some debug logs to find out what's happening:
Assistant
Let me remove the debug log and investigate further:
Assistant
Let me look at what's happening:
Assistant
Hmm, the code looks right. The issue must be elsewhere. Let me look at the actual call stack - the error comes from
nodeview packages/core/src/ExtensionManager.ts:260:20. Let me check that code:Assistant
Let me check what's happening - the issue is the value isn't what we expect. Let me debug what's actually being passed:
Assistant
Hmm, the keys are still
'_root', 'focused', 'trackWrites', 'mounted', 'markCursor', 'cursorWrapper', 'lastSelectedViewDesc', 'input', 'prevDirectPlugins', 'pluginViews', 'requiresGeckoHackNode', 'dragging', '_props', 'state', 'directPlugins', 'dispatch', 'dom', 'editable', 'nodeViews'- these are the keys of EditorView!Wait, but my console.log in table.ts never appeared. Let me check why - maybe the addNodeView result isn't being used here. Let me look again:
Actually, looking at the trace from earlier:
code❯ nodeview packages/core/src/ExtensionManager.ts:260:20This is where ExtensionManager wraps my addNodeView result. So my addNodeView result is being called.
But then:
code❯ packages/extension-table/src/table/table.ts:542:7Wait, but the table.ts at line 542 was the new View call. Let me see what line 542 has now (after my modifications):
Assistant
I see the issue!
viewis supposed to be the 3rd parameter, but myTableViewonly takes 3 parameters (node, cellMinWidth, HTMLAttributes). So when we pass(node, cellMinWidth, view, HTMLAttributes), theview(EditorView) ends up in theHTMLAttributesslot!Let me revert the debug code and fix the bug properly:
Assistant
Now let me fix
TableViewproperly to accept theviewparameter as the 3rd argument:Assistant
Now let me fix
TableViewto addviewas the third parameter properly:Assistant
Now let me run the tests again:
Assistant
The fix works! Let me verify edge cases now. Let me also test with resizable: true and other configurations:
Assistant
Let me look at the dependencies more carefully and refine the implementation:
Assistant
Let me check the columnResizing plugin source:
Assistant
Let me take a simpler approach and just use
mergeAttributesfrom@tiptap/core:Assistant
Let me revisit the implementation. The issue is I need to properly merge styles. Let me use
mergeAttributesfrom@tiptap/core:Assistant
Let me take a different approach - use
mergeAttributesfrom@tiptap/corefor cleaner style handling:Assistant
Now let me run the tests:
Assistant
Let me check the table attribute definitions:
Assistant
Let me check if the test was incorrectly written. Let me look at the existing tests to see how they handle style:
Assistant
Let me check what attributes the table actually has:
Assistant
Let me check by debugging:
Assistant
Now let me fix the resizable case. When resizable: true, the columnResizing plugin creates the View directly. I need to wrap the View to apply HTMLAttributes:
Assistant
Now let me update table.ts to wrap the View when passing to columnResizing:
Assistant
Let me take a step back. I'll take a simpler approach: apply HTMLAttributes to the view's inner
tableafter the view is constructed. This works regardless of how the view is constructed.Let me first revert the TableView to a clean state and apply HTMLAttributes in addNodeView and wrap them for columnResizing:
Assistant
Now let me update
table.tsto use this wrapper:Assistant
I need to fix the import - I used
applyTableHTMLAttributesbut I didn't export it. Let me update TableView.ts:Assistant
Now let me also update the table.ts to import
applyTableHTMLAttributes:Assistant
Now let me run the tests again:
Assistant
Let me debug:
Assistant
Let me check the cell parsing of colwidth:
Assistant
The prosemirror-tables library uses
data-colwidthto parse colwidth, not thecolwidthattribute. So the colwidth attr in my test HTML is NOT being parsed.The existing test in colgroupUpdate uses this format:
ts'<table><tbody><tr><td colwidth="100">A</td><td colwidth="200">B</td><td colwidth="300">C</td></tr></tbody></table>'And expects:
tsexpect(widthsOf()).toEqual(['100px', '200px', '300px'])So the col IS getting the right width. Let me check more carefully. Maybe the prosemirror-tables library uses a different attribute... Wait the existing test uses
colwidth="100"directly. Let me check what's happening:Assistant
Let me re-check the source carefully:
Assistant
Let me take a cleaner approach. I'll modify TableView directly to accept HTMLAttributes, and pass them through both paths:
Assistant
Now let me update table.ts to remove the
applyTableHTMLAttributescall from addNodeView (since it's now done in TableView itself):Assistant
Now let me look at the View type definition and update it to support 4 args:
Assistant
Now let me run the tests:
Assistant
The remaining failing test is based on incorrect assumptions. The table node doesn't have a
styleattribute defined in its schema, sonode.attrs.styleis always undefined. Let me update my test reproduction file:Assistant
All 7 tests pass. Now let me run all the existing tests in the extension-table package to make sure nothing is broken:
Assistant
All the existing tests pass. The 1 failure was in my own debug file. Let me clean up my debug files:
Assistant
Now let me also run the other tests across the codebase to ensure I didn't break anything:
Assistant
All tests pass. Let me also check the starter-kit tests since StarterKit includes the Table extension:
Assistant
All tests pass. Let me now make a final check and look at my changes:
Assistant
Let me check for TypeScript errors:
Assistant
Let me fix the TypeScript error:
Assistant
Let me fix the TypeScript error:
Assistant
The TypeScript error is gone. Let me run all the tests again to make sure everything still works:
Assistant
Let me write a final reproduction test based on the original issue to verify the fix:
Assistant
All 4 verification tests pass. Let me clean up the test file:
Assistant
Let me verify the final state by running all extension-table tests one more time:
Assistant
All 34 existing tests pass. Let me look at the final diff:
Assistant
Let me also do a final reproduction test from the original issue to confirm the fix:
Assistant
The original issue is fixed. Let me clean up:
Assistant
Let me check if my View type signature is compatible with 3-arg constructor:
Assistant
TypeScript accepts the assignment of a 3-arg class to a 4-arg optional type. So my type change is backward compatible. Let me make a final cleanup and run all the tests one more time:
Assistant
All 486 tests pass. Let me clean up and review the final state:
Assistant
The implementation looks clean. Let me also check the changeset directory:
Assistant
Let me run a final verification of all tests:
Assistant
Let me check the unused export:
Assistant
Let me view the final state of the file:
Assistant
The fix is minimal - 117 lines added to TableView.ts and 16 lines changed in table.ts. Let me also check that the AGENTS.md file has any specific guidance for changes:
Assistant
Let me add a changeset for this fix:
Assistant
Let me do a final test run to confirm everything works:
Assistant
Let me run the format and lint checks:
Assistant
No lint or format errors. Let me also check formatting with --check:
Assistant
All checks pass. Let me give a final summary of the changes:
Assistant
Let me provide a quick summary of my reasoning and run one more final test:
Assistant
All 44 tests pass. Now let me address the checklist from the issue description:
Assistant
Now let me do one last comprehensive verification:
Assistant
All 6 comprehensive tests pass! Let me clean up the test file:
Assistant
My fix is complete. Let me submit:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.