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]: Pasting text with more than one link sets all links' href to the first link's href #4541

Open
2 tasks done
angelikatyborska opened this issue Oct 17, 2023 · 20 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

@angelikatyborska
Copy link

angelikatyborska commented Oct 17, 2023

Which packages did you experience the bug in?

link

What Tiptap version are you using?

2.1.12

What’s the bug you are facing?

I am trying to copy-paste a piece of content that contains more than one link, and the links' text content can be interpreted as valid URLs. Below an example of such content:

--- start copying below ---

Some search engines:

--- stop copying above ---

When I copy-paste this to a TipTap editor, every link but the first one has a wrong href attribute - all links have a href attribute equal to the href attribute of the first link. See a screen recording below.

Basically on paste, TipTap changes this:

Some search engines:
- DuckDuckGo: <a href="https://duckduckgo.com/">https://duckduckgo.com/</a>
- Bing: <a href="https://www.bing.com/">https://www.bing.com/</a>

To this:

Some search engines:
- DuckDuckGo: <a href="https://duckduckgo.com/">https://duckduckgo.com/</a>
- Bing: <a href="https://duckduckgo.com/">https://www.bing.com/</a>

This only happens for links whose text content is also an URL - it doesn't happen when links are for example like [DGG](https://duckduckgo.com/)

What browser are you using?

Firefox

Code example

No response

What did you expect to happen?

I expect all links to always have the same href attribute as on the source page from which I copied them.

Anything to add? (optional)

Screen.Recording.2023-10-17.at.12.54.56.mov

I didn't prepare a CodeSandbox because this behavior can be observed right now on TipTap's official page for the link extension, as seen on the video.

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. 💖
@angelikatyborska angelikatyborska 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 Oct 17, 2023
@C-Hess
Copy link
Contributor

C-Hess commented Oct 30, 2023

Cannot reproduce as of 2.2.0-rc.4

Likely fixed by #4523

@angelikatyborska
Copy link
Author

Likely fixed by #4523

I don't think so because that PR was part of the 2.1.12 release where I'm definitely still experiencing this bug.

I'll try out 2.2.0-rc.4 and report back.

@angelikatyborska
Copy link
Author

@C-Hess The bug exists both in 2.2.0-rc.4 and in 2.1.12. Here's a reproduction codesandbox for 2.2.0-rc.4: https://codesandbox.io/s/dazzling-rain-mpqrh8?file=/src/index.js

Screen.Recording.2023-10-30.at.08.27.14.mov

@C-Hess
Copy link
Contributor

C-Hess commented Oct 30, 2023

Interesting, I'll take a look again, sorry.

@C-Hess
Copy link
Contributor

C-Hess commented Oct 31, 2023

I see now, I mistakenly forgot to clean my build when testing.

Looks like this paste handler is to blame:
https://github.com/ueberdosis/tiptap/blob/42039c05f0894a2730a7b8f1b943ddb22d52a824/packages/extension-link/src/link.ts#L151C1-L186C6

addPasteRules() {
    return [
      markPasteRule({
        find: text => find(text)
          .filter(link => {
            if (this.options.validate) {
              return this.options.validate(link.value)
            }


            return true
          })
          .filter(link => link.isLink)
          .map(link => ({
            text: link.value,
            index: link.start,
            data: link,
          })),
        type: this.type,
        getAttributes: (match, pasteEvent) => {
          const html = pasteEvent.clipboardData?.getData('text/html')
          const hrefRegex = /href="([^"]*)"/


          const existingLink = html?.match(hrefRegex)


          if (existingLink) {
            return {
              href: existingLink[1],
            }
          }


          return {
            href: match.data?.href,
          }
        },
      }),
    ]

It only grabs the first href of your entire clipboard payload I believe. This will have to modified to support multiple links within the same clipboard payload.

It also looks like #4523 was actually not merged into the develop branch, and even if it was it looks like it has the same problem...

@C-Hess
Copy link
Contributor

C-Hess commented Oct 31, 2023

Causing change #3975 @bdbch .

I think one solution could be to add some sort of option in markPasteRule so that it will NOT override an existing mark if the mark type is identical (aka, if it was already parsed via parseHTML, the paste rule should not apply)

@C-Hess
Copy link
Contributor

C-Hess commented Oct 31, 2023

Created a draft PR. need to perform further testing of side effects and write tests before publishing

@101budspencer
Copy link

Fix there already?

@Arnaud-SR
Copy link

Created a draft PR. need to perform further testing of side effects and write tests before publishing

Any news about that ?

@C-Hess
Copy link
Contributor

C-Hess commented Nov 27, 2023

Sorry, I'll try and wrap that PR up the next few days

@101budspencer
Copy link

101budspencer commented Nov 27, 2023 via email

@101budspencer
Copy link

Sorry, I'll try and wrap that PR up the next few days

Can you do it?

@C-Hess
Copy link
Contributor

C-Hess commented Dec 3, 2023

Published. Ready for review

@bdbch bdbch mentioned this issue Dec 15, 2023
4 tasks
@101budspencer
Copy link

How is it? @bdbch @C-Hess @Arnaud-SR

@Arnaud-SR
Copy link

Published. Ready for review

Any news about that ?

@giuseppeagostini-hotmart
Copy link

giuseppeagostini-hotmart commented Mar 22, 2024

any update? In version 2.2.4 it is still giving me problems @C-Hess

@v-tsys
Copy link

v-tsys commented Mar 29, 2024

Yo! Is there any ETA for this fix?

@jiegillet
Copy link
Contributor

It seems to be fixed in 2.5.4 (possibly in a previous release, I didn't bisect it)

@nperez0111
Copy link
Contributor

Is this still relevant @C-Hess #4587

@C-Hess
Copy link
Contributor

C-Hess commented Jul 29, 2024

I'll verify soon

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: Triage open
Development

No branches or pull requests

10 participants