From f09915b7593bdbb57cca4e04221b2088fb69e43f Mon Sep 17 00:00:00 2001 From: f1ames Date: Thu, 26 Sep 2024 11:39:38 +0200 Subject: [PATCH] Chore: Apply minor code corrections. --- src/useMultiRootEditor.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/useMultiRootEditor.tsx b/src/useMultiRootEditor.tsx index e9a9483..52f05de 100644 --- a/src/useMultiRootEditor.tsx +++ b/src/useMultiRootEditor.tsx @@ -505,7 +505,7 @@ const useMultiRootEditor = ( props: MultiRootHookProps ): MultiRootHookReturns = data || /* istanbul ignore next -- @preserve: It should never happen, data should be always filled. */ {} ); - const hasModifiedData = dataKeys.filter( rootName => + const modifiedRoots = dataKeys.filter( rootName => editorData[ rootName ] !== undefined && JSON.stringify( editorData[ rootName ] ) !== JSON.stringify( data[ rootName ] ) ); @@ -531,7 +531,10 @@ const useMultiRootEditor = ( props: MultiRootHookProps ): MultiRootHookReturns = }; const _updateEditorData = ( roots: Array ) => { - const dataToUpdate = roots.reduce( ( result, rootName ) => ( { ...result, [ rootName ]: data[ rootName ] } ), {} ); + const dataToUpdate = roots.reduce( + ( result, rootName ) => ( { ...result, [ rootName ]: data[ rootName ] } ), + Object.create( null ) + ); instance.data.set( dataToUpdate, { suppressErrorInCollaboration: true } as any ); }; @@ -552,8 +555,8 @@ const useMultiRootEditor = ( props: MultiRootHookProps ): MultiRootHookReturns = _handleNewRoots( newRoots ); _handleRemovedRoots( removedRoots ); - if ( hasModifiedData.length ) { - _updateEditorData( hasModifiedData ); + if ( modifiedRoots.length ) { + _updateEditorData( modifiedRoots ); } if ( rootsWithChangedAttributes.length ) {