tiptap icon indicating copy to clipboard operation
tiptap copied to clipboard

[Bug]: Links open twice when the config is `editable: false`

Open jaggy opened this issue 1 year ago • 4 comments

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. 💖

jaggy avatar Feb 11 '24 11:02 jaggy

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.

culli avatar Feb 20 '24 17:02 culli

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.

Janus451 avatar Apr 08 '24 09:04 Janus451

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

benkroeger avatar Apr 08 '24 11:04 benkroeger

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

benkroeger avatar Apr 08 '24 14:04 benkroeger

Appreciate your feedback here.

@benkroeger to be clear, your suggestion means that we should apply your PR to revert wheNotEditable right?

nperez0111 avatar May 24 '24 14:05 nperez0111

yes. I've created #5040 for that

benkroeger avatar May 24 '24 14:05 benkroeger

Should be resolved with: https://github.com/ueberdosis/tiptap/pull/5040

nperez0111 avatar May 24 '24 15:05 nperez0111

It still seems to happen in @2.5.4 😢

rlatlswo135 avatar Jul 23 '24 01:07 rlatlswo135