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.

Modification to onChange cannot get latest state

See original GitHub issue

Do you want to request a feature or report a bug?

Bug 🐛

What’s the current behavior?

If I have a state which should update for each onChange() call on the editor, the onChange() only has access to the initial state. It also somehow reverts to the barebones editor state during this behavior.

Cannot find a descendant at path [0] in node: 
{
  children: [],
  operations: [],
  selection: null,
  marks: null,
  history: {
    undos: [],
    redos: []
  }
}
GIF of issue in action

Apr-17-2020 15-35-34

Sandbox of issue reproduction

https://codesandbox.io/s/slate-repo-irmerk-17-04-2020-mebkd

Information about your OS, browser, Slate version, etc.

Slate: 0.57.1 Browser: Chrome OS: Mac

What’s the expected behavior?

Slate should handle updating of the editor without losing its current value, selection, etc when one of the custom high order functions wrapping the creation of the editor changes

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:17 (5 by maintainers)

github_iconTop GitHub Comments

11reactions
jonathaneckmancommented, Sep 7, 2020

I am seeing this same behavior whenever my app hot module reloads. In my case the steps to reproduce are:

  1. Begin typing in an editor.
  2. Make a change in code and save to trigger hot module reload.
  3. After a successful bundle rebuild, the page attempts to refresh and the following error is thrown: Cannot find a descendant at path [0] in node: {"children":[],"operations":[],"selection":null,"marks":null}.

This is confusing since I initialize the editor with a default value of [{ type: 'paragraph', children: [{ text: '' }] }], so where is the editor getting the value reported in the error message?

4reactions
CloudDrivenSolutionscommented, Sep 8, 2021

The resolution with issues relating to CRA was to utilize useRef instead of useMemo.

const editorRef = useRef() if (!editorRef.current) editorRef.current = withReact(createEditor()); const editor = editorRef.current;Ï

Read more comments on GitHub >

github_iconTop Results From Across the Web

ReactJS: Input onChange not Updating State - Stack Overflow
If I understand correctly you want DuplicateHubDisplay 's commsTitle state to update when either (1) the inputValue of the parent component ...
Read more >
Lifting State Up - React
Often, several components need to reflect the same changing data. We recommend lifting the shared state up to their closest common ancestor.
Read more >
What Every React Developer Should Know About State
It accepts a new state value and enqueues a re-render of the component. What does this word "enqueues" mean? In other words, it...
Read more >
Changing State via User Input - Thinkster.io
Learn how to capture data from an input field and update a component's state. ... wrong and won't work, as React doesn't watch...
Read more >
React onChange with input field & button | by Mahesh
At last, we need to make sure enabling/disabling button is done when there is no change in data and during API call. I...
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