tldraw / tldraw

SDK for creating whiteboards and canvas experiences on the web.
https://tldraw.dev
Other
33.04k stars 1.98k forks source link

[Bug]: loadSnapshot disables keyboard #3696

Open WilfredoHQ opened 2 weeks ago

WilfredoHQ commented 2 weeks ago

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?

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

linear[bot] commented 2 weeks ago

TLD-2491 [Bug]: loadSnapshot disables keyboard

MitjaBezensek commented 1 week ago

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?

WilfredoHQ commented 1 week ago

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.