tiptap
tiptap copied to clipboard
[Bug]: Issue in setting two anchor elements as HTML strings via `setContent`
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,
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,
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. 💖
+1 Also encountering this issue!
+1
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