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 occurred when calling renderFromHTML: Can't find a Block to remove. #2518

Open
luichooy opened this issue Oct 20, 2023 · 3 comments
Open
Labels

Comments

@luichooy
Copy link

Describe a bug.
I need to call the editor.clear() method to clear the existing content in the editor before calling the editor.blocks.renderFromHTML() method.

However, doing so results in the error "Uncaught (in promise) Error: Can't find a Block to remove. "

The clear method is supposed to remove all Blocks and create a new empty initial type Block. So, after calling the clear method, a new default block should have been created.

I'm wondering why calling renderFromHTML after clear is causing the error "Can't find a Block to remove".

Additionally, even if there is an error, why isn't it caught by using renderFromHTML().catch()? Instead, the error is thrown directly. In a React development environment, this would result in a runtime error.

Steps to reproduce:

  1. call editor.clear()
  2. call editor.blocks.renderFromHTML( '<p>call renderFromHTML after editor.clear()</p>')
  3. The error message states "Can't find a Block to remove" and appeared in the console.

Expected behavior:
No error occur or some ways to avoid this, thanks!

Screenshots:
image

Device, Browser, OS:

Editor.js version:
https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest
Plugins you use with their versions:

@luichooy luichooy added the bug label Oct 20, 2023
@Marax
Copy link

Marax commented Oct 23, 2023

I had same issue when I called clear() twice in a row, while not waiting for first clear to finish.

renderFromHTML actually also calls internally clear(), so check that you wait for the first clear() to finish before calling the renderFromHTML either by using await before clear or by calling renderFromHTML inside .then() block.

@kalebda
Copy link

kalebda commented Feb 6, 2024

Hey @luichooy found a way? I am in a react dev and facing the same problem. wanted to clear and render a new block programmatically

@terrancrypt
Copy link

I have the same error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants