Skip to content

Initializing editor with content that has custom blocks results in error #345

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
handzlikt opened this issue Sep 21, 2023 · 4 comments
Closed
Labels
bug Something isn't working

Comments

@handzlikt
Copy link

Describe the bug

After adding the save and load functionality (https://www.blocknotejs.org/examples/saving-loading) to the Alert Block example (https://www.blocknotejs.org/examples/alert-block)
the editor throws an error on initialization whenever the Alert Block is present in the content.
Same happens with the much simple example of Custom Blocs usage https://www.blocknotejs.org/docs/block-types#custom-block-types

To Reproduce

  1. Visit https://codesandbox.io/s/epic-forest-c5zwzz
  2. Enter some content that is different than the Alert element
  3. Refresh the browser inside sandbox -> the editor should initialize with the previous content
  4. Add Alert element
  5. Refresh the browser inside sandbox -> the editor raises 'RangeError: Position undefined out of range'

Misc

  • Package manager: npm
  • Browser: Chrome
@handzlikt handzlikt added the bug Something isn't working label Sep 21, 2023
@marwan37
Copy link

I don’t have a definitive solution for the issue you’re encountering, but I’d like to share some insights that might help.

In my project, I’ve been using Yjs with IndexedDb to store the editor's content and haven’t encountered the RangeError you mentioned. I suspected the issue might be related to localStorage, so I attempted to reproduce the CodeSandbox environment locally, using your Alert.tsx code . I stored the content in localStorage and initialized it from there, but still didn’t experience any issues. Same for other custom block types like Image.

Out of curiosity, are you seeing the RangeError in your local environment as well, or only in the code sandbox? It’s possible that the issue could be related to the sandbox environment itself.

@todthomson
Copy link

todthomson commented Sep 25, 2023

I think this error is the same that this PR fixes: #336.

@handzlikt
Copy link
Author

It's not only an sandbox issue - I get in my local env as well. It happens also when the initial content is hardcode instead of read from localStorage. What's interesting it doesn't occur in the production build of the app.

@todthomson thank you, it looks indeed as a potential duplicate of https://github.com/TypeCellOS/BlockNote/pull/336

@matthewlipski
Copy link
Collaborator

Ok I found the root cause of the issue, tl;dr the initial content is rendered before the underlying TipTap editor is fully initialized, which doesn't affect default blocks (they don't use any editor functions when rendering) but throws an error for custom blocks. Should be fixed in #348👍

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

4 participants