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 explore the repository structure and find the relevant files.
Assistant
Now I understand the issue. Let me look at the
addNodeViewmethod. TheViewis called asnew View(node, this.options.cellMinWidth, view), butTableView's constructor only takes(node, cellMinWidth). TheTableViewnever appliesthis.options.HTMLAttributes.The issue suggests a minimal fix: have
TableViewapplythis.options.HTMLAttributesto the inner<table>element in its constructor.Let me look at the full picture. The
addNodeViewcreates aViewbut doesn't passHTMLAttributes. The fix should:- Pass
HTMLAttributesto theViewconstructor, OR - Apply
HTMLAttributesin theaddNodeViewitself after creating the view.
Let me look at how the default View is set up, and the
TableViewconstructor signature.Let me look at the truncated part of table.ts to see the default options.
- Pass
Assistant
Let me look at the existing tests for the table extension to understand the expected behavior.
Assistant
Now I understand the test setup. Let me think about the best fix.
The issue is that
TableViewdoesn't applythis.options.HTMLAttributes. The minimal fix is to makeTableViewapply the HTMLAttributes to the table element.The cleanest approach: pass the HTMLAttributes to the
Viewconstructor inaddNodeView, and modifyTableViewto accept and apply them.But the
Viewtype is(new (node, cellMinWidth, view) => NodeView) | null. If we change the signature, custom Views would break.Let me think about the approach the actual tiptap maintainers took. Let me check the git log to see if there's any hint, and check the version.
Actually, let me think about this differently. The issue is that the
addNodeViewreturns aTableViewbutrenderHTML(which applies HTMLAttributes) is bypassed.The most robust fix that mirrors
renderHTMLand handles both resizable and non-resizable: apply the HTMLAttributes in the NodeView. But for the resizable case, the columnResizing plugin's NodeView is used.Let me focus on the approach: modify to apply HTMLAttributes to the View's table element after creating it.
Assistant
Let me look at how
mergeAttributesworks and how the columnResizing plugin instantiates the View.Assistant
Assistant
Let me check the table node's attributes to understand what
HTMLAttributes(per-node attrs) contains inrenderHTML.Assistant
Let me check the table node's
addAttributesto understand what attributes are stored on the node. I don't seeaddAttributesin table.ts. Let me check if the table node has any attributes at all.Assistant
Let me check the full table.ts file to see if there's an
addAttributesor wherestyleattr comes from.Assistant
Let me check the git history of the
addNodeViewand theViewoption to understand what changed in 3.23.Assistant
Let me check the git history of the columnResizing
Viewoption to understand if the resizable case had this bug before.Assistant
Let me check if the table node has a
styleattribute defined anywhere, and look at thecreateColGrouputility.Assistant
Let me look at the columnResizing plugin's View option type and how it's typed.
Assistant
Let me look at how the columnResizing plugin uses the View - whether it does instanceof checks or just constructs it.
Assistant
Let me check if there's an existing helper in core for applying attributes to a DOM element, and look at the utilities folder structure.
Assistant
Let me look at the
resetAttributes.tsto see how tiptap applies/removes attributes to DOM elements, to mirror the approach.Assistant
Let me look at the full props of the columnResizing plugin to understand how it registers the nodeView.
Assistant
Now I have a good understanding. Let me check how tests are run in this repo and write a reproduction script first.
Assistant
Let me check the vitest config and how the table tests set up the DOM environment.
Assistant
Tests use
happy-domenvironment. Let me write a reproduction test to confirm the bug first.Assistant
Both cases fail — the bug is confirmed for both
resizable: falseandresizable: true. Now let me implement the fix.My plan:
- Create a helper
applyHTMLAttributesToElementthat applies HTMLAttributes to a DOM element (handlingclass/stylespecially, mirroringrenderHTML). - In
addNodeView(non-resizable case), apply HTMLAttributes to the View'stableelement after construction. - In
addProseMirrorPlugins(resizable case), wrap theViewpassed tocolumnResizingso HTMLAttributes are applied.
Let me first create the helper utility.
- Create a helper
Assistant
Now let me create the helper utility file.
Assistant
Let me check the build/type-check setup before writing the wrapper.
Assistant
There's a tsconfig with strict mode. Let me create the wrapper utility and then type-check.
Assistant
Now let me check the index/barrel files to understand exports.
Assistant
The
table/index.tsexports some utilities but not all (e.g., colStyle.ts isn't exported). I don't necessarily need to export my new utilities from the public API, since they're internal. But let me check how TableView is exported. Theindex.tsof table exports./table.jswhich exports TableView. Let me check the main index.ts of extension-table.Assistant
TableViewis exported publicly from./table/TableView.js. My new utilities are internal helpers. Now let me update the wrapper's return type to be non-null (since it always returns a constructor when given a base view).Assistant
Now let me modify
table.ts. First, let me view the relevant sections and add the imports.Assistant
Now let me add the imports and modify the
addProseMirrorPluginsandaddNodeViewmethods.Assistant
Now let me modify the
addProseMirrorPluginsandaddNodeViewmethods.Assistant
Now let me update
addNodeViewto use the wrapper too (DRY and consistent).Assistant
Now let me run the formatter to fix line length and formatting, then run the reproduction test.
Assistant
Now let me run the reproduction test to confirm the fix.
Assistant
Both tests pass. Let me run the existing extension-table tests to make sure I didn't break anything.
Assistant
All existing tests pass. Let me extend the reproduction test to cover edge cases (style merge, class persistence after column ops,
View: nullfallback, read-only mode).Assistant
The min-width failure is a test-setup issue:
setupinitializes a 1-column table, theninsertTableadds a second table, andquerySelector('table')returns the first (1-col) table → 25px. Thebackground: redstyle IS applied correctly (that assertion passed). Let me fix the test to use a 3-column content directly.Assistant
All 10 edge-case tests pass. Now let me run the TypeScript type-checker to make sure there are no type errors, since the wrapper uses some casting.
Assistant
The errors are all in
demos/andnode_modules/, none in my files. Let me specifically check my files for any type errors.Assistant
The wrapper's parameters need explicit types (strict mode). Let me fix that.
Assistant
No type errors in my files. Let me re-run the tests to confirm everything still passes.
Assistant
All tests pass. Let me check if
TableKitor other places configure the TableViewand might need the same fix.Assistant
TableKitjust passes options through toTable.configure, so the fix inTablecovers it. Let me check if there are any other tests across the repo that use the Table extension and might be affected.Assistant
Let me run the static-renderer and collaboration-caret tests (which use tables) to make sure nothing breaks.
Assistant
All tests pass. Let me check the changeset convention to add a changeset for this fix.
Assistant
Now let me run the linter on my files to ensure they pass.
Assistant
Linting passes. Let me review all my changes with git diff.
Assistant
Now I need to remove the temporary reproduction test file before submitting (I shouldn't add new tests to the repo). Let me remove it and run the full extension-table test suite once more to confirm.
Assistant
All tests pass. Let me check if the
TableNodeViewConstructortype I exported is actually used anywhere; if not, I'll remove it to avoid dead code.Assistant
The
TableNodeViewConstructortype is unused. Let me remove it to keep the file minimal.Assistant
Let me re-run format, lint, typecheck, and tests one final time to confirm everything is clean.
Assistant
Everything is clean. Let me do a final end-to-end verification by temporarily re-creating the repro test, running it, and removing it.
Assistant
The fix works end-to-end. Let me do a final review of the complete set of changes.
Assistant
Everything looks good. Let me run the full extension-table test suite one final time to confirm nothing is broken.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.