slate: Modification to onChange cannot get latest state
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
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
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 1
- Comments: 17 (5 by maintainers)
I am seeing this same behavior whenever my app hot module reloads. In my case the steps to reproduce are:
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?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;ร
@mikestopcontinues You could try importing your module dynamically and disabling SSR
How to fix it in CRA-driven project?