Skip to content

Commit f00e111

Browse files
committed
Improve checkCompatibilityWithExistingValue comment
1 parent dfaa39b commit f00e111

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

lib/utils.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff 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};

0 commit comments

Comments
 (0)