Skip to content
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

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

Closed
1 of 2 tasks
jaggy opened this issue Feb 11, 2024 · 7 comments
Closed
1 of 2 tasks

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

jaggy opened this issue Feb 11, 2024 · 7 comments
Labels
Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug

Comments

@jaggy
Copy link

jaggy commented Feb 11, 2024

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?

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

Are you sponsoring us?

  • Yes, I’m a sponsor. 💖
@jaggy jaggy added Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug labels Feb 11, 2024
@culli
Copy link

culli commented Feb 20, 2024

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.

@Janus451
Copy link

Janus451 commented Apr 8, 2024

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.

@benkroeger
Copy link
Contributor

benkroeger commented Apr 8, 2024

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
Copy link
Contributor

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: #5040

@nperez0111
Copy link
Contributor

Appreciate your feedback here.

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

@benkroeger
Copy link
Contributor

yes. I've created #5040 for that

@nperez0111
Copy link
Contributor

Should be resolved with: #5040

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug
Projects
Status: Done
Development

No branches or pull requests

5 participants