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

Error: Blocks with the following IDs could not be found in the editor #836

Open
pruthvidarji1993 opened this issue Jun 12, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@pruthvidarji1993
Copy link

pruthvidarji1993 commented Jun 12, 2024

I'm currently implementing BlockNote in our app, and we are storing markdown in our database. After storing the markdown, we need to display the initial data in the editor. To do this, we have to convert the markdown to blocks. However, I am encountering the following runtime error during the conversion:
Error: Blocks with the following IDs could not be found in the editor:b2f5efd8-367c-466b-a24b-98c1c7f88f9b

Could you please help me resolve this issue? I’m stuck and would appreciate any guidance.

Here is the code I am using to convert markdown to blocks:

useEffect(() => {
  async function loadInitialHTML() {
    const blocks = await editor.tryParseMarkdownToBlocks(planDetails?.noteBlock);
    console.log('blocks: ', blocks);

    editor.replaceBlocks(editor.document, blocks || []);
  }

  if (editor && planDetails?.noteBlock) {
    setTimeout(() => {
      loadInitialHTML();
    }, 1000);
  }
}, [editor, planDetails?.noteBlock]);

Current Specifications:

Next.js: ^13.2.4
BlockNote: ^0.14.0

Thank you in advance for your help!

@pruthvidarji1993 pruthvidarji1993 added the bug Something isn't working label Jun 12, 2024
@pruthvidarji1993
Copy link
Author

@YousefED It would be really great if you can help me in this

@matthewlipski
Copy link
Collaborator

I'm not seeing any errors using this code:

import "@blocknote/core/fonts/inter.css";
import { useCreateBlockNote } from "@blocknote/react";
import { BlockNoteView } from "@blocknote/mantine";
import "@blocknote/mantine/style.css";
import { useEffect } from "react";

const md = `# Heading

Paragraph

- List Item`;

export default function App() {
  // Creates a new editor instance.
  const editor = useCreateBlockNote({
    initialContent: [
      {
        type: "paragraph",
        content: "Paragraph 1",
      },
      {
        type: "paragraph",
        content: "Paragraph 2",
      },
      {
        type: "paragraph",
        content: "Paragraph 3",
      },
    ],
  });

  useEffect(() => {
    async function replaceContentWithMarkdown(markdown: string) {
      const blocks = await editor.tryParseMarkdownToBlocks(markdown);

      editor.replaceBlocks(editor.document, blocks);
    }

    // debugger;
    setTimeout(() => {
      replaceContentWithMarkdown(md);
    }, 1000);
  }, [editor]);

  // Renders the editor instance using a React component.
  return <BlockNoteView editor={editor} />;
}

Can you post the values of planDetails?.noteBlock, blocks, and editor.document you get when calling editor.replaceBlocks?

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

2 participants