tldraw / tldraw

SDK for creating whiteboards and canvas experiences on the web.

Home Page:https://tldraw.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: loadSnapshot disables keyboard

WilfredoHQ opened this issue · comments

What happened?

The keyboard stopped responding when deleting, copying, cutting, etc.
Using the buttons on the user interface, actions are carried out normally.

How can we reproduce the bug?

  • Create a shape
  • Save with getSnapshot somewhere
  • Delete the shapes or make any changes (optional)
  • Load the saved snapshot with loadSnapshot
const snapshot = editor.store.getSnapshot()
editor.store.loadSnapshot(snapshot)

See an example

What browsers are you seeing the problem on?

Firefox, Chrome

Contact Details

wilfredo_sj@hotmail.com

Code of Conduct

  • I agree to follow this project's Code of Conduct

Hey! Thanks for reporting this, we'll investigate it a bit further.

The issue seems to be that the editor looses focus. As a temporary workaround you can use the following line (after loading the snapshot).

editor.updateInstanceState({ isFocused: true })

You can also try playing with the editor.store.getSnapshot options. Using editor.store.getSnapshot('all') would also store the instance state and would then allow you to load it back in the same state as it was when storing the snapshot.

What are you trying to achieve? Just load a document when the page first loads?

Thank you very much, as you mentioned what I was trying to achieve is to load a document when the page loads for the first time.
The suggested temporary solution works great, the option to use "all" when obtaining the snapshot works just as well, but it saves data that I don't really need to save. Anyway, it's great for other cases.