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

custom block Copying and pasting will result in an error #1149

Closed
1 task
q2177329q opened this issue Oct 14, 2024 · 3 comments · Fixed by #1159
Closed
1 task

custom block Copying and pasting will result in an error #1149

q2177329q opened this issue Oct 14, 2024 · 3 comments · Fixed by #1159
Assignees
Labels
bug Something isn't working

Comments

@q2177329q
Copy link

Describe the bug
987.94bd8b52946dbc4b.js:9 Uncaught TypeError: Cannot read properties of null (reading 'firstChild')
at Y.addAll (987.94bd8b52946dbc4b.js:9:94126)
at Y.addElementByRule (987.94bd8b52946dbc4b.js:9:94028)
at Y.addElement (987.94bd8b52946dbc4b.js:9:92610)
at Y.addDOM (987.94bd8b52946dbc4b.js:9:91128)
at Y.addAll (987.94bd8b52946dbc4b.js:9:94220)
at _.parseSlice (987.94bd8b52946dbc4b.js:9:87860)
at eW (849baa33.2286729f2173c959.js:1:38904)
at tr (849baa33.2286729f2173c959.js:1:51532)
at tK.pasteHTML (849baa33.2286729f2173c959.js:1:90793)
at C.paste (4018.8ec8146930b55b85.js:1:149304)

To Reproduce
https://www.blocknotejs.org/docs/custom-schemas/custom-blocks#custom-block-types. the sample has the same issue, here is a video. and The procedure is Select some text -> copy(command + C on Mac) -> paste(command + V on mac). you will see the error log

CleanShot.2024-10-14.at.17.12.20.mp4

Misc

  • Node version: v18.17.0
  • Package manager: npm
  • Browser: chrome v 126
  • I'm a sponsor and would appreciate if you could look into this sooner than later 💖
@q2177329q q2177329q added the bug Something isn't working label Oct 14, 2024
@Elon-Mask12
Copy link

facing the same issue. tried setting parsekey, but its getting ignored.

@YousefED
Copy link
Collaborator

Thanks!

First diagnosis:

The ParseRule can't find the DOM element. This can be fixed by changing:

renderHTML({ HTMLAttributes }) {
      // renderHTML is used for copy/pasting content from the editor back into
      // the editor, so we need to make sure the `blockContent` element is
      // structured correctly as this is what's used for parsing blocks. We
      // just render a placeholder div inside as the `blockContent` element
      // already has all the information needed for proper parsing.
      const div = document.createElement("div");
      div.setAttribute("data-editable", "true");

and adding div.setAttribute("data-tmp-placeholder", "true");

Let's:

a) diagnose why this goes wrong now (seems like a regression)
b) add unit tests
c) create a proper fix (not sure if the above is a proper fix or not without step (a))

@q2177329q
Copy link
Author

When can I use the new version. Is it possible to release a beta version first? I'm already using this feature in my production environment

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

Successfully merging a pull request may close this issue.

4 participants