bug
if you have multiline content in the editor, and you use setValue(blankSlateValue), it causes
Cannot find a descendant at path [1,0] in node: {"children":[{"type":"paragraph","children":[{"text":""}]}],"operations":[],"selection":{"anchor":{"path":[1,0],"offset":6},"focus":{"path":[1,0],"offset":6}},"marks":null,"history":{"undos":[[{"type":"set_selection","properties":null,"newProperties":{"anchor":{"path":[0,0],"offset":0},"focus":{"path":[0,0],"offset":0}}}],[{"type":"insert_text","path":[0,0],"offset":0,"text":"e"},{"type":"insert_text","path":[0,0],"offset":1,"text":"a"},{"type":"insert_text","path":[0,0],"offset":2,"text":"f"},{"type":"insert_text","path":[0,0],"offset":3,"text":"e"},{"type":"insert_text","path":[0,0],"offset":4,"text":"a"},{"type":"insert_text","path":[0,0],"offset":5,"text":"f"},{"type":"insert_text","path":[0,0],"offset":6,"text":"e"},{"type":"insert_text","path":[0,0],"offset":7,"text":"a"}],[{"type":"split_node","path":[0,0],"position":8,"target":null,"properties":{}},{"type":"split_node","path":[0],"position":1,"target":8,"properties":{"type":"paragraph"}}],[{"type":"insert_text","path":[1,0],"offset":0,"text":"f"},{"type":"insert_text","path":[1,0],"offset":1,"text":"e"},{"type":"insert_text","path":[1,0],"offset":2,"text":"a"},{"type":"insert_text","path":[1,0],"offset":3,"text":"f"},{"type":"insert_text","path":[1,0],"offset":4,"text":"a"},{"type":"insert_text","path":[1,0],"offset":5,"text":"e"}]],"redos":[]}}
Slate: 0.57.1
Browser: Chrome
OS: Mac
focus should be set automatically and not cause this error.
i have a quick hack that does
editor.selection = {
anchor: {
path: [0,0],
offset:0
},
focus: {
path: [0,0],
offset: 0
}
}
before i setValue(blankSlateValue) and it works as expected
Just confirming this bug, I hit it and resetting the anchor and focus avoids the error when resetting to a simple state like:
const initialValue = [
{
type: 'paragraph',
children: [{ text: '' }],
}
] as Node[]
Hi @hanselke , incidentally the "hack" you mentioned is the solution to this behavior. The selection state for slate is controlled separately from the value state, and if you pass it a value and the selection state is no longer valid, it will throw an exception. Setting the selection to a neutral state is necessary before resetting the value.
This is caused by react Fast Refresh. I got rid of the crash by adding // @refresh reset to the top of the file according to https://reactnative.dev/docs/fast-refresh#tips
This is caused by react Fast Refresh. I got rid of the crash by adding
// @refresh resetto the top of the file according to https://reactnative.dev/docs/fast-refresh#tips
Thank you, this is very useful to me
Most helpful comment
This is caused by react Fast Refresh. I got rid of the crash by adding
// @refresh resetto the top of the file according to https://reactnative.dev/docs/fast-refresh#tips