tiptap
tiptap copied to clipboard
[Bug]: Links open twice when the config is `editable: false`
Which packages did you experience the bug in?
extension-link
What Tiptap version are you using?
2.2.2
What’s the bug you are facing?
The link opens twice when the clicking a link on an editor with editable: false as the Editor settings.
Tested on:
- macOS 14.2.1
- Chrome/Safari/Firefox
What browser are you using?
Chrome
Code example
https://github.com/jaggy/tiptap-link-opens-twice-reproduction
What did you expect to happen?
It should only open one new tab.
Anything to add? (optional)
When openOnClick is set to false:
editable: true
Doesn't open. Which is correct.
editable: false
It opens once.
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. 💖
I'm running into this exact case too When editable == false, then links DO open. I'm on 2.1.13 and will double check if an upgrade helps.
I'm noticing the same issue. Links open once when editable=true and twice when editable=false. On version 2.2.6. With openOnClick: true.
For some reason, Firefox doesn't 'prevent' the click event when editable (clicking on a link inside a contenteditable=true container is usually caught)
I assume that the openOnClick option only exists because one wanted to allow links to be clickable while editing - and not to make them clickable at all - which they usually are due to the nature of <a> tags.
When the editor is not editable, shouldn't click events on <a> tags naturally be handled by the browser instead of the editor?
Also, we're currently facing this issue in our codebase as well
it seems that prosemirror-view calls event.preventDefault() on the mouseup event (in this case because extension-link returns true after opening the link).
Immediately after that, the browser emits a click event - which is not handled by prosemirror-view nor extension-link and thus (when the editor is NOT editable --> contenteditable=false) the default click handler for a <a> element in the browser kicks in (link is opened again).
My suggestion is to follow @jaggy 's observation and set { openOnClick: false } so that extension-link does not register the 'onMouseUp' handler (via prosemirror-view plugin).
Longterm, I think the clickHandler from extension-link should return false early if view.editable !== true.
@bdbch @svenadlung
relates to: https://github.com/ueberdosis/tiptap/pull/5040
Appreciate your feedback here.
@benkroeger to be clear, your suggestion means that we should apply your PR to revert wheNotEditable right?
yes. I've created #5040 for that
Should be resolved with: https://github.com/ueberdosis/tiptap/pull/5040
It still seems to happen in @2.5.4 😢