-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: isNodeEmpty Function Incorrectly Flags Tiptap as Empty When Table Lacks Text Content #5475
Comments
This is difficult, there are many different ways to understand content as being "empty", a table is meant to hold content, if it does not have that content isn't it empty? I understand that this is different from prior versions but that is only because the prior versions did not really inspect the content. Could you explain to me a situation where a user would really create an empty table & expect it to be saved? |
The issue arises because I rely on the isNodeEmpty function to decide when to save or update content. Currently, Tiptap's isNodeEmpty function flags a table with no text as empty, even though the table structure itself holds value. This can be problematic, especially in cases like placeholders for future data or template creation. I understand and agree with your perspective on the matter. |
In your case, I would recommend using: import { isNodeEmpty } from '@tiptap/core';
function shouldSave(editor: Editor) {
let isContentEmpty = true
editor.state.doc.content.forEach(node => {
if (isContentEmpty === false) {
return
}
isContentEmpty = isNodeEmpty(node, { checkChildren: false })
})
return isContentEmpty
} This will check all of the top-level children to see if they are empty or not. Honestly, I think that another option for counting certain node types as empty may be convenient to have as well |
Thank you so much for the suggestion! I really appreciate the code snippet you provided. |
Affected Packages
core
Version(s)
2.5.9
Bug Description
The isNodeEmpty function in Tiptap is incorrectly detecting the editor's content as empty when it contains a table with no text inside the cells. Even though a table structure is present, the function returns true, indicating that the content is empty.
Steps to Reproduce
editor.isEmpty
- isNodeEmpty - function.Browser Used
Chrome
Code Example URL
No response
Expected Behavior
The function should recognize that the editor contains a table and return false, indicating that the content is not empty.
Additional Context (Optional)
Actual Behavior
The function returns true, incorrectly signaling that the editor content is empty.
Impact
This behavior can lead to issues in applications relying on isNodeEmpty for content validation or other logic, as valid content (a table) is being dismissed as empty.
Suggested Fix
The function should be updated to account for non-text elements like tables, considering the editor non-empty if such elements are present.
Dependency Updates
The text was updated successfully, but these errors were encountered: