plate icon indicating copy to clipboard operation
plate copied to clipboard

Plate remount is setting the editor to null

Open zbeyens opened this issue 2 years ago • 7 comments

Description

It looks like Plate gets into a bad state when it’s remounted with the same id. The editor gets set to null.

Sandbox

https://codesandbox.io/s/friendly-sinoussi-3xgwx2 Clicking the remount button removes the editor

Environment

  • slate:
  • slate-react:
  • browser: chrome

zbeyens avatar Apr 28 '22 10:04 zbeyens

I prevent remount to prevent these kind of problem. In my side, remount cause it lost focus.

linonetwo avatar Apr 30 '22 14:04 linonetwo

I prevent remount to prevent these kind of problem. In my side, remount cause it lost focus.

how to prevent remount? Could you paste the code please? I enter the same question

zerosoul avatar May 12 '22 06:05 zerosoul

I'm using it in tiddlywiki, and I detect if the change is trigger by plate's onsave, then don't unmount react-com's root. If is trigger by 3rd party, then unmount react-dom, then remount.

https://github.com/tiddly-gittly/slate-write/blob/2b4ef9a7ecdb431000bf5e2ac860cf8fd5cdb65b/src/editor/index.ts#L42-L66

linonetwo avatar May 12 '22 07:05 linonetwo

any updates on fixing this issue?

suchanlee avatar Jun 13 '22 22:06 suchanlee

I think we can unmount remount parent component to avoid most of the problems, just like I do.

linonetwo avatar Jun 15 '22 08:06 linonetwo

any updates on fixing this issue? . in my case , i need plate to remount frequently

StarHosea avatar Aug 02 '22 16:08 StarHosea

Just wrap plate in a parent component, and remount that component by change the key or something.

linonetwo avatar Aug 08 '22 08:08 linonetwo

Why do we even need to not render the content if the id is not found ? I mean, why not just render the children and be it ?

VictorBaron avatar Aug 29 '22 16:08 VictorBaron

It would result into errors as the store needs to be created before the children subscribe to it using hooks. I've tried to fix the timing issue to no avail so I plan to migrate the plate store from zustand to jotai as jotai is using react context.

zbeyens avatar Aug 29 '22 18:08 zbeyens

If anyone is interested, in my case it seems to work - not the timing issue, but it allows to Plate to be remounted. GL with this @zbeyens 🙂

VictorBaron avatar Aug 30 '22 12:08 VictorBaron

I think this issue is plaguing me with serializing and de-serializing HTML. TypeError: Cannot read properties of null (reading 'plugins') -- we use Plate to edit simple email contents and store the user input as HTML in the backend and want to rehydrate Plate with that HTML content. However, Editor is null... I think it's a race condition or a timing issue.

rmacy avatar Aug 30 '22 18:08 rmacy