plate
plate copied to clipboard
`editor.selection` is null after unmount/remount
Description
On first component mount, the editor.selection is correctly defined but after unmounting and remounting the component, editor.selection is null forever
To reproduce the behavior:
- Click on "Toggle editor" to first mount the editor
- Type some text and see the focus offset printing correctly
- Click on "Toggle editor" twice (to unmount and remount)
- See offset undefined
Sandbox
https://codesandbox.io/s/issue-with-custom-editor-when-unmounting-cdq9l
Expectation
I would expect the selection not to be null after a remount
Environment
- slate: 0.72.0
- slate-react: 0.72.1
- browser: any
As a workaround, you can set a random editor ID:
const randomEditorId = useMemo(() => Math.random().toString(), [])
const editor = useMemo(
() =>
withPlate(createEditor(), { id: randomEditorId, plugins: platePlugins }),
// eslint-disable-next-line react-hooks/exhaustive-deps
[]
)