File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed
packages/runtime/src/cross Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -151,7 +151,7 @@ async function doApplyMutation(
151151 logging
152152 ) ;
153153
154- if ( r ) {
154+ if ( r && typeof r === 'object' ) {
155155 if ( ! arrayCloned ) {
156156 resultData = [ ...resultData ] ;
157157 arrayCloned = true ;
@@ -160,9 +160,12 @@ async function doApplyMutation(
160160 updated = true ;
161161 }
162162 }
163- } else {
163+ } else if ( resultData !== null && typeof resultData === 'object' ) {
164+ // Clone resultData to prevent mutations affecting the loop
165+ const currentData = { ...resultData } ;
166+
164167 // iterate over each field and apply mutation to nested data models
165- for ( const [ key , value ] of Object . entries ( resultData ) ) {
168+ for ( const [ key , value ] of Object . entries ( currentData ) ) {
166169 const fieldInfo = modelFields [ key ] ;
167170 if ( ! fieldInfo ?. isDataModel ) {
168171 continue ;
@@ -178,7 +181,7 @@ async function doApplyMutation(
178181 logging
179182 ) ;
180183
181- if ( r ) {
184+ if ( r && typeof r === 'object' ) {
182185 resultData = { ...resultData , [ key ] : r } ;
183186 updated = true ;
184187 }
You can’t perform that action at this time.
0 commit comments