Skip to content

Commit

Permalink
Restore restarted watchdog editor with current react state
Browse files Browse the repository at this point in the history
  • Loading branch information
Mati365 committed Oct 15, 2024
1 parent 2cea7d9 commit 69f4c3f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/useMultiRootEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,13 @@ const useMultiRootEditor = ( props: MultiRootHookProps ): MultiRootHookReturns =
current: 0
};

watchdog.setCreator( async ( data, config ) => {
// Keeping using `data` from creator function callback seems to be a good idea in theory,
// but in practice, it leads to instability. The `data` object can be changed during the editor
// initialization, which can lead to unexpected reset of value in the editor, that do not match
// with the current react state. To prevent this, we are using the `data` from the hook state.
// It's not super optimal, but it's the most stable solution at this moment.
// See more: https://github.com/ckeditor/ckeditor5-react/issues/542
watchdog.setCreator( async ( _, config ) => {
const { onAfterDestroy } = props;

if ( totalRestartsRef.current > 0 && onAfterDestroy && editorRefs.instance.current ) {
Expand Down

0 comments on commit 69f4c3f

Please sign in to comment.