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 analyze the issue:
- The bug is in
@tiptap/extension-tableversion 3.23.x - The
TableViewNodeView ignoresHTMLAttributeswhenresizable: false(the default) - This is a regression from 3.22.4 where
addNodeView()didn't exist - The fix should make
TableViewapplythis.options.HTMLAttributesto the inner<table>element
Let me start by exploring the repository structure to find the relevant code.
- The bug is in
Assistant
I found the relevant files. Let me look at:
/tiptap/packages/extension-table/src/table/TableView.ts- The TableView that ignores HTMLAttributes/tiptap/packages/extension-table/src/table/table.ts- The Table extension with addNodeView/tiptap/packages/extension-table/src/table/index.ts- To understand what's exported
Let me examine these files.
Assistant
I need to use the
opencommand without thefileargument key in the way I tried. Let me try a different approach.Assistant
Now let me look at the table extension to see how
TableViewis instantiated and how options are passed:Assistant
Now I understand the issue clearly. Let me examine the full picture:
TableViewconstructor receives(node, cellMinWidth, view)but never appliesHTMLAttributesfrom optionsaddNodeViewintable.tscreatesViewwith onlynode, cellMinWidth, viewbut notHTMLAttributes- The
renderHTMLmethod correctly usesmergeAttributes(this.options.HTMLAttributes, ...)but this is bypassed when NodeView is active
Let me first check the current signature and see the types file too:
Assistant
Now I understand the full picture. Let me check the tests to see what tests exist:
Assistant
Now I have a clear understanding. Let me look at the full table.ts to see the exact line numbers for addNodeView:
Assistant
Now I have a clear picture of the issue. Let me summarize:
Root Cause Analysis:
TableViewconstructor only receives(node, cellMinWidth)but notHTMLAttributesTableViewnever reads or appliesHTMLAttributesto the<table>elementaddNodeView()intable.tsonly passes(node, cellMinWidth, view)to the View constructor- The
renderHTMLmethod correctly usesmergeAttributes(this.options.HTMLAttributes, ...)but this is bypassed when the NodeView is active (which happens whenresizable: false, the default)
Fix Plan:
- Update
TableViewconstructor to accept an optionalhtmlAttributesparameter - Apply
mergeAttributeswithhtmlAttributesto the inner<table>element inTableView - Update
addNodeView()intable.tsto passthis.options.HTMLAttributesto the View constructor
Let me also check the current imports in TableView.ts:
Assistant
Now I understand the full picture. Let me plan the fix:
- In
TableView.ts: Update the constructor to accepthtmlAttributesparameter and apply them to the table element usingmergeAttributes - In
table.ts: Passthis.options.HTMLAttributesto the View constructor
Let me implement this:
- In
Assistant
Assistant
Let me search for mergeAttributes usage in the extension-table package.
Assistant
Assistant
Looking at the existing TableView.ts, it imports
NodeViewandViewMutationRecordfrom@tiptap/pm/view, which already includes theEditorViewtype. Let me check if it's already imported.Assistant
Now I'll implement the fix. Let me edit the TableView.ts file first to add
htmlAttributessupport.Assistant
Let me try using the special edit command with proper formatting.
Assistant
Let me try using the edit command with proper multi-line syntax. I need to be more careful with the formatting.
Assistant
Let me try a different approach with the heredoc syntax for the edit command:
Assistant
Let me use bash commands with sed to make the edits instead.
Assistant
Let me check what the file looks like now.
Assistant
Good, the import was added. Now let me add a blank line and update the TableView constructor. First, let me see the current state of the file with line numbers:
Assistant
Let me first add a blank line between the imports and then update the TableView class:
Assistant
Let me check the current state of the file and then continue with the edits.
Assistant
Good, the imports look properly formatted now. Let me see the TableView class with line numbers:
Assistant
Now let me update the TableView class. I need to:
- Add an
htmlAttributesproperty - Update the constructor to accept
htmlAttributesparameter - Apply
htmlAttributesto the table element
- Add an
Assistant
Let me use a different approach with sed to make these changes:
Assistant
Good, perl is available. Let me use perl to make the edits.
Assistant
Let me check the file state:
Assistant
The perl regex didn't work because of the complex multi-line pattern. Let me take a simpler approach - I'll write the complete file using a heredoc.
Assistant
Let me verify the TableView.ts file was written correctly:
Assistant
TableView.ts has been updated. Now I need to update
addNodeView()in table.ts to passthis.options.HTMLAttributesto the View constructor. Let me check the current state:Assistant
Now let me update
addNodeView()in table.ts to pass the HTMLAttributes:Assistant
Let me verify the change:
Assistant
Now let me verify the changes by running the existing tests and also creating a test to reproduce the original issue.
Assistant
Let me run the tests to see if my changes work correctly. I should run the unit tests first.
Assistant
Let me try a more targeted approach - check if the TypeScript compiles and run a simple verification:
Assistant
The TypeScript errors are from demos and node_modules, not from my changes. Let me try to build just the extension-table package to verify my changes compile correctly:
Assistant
Let me try a simpler verification approach by writing a test script:
Assistant
Let me verify the syntax of my changes by parsing them:
Assistant
Let me look at the existing tests for the table extension and check if I can run them:
Assistant
Let me check if the existing tests still pass and also verify my changes are syntactically correct by trying to import the module:
Assistant
All 34 existing tests pass. Now let me create a test script to verify that the HTMLAttributes fix actually resolves the reported issue:
Assistant
All my verification tests pass. Let me also run the existing test suite one more time to confirm nothing is broken:
Assistant
All 34 tests pass. Let me verify the complete changes I've made:
Assistant
The fix is complete. Let me summarize what was done:
Summary of Changes
Problem
In
@tiptap/extension-table3.23.x, configuring the Table extension withHTMLAttributesno longer applied those attributes to the rendered<table>element whenresizable: false(the default). This was a regression from 3.22.4 whereaddNodeView()didn't exist and the schema'srenderHTMLmethod was used.Root Cause
3.23 added
addNodeView()that returns aTableViewNodeView. Whenresizableis false (the default), this NodeView is used, bypassingrenderHTML. However,TableViewnever read or appliedthis.options.HTMLAttributesto the inner<table>element.Fix (2 files modified)
1.
packages/extension-table/src/table/TableView.ts:- Added import of
mergeAttributesfrom
- Added import of
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.