plate icon indicating copy to clipboard operation
plate copied to clipboard

`editor.selection` is null after unmount/remount

Open baptisteArno opened this issue 3 years ago • 1 comments

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:

  1. Click on "Toggle editor" to first mount the editor
  2. Type some text and see the focus offset printing correctly
  3. Click on "Toggle editor" twice (to unmount and remount)
  4. 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

baptisteArno avatar Jan 13 '22 10:01 baptisteArno

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
    []
  )

baptisteArno avatar Jan 13 '22 11:01 baptisteArno