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

TipTap doesn't work properly in Safari inside a ShadowRoot #2639

Closed
1 of 2 tasks
andersgranberg opened this issue Mar 22, 2022 · 1 comment
Closed
1 of 2 tasks

TipTap doesn't work properly in Safari inside a ShadowRoot #2639

andersgranberg opened this issue Mar 22, 2022 · 1 comment
Labels
Type: Bug The issue or pullrequest is related to a bug

Comments

@andersgranberg
Copy link

What’s the bug you are facing?

The editor doesn't work properly in Safari if placed inside a ShadowRoot. The editor repeatedly moves the focus point to the end of the document on every input/keypress. It's also not possible to create a new paragraph between two already existing paragraphs since the focus point is moved. There's also a problem with selecting text which is making it impossible to use BubbleMenu etc.

How can we reproduce the bug on our side?

Create a custom element like the example below:

import { Editor } from '@tiptap/core'
import StarterKit from '@tiptap/starter-kit'

customElements.define(
    'custom-tiptap',
    class extends HTMLElement {
      constructor() {
        super();  
        this.attachShadow({ mode: 'open', delegatesFocus: false });
        this.shadowRoot.innerHTML = this.render();
      }
      connectedCallback() {        
        new Editor({
            element: this.shadowRoot.querySelector('.element'),
            extensions: [
              StarterKit,
            ],
            content: '<p>This example will NOT work in Safari</p>',
          });          
      }
      render() {
        return `
        <div>TipTap
        <div class="element" style="width:500px;"></div>
        </div>
        `;
    }    
  },
);

If the shadow root is not used the editor works accordingly. See below for a working example.

import { Editor } from '@tiptap/core'
import StarterKit from '@tiptap/starter-kit'

customElements.define(
    'custom-tiptap',
    class extends HTMLElement {
      constructor() {
        super();  
        this.innerHTML = this.render();
      }
      connectedCallback() {        
        new Editor({
            element: this.querySelector('.element'),
            extensions: [
              StarterKit,
            ],
            content: '<p>This example will work in Safari</p>',
          });          
      }
      render() {
        return `
        <div>TipTap
        <div class="element" style="width:500px;"></div>
        </div>
        `;
    }    
  },
);

Can you provide a CodeSandbox?

No response

What did you expect to happen?

Expected the editor to work even if placed inside a shadow root in Safari.

Anything to add? (optional)

Could this be related to similar issues in ProseMirror? Tried these suggested solutions but with no success.

https://discuss.prosemirror.net/t/prosemirror-inside-a-shadowroot/2387
/~https://github.com/jsturgill/shadow-root-get-selection-polyfill

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. 💖
@andersgranberg andersgranberg added the Type: Bug The issue or pullrequest is related to a bug label Mar 22, 2022
@philippkuehn
Copy link
Contributor

Hmm, seems like a browser bug :( ProseMirror/prosemirror#476

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug The issue or pullrequest is related to a bug
Projects
None yet
Development

No branches or pull requests

2 participants