Open luichooy opened 9 months ago
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.
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
Describe a bug. I need to call the
editor.clear()
method to clear the existing content in the editor before calling theeditor.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
afterclear
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:
editor.clear()
editor.blocks.renderFromHTML( '<p>call renderFromHTML after editor.clear()</p>')
Expected behavior: No error occur or some ways to avoid this, thanks!
Screenshots:![image](https://github.com/codex-team/editor.js/assets/26423033/f0487111-fae0-4415-9a38-cd74361fa221)
Device, Browser, OS:
Editor.js version: https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest Plugins you use with their versions: