tiptap icon indicating copy to clipboard operation
tiptap copied to clipboard

[Bug]: Issue in setting two anchor elements as HTML strings via `setContent`

Open vivinkrishna-ni opened this issue 1 year ago • 1 comments

Which packages did you experience the bug in?

extension-core, extension-link

What Tiptap version are you using?

2.1.13

What’s the bug you are facing?

Setting two or more anchor elements with the same href value and without whitespace between them via a setContent with the content as HTML string renders as a single anchor element in the DOM.

For example,

editor.commands.setContent('<a href="#">Link1</a><a href="#">Link2</a>')

Here, Link1 and Link2 have the same href values and without a whitespace between them. It renders as a single link in the editor with href value as # and text content as Link1Link2 (text concatenates). Here is the snapshot of the equivalent DOM for reference, image

What browser are you using?

Chrome

Code example

https://stackblitz.com/edit/typescript-5rqrek

What did you expect to happen?

With the above example, I expect them to be rendered as separate links, and here is the snapshot of the expected DOM equivalent, image

Anything to add? (optional)

No response

Did you update your dependencies?

  • [X] Yes, I’ve updated my dependencies to use the latest version of all packages.

Are you sponsoring us?

  • [ ] Yes, I’m a sponsor. 💖

vivinkrishna-ni avatar Dec 12 '23 14:12 vivinkrishna-ni

+1 Also encountering this issue!

jamdav16 avatar Apr 10 '24 01:04 jamdav16

+1

m-akinc avatar Jun 05 '24 18:06 m-akinc

This is a feature of prosemirror, where if the attributes of nodes are the same it will merge them together. In most cases this is desirable behavior. It would not merge them together if they were instead having different attributes.

I tried, this and it created separate links as expected because the href is pointing to different values:

<a href="https://www.goole.com?q=search">https://www.goole.com</a><a href="https://www.goole.com">https://www.goole.com</a>

In most cases this would be desirable & even equivalent so I'm curious why you would not also want this behavior

nperez0111 avatar Jun 06 '24 07:06 nperez0111