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 analyze the issue:
- The bug is in
@tiptap/extension-tableversion 3.23.x - When
resizableis false (default), theTableViewNodeView ignoresHTMLAttributes - This is a regression from 3.22.4 where it worked correctly
- The root cause is that
TableViewdoesn't readthis.options.HTMLAttributesin its constructor
Let me first explore the repository structure to understand the codebase.
- The bug is in
Assistant
The key file to look at is
/tiptap/packages/extension-table/src/table/TableView.ts. Let me also look at the table extension file.Let me examine these files:
- TableView.ts - where the bug is
- table/index.ts - the main table extension file with addNodeView
- table/table.ts - the schema file with renderHTML
Assistant
I need to use the
opencommand without the "tool call" format. Let me try again with the proper syntax.Assistant
Let me read the files using bash commands instead.
Assistant
Now let me check the table extension file to see how
addNodeViewand the options are defined:Assistant
Now let me check the main table.ts file:
Assistant
Now I understand the issue. Let me analyze:
TableViewconstructor doesn't receive or applyHTMLAttributes- When
addNodeView()is active (non-resizable case), it bypassesrenderHTMLwhich does applyHTMLAttributes - The fix needs to pass
HTMLAttributestoTableViewand apply them to the table element
Let me also check the types file to understand the View type:
Assistant
Let me check if there are any existing tests related to this:
Assistant
Now I understand the issue completely. The
TableViewconstructor doesn't accept or applyHTMLAttributesfrom the options. Let me also look at the imports and howmergeAttributesis used in the codebase:Assistant
Now I have a complete understanding of the issue. Let me verify if there are other places that instantiate
TableView:Assistant
Let me check the imports at the top of the TableView.ts file:
Assistant
Now I have a clear understanding of the issue. Let me:
- First create a reproduction script to confirm the bug
- Then fix the issue
- Verify the fix works
Assistant
Let me check the package.json to see how to run tests:
Assistant
Now I have a clear understanding of the issue. Let me implement the fix:
Problem: The
TableViewconstructor doesn't accept or applyHTMLAttributesfrom the extension options. WhenaddNodeView()is active (non-resizable case), it bypassesrenderHTMLwhich normally appliesHTMLAttributes.Solution:
- Modify
TableView.tsto accept and applyHTMLAttributes - Modify
addNodeView()intable.tsto passHTMLAttributestoTableView
Let me first look at the full TableView.ts constructor to understand the structure better:
- Modify
Assistant
Now I understand the issue completely. Let me implement the fix:
Problem: The
TableViewconstructor doesn't accept or applyHTMLAttributesfrom the extension options. WhenaddNodeView()is active (non-resizable case), it bypassesrenderHTMLwhich normally appliesHTMLAttributes.Solution:
- Modify
TableView.tsto accept and applyHTMLAttributes - Modify
addNodeView()intable.tsto passHTMLAttributestoTableView
Let me start with the
TableView.tsfix:- Modify
Assistant
Now I have a complete understanding. Let me implement the fix:
- First, update
TableView.tsto acceptHTMLAttributesand apply them to the table element - Then, update
table.tsto passHTMLAttributesto theTableViewconstructor and update the type
- First, update
Assistant
Let me first understand how
mergeAttributesis used in the tiptap codebase:Assistant
Let me look at how mergeAttributes works:
Assistant
I see that
mergeAttributesreturns an object, not a string. I need to apply the attributes to the DOM element directly. Let me look at howrenderHTMLhandles this:Assistant
I understand now. Let me look at how other NodeViews in tiptap apply HTML attributes:
Assistant
Let me look at how the core exports mergeAttributes and check the index.ts to understand what's available:
Assistant
Let me reconsider my approach. I need to:
- Import
mergeAttributesfrom@tiptap/coreinTableView.ts - Add an
htmlAttributesparameter toTableViewconstructor - Apply the htmlAttributes to the table element
- Update the type definition in
table.tsfor theViewoption to accept the extra parameter - Update
addNodeView()to passHTMLAttributestoTableView
Let me also check what the
@tiptap/coreexports:- Import
Assistant
Let me check how the package exports work to make sure mergeAttributes is available:
Assistant
Now let me implement the fix properly. I'll update both files:
Assistant
Now I need to update the
table.tsfile to passHTMLAttributesto theTableViewconstructor. Let me first check the exact line where the View is instantiated:Assistant
I need to update two things in table.ts:
- The type signature for
Viewoption (line 88) - add the htmlAttributes parameter - The
addNodeView()method (line 534) - passthis.options.HTMLAttributesto the View
Let me view the relevant sections:
- The type signature for
Assistant
Now let me update the type signature for
View:Assistant
Now I need to update the
addNodeView()method to passHTMLAttributesto the View constructor.Assistant
Now I need to update the addNodeView method to pass HTMLAttributes to the View constructor. Let me do that with sed.
Assistant
Let me verify the changes made:
Assistant
Good. Now let me verify both changes are correct by looking at the full context of each changed section.
Assistant
The changes look good. Now let me verify the TableView.ts file to make sure it looks correct, and also check if there are any tests I can run to verify the fix works.
Assistant
Now let me verify the changes look correct by checking the full context of the addNodeView method:
Assistant
Now let me build and test the changes. Let me first check the repository structure and how to run tests:
Assistant
Let me build the package and run the tests to verify the fix works:
Assistant
The command timed out because it was waiting for user input. Let me try running it with pnpm already installed or skip the confirmation.
Assistant
It seems pnpm is trying to download and install. Let me wait for it to finish.
Assistant
The pnpm command seems to be hanging. Let me try a different approach - maybe I can use node/npm directly to check if the build works, or let me try running the pnpm command with the --prefer-offline flag.
Actually, looking at this more carefully, I see that the pnpm command is trying to download and show a prompt. Let me try to see if there's already a node_modules directory and if the build has been done before.
Let me also check if there's a simpler way to test - maybe I can just verify the TypeScript compilation without building everything.
Wait, let me try a different approach. The commands are timing out because of the corepack prompt. Let me try to set the environment variable to auto-accept or use npx directly.
Assistant
Let me try a different approach - I'll check if npx or another package manager is available, or disable corepack:
Assistant
Good, node works. Let me try installing pnpm globally with npm and then run the build:
Assistant
Let me try a different approach to verify the changes work:
Assistant
I can see the tools are available. Let me try running the TypeScript compiler directly to check for errors:
Assistant
The TypeScript errors shown are all from demo files and node_modules, not from my changes to the extension-table package. This indicates my changes are syntactically correct. Let me verify by checking if there are any errors specifically in the files I modified.
Assistant
The changes are correct. Let me verify by checking the final state of both modified files:
Assistant
The changes look good. Let me verify the full diff including the table.ts file and then check if there are any existing tests to run:
Assistant
Let me try to run the existing tests for the extension-table package:
Assistant
All 44 existing tests pass. Let me verify the fix is complete by reviewing the changes one more time:
Assistant
The fix is complete. Let me summarize what was done:
Summary of Changes
The bug was that
TableViewNodeView ignoredHTMLAttributesfrom extension options whenresizableis false (the default), because the NodeView bypassedrenderHTMLwhich normally applies these attributes.Files Modified:
-
packages/extension-table/src/table/TableView.ts:- Added import for
mergeAttributesfrom@tiptap/core - Extended the constructor to accept an optional
htmlAttributesparameter - Applied
HTMLAttributesto the table element usingmergeAttributesto properly handle class and style attributes
- Added import for
-
packages/extension-table/src/table/table.ts:- Updated the
Viewtype signature inTableOptionsto accept the newhtmlAttributesparameter - Updated
addNodeView()to passthis.options.HTMLAttributesto the View constructor
- Updated the
Test Results:
- All 44 existing tests pass
- TypeScript compilation shows no errors in the modified files
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.