Slate: Cannot find a descendant at path when setting initialValue

Created on 27 Mar 2020  路  4Comments  路  Source: ianstormtaylor/slate

Do you want to request a _feature_ or report a _bug_?

_bug_

What's the current behavior?

When I start with an empty state, add some text and make NO changes to it, f. If I then programmatically reset the state via a button it results in a crash.

Slate: 0.XX.X
Browser: Chrome / Safari / Firefox / Edge
OS: Mac / Windows / Linux / iOS / Android

What's the expected behavior?

Most helpful comment

Hi @ramsy-leftclick , this is not a bug. You need to reset selection when you reset the editor value, because selection is not packed in with the value. The crash is because when you rip out the value under the editor, it will still hold onto its current selection state and then have nothing to retrieve at that area.

You probably need to call something like Transforms.select(editor, [0]) before setValue

All 4 comments

Hey @ramsy-leftclick, this happens if you don't also reset the selection state which is stored separately from the value. Also, your empty state must have at least one text node in it.

In the future, some code to show a minimum reproduction of the error would be helpful as well :)

Hi @CameronAckermanSEL.

Thanks for the response. I made a Sandbox containing the code, which I've submitted with the bug.

https://codesandbox.io/s/jovial-browser-43pzl

Hi @ramsy-leftclick , this is not a bug. You need to reset selection when you reset the editor value, because selection is not packed in with the value. The crash is because when you rip out the value under the editor, it will still hold onto its current selection state and then have nothing to retrieve at that area.

You probably need to call something like Transforms.select(editor, [0]) before setValue

Hi @ramsy-leftclick , this is not a bug. You need to reset selection when you reset the editor value, because selection is not packed in with the value. The crash is because when you rip out the value under the editor, it will still hold onto its current selection state and then have nothing to retrieve at that area.

You probably need to call something like Transforms.select(editor, [0]) before setValue

select din't work for me, I had to use: Transforms.deselect(editor);

Was this page helpful?
0 / 5 - 0 ratings