Skip to content

Commit

Permalink
Merge pull request #546 from ckeditor/ck/542
Browse files Browse the repository at this point in the history
Fix: Prevent potential crashes of `useMultiRootEditor` during the initialization phase when setting the new state of the multi-root editor with an attached watchdog. Closes #542
  • Loading branch information
Mati365 authored Oct 16, 2024
2 parents 2cea7d9 + 69f4c3f commit 4df6509
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 4df6509

Please sign in to comment.