Skip to content

Error when trying to copy and paste text in the editor #1648

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

Closed
1 task
asasher opened this issue Apr 28, 2025 · 2 comments
Closed
1 task

Error when trying to copy and paste text in the editor #1648

asasher opened this issue Apr 28, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@asasher
Copy link

asasher commented Apr 28, 2025

Describe the bug
I'm getting the following error when trying to copy and paste text in the same editore

Uncaught TypeError: Cannot read properties of null (reading 'append')
    at closeFragment (index.js:1720:38)
    at closeFragment (index.js:1716:56)
    at closeFragment (index.js:1716:56)
    at replaceRange (index.js:1698:110)
    at Transaction.replaceRange (index.js:2002:9)
    at TextSelection.replace (index.js:90:16)
    at TextSelection.replace (index.js:252:15)
    at Transaction.replaceSelection (index.js:601:24)
    at doPaste (index.js:3645:25)
    at EditorView.pasteHTML (index.js:5660:16)
    at Gn.pasteHTML (BlockNoteEditor.ts:1637:27)
    at Bi (pasteExtension.ts:55:12)
    at Object.defaultPasteHandler (pasteExtension.ts:120:28)
    at BlockNoteExtensions.ts:274:23
    at Plugin.paste (pasteExtension.ts:113:24)
    at index.js:3108:26
    at EditorView.someProp (index.js:5514:50)
    at runCustomHandler (index.js:3106:17)
    at view.dom.addEventListener.view.input.eventHandlers.<computed> (index.js:3075:53)

To Reproduce

  1. Type anything in the editor
  2. Copy part of the the text, Cmd+C
  3. Arrow down and paste, Cmd+V
  4. Boom

Adding the following to package.json seems to fix the issue:

"pnpm": {
    "overrides": {
      "prosemirror-model": "1.25.0"
    }
  }

Here's the repo and a stackblitz demo-ing the issue:
Github Repo
Stackblitz

Misc

  • Node version: v23.10.0

  • Package manager: [email protected]

  • Browser: Arc

  • I'm a sponsor and would appreciate if you could look into this sooner than later 💖

@asasher asasher added the bug Something isn't working label Apr 28, 2025
@danlupascu
Copy link

danlupascu commented May 5, 2025

  1. I can confirm that this issue is happening on my side as well
  2. It is fixed by using "prosemirror-model": "1.25.0", but only for raw text. If you copy-paste a piece of code from your IDE then this error shows up again.

Update: here's my temporary fix for this issue:

const editor = useCreateBlockNote({
    pasteHandler: ({ event, defaultPasteHandler }) => {
      try {
        // Try to use the default copy paste handler
        return defaultPasteHandler();
      } catch (e) {
        // If the default copy past handler fails then at least try to paste the contents as regular text
        if (event.clipboardData?.types.includes('text/plain')) {
          editor.pasteText(event.clipboardData.getData('text/plain'));
          return true;
        }
        throw e;
      }
    },
  });

@nperez0111
Copy link
Contributor

Closing as tracked as part of #1645

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants