question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

setValue(blankSlateValue) would cause focus error

See original GitHub issue

Do 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:closed
  • Created 4 years ago
  • Reactions:21
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

36reactions
mdegreescommented, Aug 13, 2020

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

22reactions
caminadcommented, Feb 3, 2021

I was seeing this with react-refresh after following the installation guide, I fixed it by replacing const editor = useMemo(...) with

const [editor] = useState(() => withReact(createEditor()))
const [value, setValue] = useState(initialValue)

to tie the editor lifetime to that of the parent component and persist it across hot module reloads (React.useMemo is re-evaluated each time.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular Material 2 md-input is not focusing when i ...
Just use <md-input formControlName="code" placeholder="Code..."></md-input> without md-input-container.
Read more >
slate - setValue(blankSlateValue) would cause focus error ...
focus should be set automatically and not cause this error. i have a quick hack that does. editor.selection = { anchor: { path:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found