ckeditor / ckeditor5-react

Official CKEditor 5 React component.
https://ckeditor.com/ckeditor-5
Other
426 stars 100 forks source link

Quick rerendering causes editor issues #471

Closed DawidKossowski closed 5 months ago

DawidKossowski commented 7 months ago

In StrictMode or in situations where the application quickly rerenders, the next editor instance is rerendered or attempts to rerender before the previous instance is destroyed, especially when the editor uses async calls (for example, for getting the cloud services token).

We've implemented a mechanism to keep track of the destroying promise (editorDestructionInProgress) and to wait for it to resolve before initializing the next editor instance. However, in some cases, the next editor instance is initialized before the previous one starts the destroying process (editorDestructionInProgress is null). This results in two editor instances on the page or in an error: CKEditorError: editor-source-element-already-used. The outcome depends on the integration.

This issue is non-deterministic and depends on the React versions, but it can be reproduced by adding the config with cloudServices property (in our demo: demo-react-18) to trigger a request for a token during editor initialization.

DawidKossowski commented 7 months ago

@Mati365 please check this mechanism in both integrations: CKEditor and useMultiRootEditor.

Mati365 commented 5 months ago

Fixed in https://github.com/ckeditor/ckeditor5-react/releases/tag/v7.0.0. Closing as done.