File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -216,8 +216,13 @@ function checkCompatibilityWithExistingValue(
216216 isCompatible : true ,
217217 } ;
218218 }
219- // An empty array existing value is compatible with an object update.
220- // PHP's json_encode produces [] for empty associative arrays that should be {}.
219+
220+ // PHP's associative arrays cannot distinguish between an empty list and an
221+ // empty object, so it encodes both as []. A key that should hold an
222+ // object may arrive from the server as [] and be stored that way. If
223+ // we then try to MERGE an object into that key, the array-vs-object type check
224+ // would normally block it. Since an empty array carries no data worth
225+ // preserving, we treat it as compatible with an object update and coerce it.
221226 const isObjectValue = typeof value === 'object' && ! Array . isArray ( value ) ;
222227 if ( Array . isArray ( existingValue ) && existingValue . length === 0 && isObjectValue ) {
223228 return { isCompatible : true , isEmptyArrayCoercion : true } ;
You can’t perform that action at this time.
0 commit comments