Skip to content

Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node. #562

@Nquq

Description

@Nquq

Hello!

I have a problem with the mermaid plugin. When I start erasing the word 'mermaid' in the editor, I get an error like in the screenshot.

image

here is my code component

export const Code = ({ inline, children = [], className, ...props }: any) => {
    const mermaidGraphId = useRef(`mermaidGraph${randomId()}`);
    const code = getCode(children);
    const mermaidGraph = useRef(null);

    const handle = useCallback(async () => {
        if (mermaidGraph.current) {
            try {
                const { svg } = await mermaid.render(
                    mermaidGraphId.current,
                    code
                );
                mermaidGraph.current.innerHTML = svg;
            } catch (error) {
                mermaidGraph.current.innerHTML = error;
            }
        }
    }, [mermaidGraph, code]);

    useEffect(() => {
        handle();
    }, [handle]);

    if (
        typeof code === 'string' &&
        typeof className === 'string' &&
        /^language-mermaid/.test(className.toLocaleLowerCase())
    ) {
        return (
            <code ref={mermaidGraph}>
                <code id={mermaidGraphId.current} style={{ display: 'none' }} />
            </code>
        );
    }

    return <code className={String(className)}>{children}</code>;
};

and MDEditor component

<MDEditor
     height={400}
     value={text}
     onChange={text => {
         setText(text);
         setFieldValue('text', text);
      }}
      previewOptions={{
          components: {
              code: Code,
              img: Image
           }
      }}
/>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions