setValue(blankSlateValue) would cause focus error
See original GitHub issueDo you want to request a feature or report a bug?
bug
What’s the current behavior?
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
What’s the expected behavior?
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
Issue Analytics
- State:
- Created 4 years ago
- Reactions:21
- Comments:7 (1 by maintainers)
Top GitHub Comments
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#tipsI was seeing this with react-refresh after following the installation guide, I fixed it by replacing
const editor = useMemo(...)
withto tie the editor lifetime to that of the parent component and persist it across hot module reloads (
React.useMemo
is re-evaluated each time.)