Skip to content

Fix: Adding empty td tag inside table throws RangeError #6241

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

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

Meyazhagan
Copy link

@Meyazhagan Meyazhagan commented Apr 6, 2025

Changes Overview

Closes: #6237

By default we using DOMParser.parseSlice (this function is not parsing the full node.), and no option to disable it
so, I created an option useParseSlice,

https://discuss.prosemirror.net/t/domparser-parseslice-not-parsing-correctly-empty-table-cell/5510

Implementation Approach

Testing Done

Verification Steps

Additional Notes

Checklist

  • I have created a changeset for this PR if necessary.
  • My changes do not break the library.
  • I have added tests where applicable.
  • I have followed the project guidelines.
  • I have fixed any lint issues.

Related Issues

Copy link

changeset-bot bot commented Apr 6, 2025

🦋 Changeset detected

Latest commit: 6621e38

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 54 packages
Name Type
@tiptap/core Major
@tiptap/extension-blockquote Major
@tiptap/extension-bold Major
@tiptap/extension-bubble-menu Major
@tiptap/extension-bullet-list Major
@tiptap/extension-character-count Major
@tiptap/extension-code-block-lowlight Major
@tiptap/extension-code-block Major
@tiptap/extension-code Major
@tiptap/extension-collaboration-cursor Major
@tiptap/extension-collaboration Major
@tiptap/extension-color Major
@tiptap/extension-document Major
@tiptap/extension-dropcursor Major
@tiptap/extension-floating-menu Major
@tiptap/extension-focus Major
@tiptap/extension-font-family Major
@tiptap/extension-gapcursor Major
@tiptap/extension-hard-break Major
@tiptap/extension-heading Major
@tiptap/extension-highlight Major
@tiptap/extension-history Major
@tiptap/extension-horizontal-rule Major
@tiptap/extension-image Major
@tiptap/extension-italic Major
@tiptap/extension-link Major
@tiptap/extension-list-item Major
@tiptap/extension-list-keymap Major
@tiptap/extension-mention Major
@tiptap/extension-ordered-list Major
@tiptap/extension-paragraph Major
@tiptap/extension-placeholder Major
@tiptap/extension-strike Major
@tiptap/extension-subscript Major
@tiptap/extension-superscript Major
@tiptap/extension-table-cell Major
@tiptap/extension-table-header Major
@tiptap/extension-table-row Major
@tiptap/extension-table Major
@tiptap/extension-task-item Major
@tiptap/extension-task-list Major
@tiptap/extension-text-align Major
@tiptap/extension-text-style Major
@tiptap/extension-text Major
@tiptap/extension-typography Major
@tiptap/extension-underline Major
@tiptap/extension-youtube Major
@tiptap/html Major
@tiptap/react Major
@tiptap/starter-kit Major
@tiptap/suggestion Major
@tiptap/vue-2 Major
@tiptap/vue-3 Major
@tiptap/pm Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

netlify bot commented Apr 6, 2025

Deploy Preview for tiptap-embed ready!

Name Link
🔨 Latest commit 6621e38
🔍 Latest deploy log https://app.netlify.com/sites/tiptap-embed/deploys/680a40ae4db9cb00074f1851
😎 Deploy Preview https://deploy-preview-6241--tiptap-embed.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@Meyazhagan Meyazhagan changed the title Fix(): Fix: Adding empty td tag inside table throws RangeError Apr 6, 2025
@its-me-dhina
Copy link

Verified the changes on local and the fix seems to be working fine. Can we prioitize merging this request?

Thanks!

@Meyazhagan Meyazhagan marked this pull request as ready for review April 8, 2025 16:04
@timothyerwin
Copy link

@Meyazhagan thanks, I'm seeing the same issue

@arnaugomez arnaugomez requested a review from bdbch April 10, 2025 11:28
@@ -10,7 +10,7 @@ import { Content } from '../types.js'
import { elementFromString } from '../utilities/elementFromString.js'

export type CreateNodeFromContentOptions = {
slice?: boolean
Copy link
Contributor

@arnaugomez arnaugomez Apr 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it already possible to disable DOMParser.parseSlice by calling createNodeFromContent with the parameter slice: false? @Meyazhagan . I believe your PR only changes the name of the parameter from slice to useParseSlice. It also changes its default value from true to false, which is a breaking change.

Therefore, I believe you could achieve the desired behavior of disabling DOMParser.parseSlice with the current code, by calling createNodeFromContent with the slice parameter to false. Could you check that this is true?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is already possible to disable DOMParser.parseSlice by calling createNodeFromContent with the slice parameter set to false, then this PR is likely not necessary. Or is there anything I'm missing? Correct me if I'm wrong.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arnaugomez is it possible to disable it while inserting the content into the editor?

Ref: #6237

Copy link
Contributor

@arnaugomez arnaugomez Apr 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's possible to achieve the same behavior of disabling DOMParser.parseSlice by calling createNodeFromContent with the slice parameter set to false. Have you tried it? @hafeezulkareem-yellow @Meyazhagan

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arnaugomez yeah I tried this changes, it is working!

quick question: createNodeFromContent function is being used in two places, createDocument and in insertContentAt both the place also we setting slice to false to use parse function, instead we can change in createNodeFromContent, by default to using parse function!

is there any good reason to have parseSlice as default parser ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Meyazhagan Yes, sure, if you think we can refactor it so that the code is simpler, create another PR with your changes and we'll review it. Thanks for your suggestion!

@arnaugomez arnaugomez removed the request for review from bdbch April 10, 2025 11:42
Copy link
Contributor

@arnaugomez arnaugomez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a changeset

@arnaugomez arnaugomez requested a review from bdbch April 13, 2025 09:16
@arnaugomez
Copy link
Contributor

@bdbch Could you review this? To me it looks good but I'm not familiar with this code and I want to make sure it does not break things.

@Meyazhagan Meyazhagan requested a review from arnaugomez April 13, 2025 12:06
Copy link
Member

@bdbch bdbch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that we hard-code slice: false into the insertContentAt function as it can potentially break the behavior for existing implementations.

Could we please have that as an option for insertContent and insertContentAt if this needs to be changed depending on what kind of content you want to insert and how you want to do it?

@@ -74,6 +74,7 @@ export const insertContentAt: RawCommands['insertContentAt'] = (position, value,

try {
content = createNodeFromContent(value, editor.schema, {
slice: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be hard-coded in the insertContentAt function?

Maybe we could expose this as an option rather than enforcing this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also make sure to pass through this new option in insertContent

"@tiptap/core": minor
---

fix parsing of empty html table in insertContentAt func
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the changeset accordingly.

@hafeezulkareem-yellow
Copy link

Hi @Meyazhagan @bdbch, I appreciate the work you are doing. It would be extremely helpful if we fast-track a fix for it. Thanks again for your time and support!

@Meyazhagan Meyazhagan requested a review from bdbch April 24, 2025 13:47
Copy link
Contributor

@arnaugomez arnaugomez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

...options,
}

let content: Fragment | ProseMirrorNode

try {
content = createNodeFromContent(value, editor.schema, {
slice: options.slice,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am concerned this is a breaking change. Before these changes, the createNodeFromContent was called with the slice value being false. But now it is called with a default value of true. If the default value of options.slice was false then this would not be a breaking change. But if the value should be true by default, then you have my approval. Just wanted to point this out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also rather keep the previous default to not cause breaking changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Adding empty td tag inside table throws RangeError
6 participants