Skip to content

Error in imageMouseEnterHandler when hovering over image with editable set to false #519

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
riziuzi opened this issue Jan 14, 2024 · 0 comments · Fixed by #533
Closed
1 task

Error in imageMouseEnterHandler when hovering over image with editable set to false #519

riziuzi opened this issue Jan 14, 2024 · 0 comments · Fixed by #533
Labels
bug Something isn't working prio:high High priority

Comments

@riziuzi
Copy link

riziuzi commented Jan 14, 2024

Describe the bug
Whenever I hover over the image in editable: false option, I get error: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.
To Reproduce

import { BlockNoteView, useBlockNote } from "@blocknote/react";
import React, { useEffect, useRef } from 'react';

const EditorComponent = ({ index, data }) => {
    const sampleData=[
        {
          "id": "initialBlockId",
          "type": "image",
          "props": {
            "backgroundColor": "default",
            "textAlignment": "left",
            "url": "https://unsplash.com/photos/a-woman-working-on-a-laptop-6uAssP0vuPs",
            "caption": "",
            "width": 512
          },
          "children": []
        },
        {
          "id": "1b931231-0e0f-4413-90b7-6642c4561fa7",
          "type": "paragraph",
          "props": {
            "textColor": "default",
            "backgroundColor": "default",
            "textAlignment": "left"
          },
          "content": [],
          "children": []
        }
      ]
const cleanData = transformData(data)
    const editor = useBlockNote({
        editable: false,
        initialContent: sampleData,
        onEditorReady: (editor) =>{ console.log('Editor is ready!', editor)
        },
        onEditorContentChange: (editor) =>
            {
                console.log("Editr Chnaged?")                                              
 editor.topLevelBlocks directly everything works fine
            },
        domAttributes: {
            editor: {
                class: "min-h-[calc(100vh-152px)] w-full"
            },
            blockGroup: {
                class: "border border-blue-500 "
            },
            blockContainer: {
                class: "",
            },
        },
    });

    return(
        <BlockNoteView editor={editor} theme={"dark"} className="flex justify-center text-left w-full border border-red-500 " />
    )

};

Suspect
the file at

./node_modules/@blocknote/core/src/blocks/ImageBlockContent/ImageBlockContent.ts

having the code:

  // Shows the resize handles when hovering over the image with the cursor.
  const imageMouseEnterHandler = () => {
    if (editor.isEditable) {
      imageWrapper.appendChild(leftResizeHandle);        // This was where the error was squiggled : Uncaught DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.
      imageWrapper.appendChild(rightResizeHandle);
    } else {
      imageWrapper.removeChild(leftResizeHandle);
      imageWrapper.removeChild(rightResizeHandle);
    }
  };

is showing the issue
Misc

  • Node version: v18.16.1
  • Package manager: npm
  • Browser: Brave
  • I'm a sponsor and would appreciate if you could look into this sooner than later 💖
@riziuzi riziuzi added the bug Something isn't working label Jan 14, 2024
@matthewlipski matthewlipski added the prio:mid Medium priority label Jan 18, 2024
@matthewlipski matthewlipski added prio:high High priority and removed prio:mid Medium priority labels Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working prio:high High priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants