Skip to content

Commit 9ce1bc7

Browse files
committed
Better comments for future engineers
1 parent dad8aa4 commit 9ce1bc7

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

lib/Onyx.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ function merge<TKey extends OnyxKey>(key: TKey, changes: OnyxMergeInput<TKey>):
239239
const validChanges = mergeQueue[key].filter((change) => {
240240
const {isCompatible, existingValueType, newValueType, isEmptyArrayCoercion} = utils.checkCompatibilityWithExistingValue(change, existingValue);
241241
if (isEmptyArrayCoercion) {
242+
// Merging an object into an empty array isn't semantically correct, but we allow it
243+
// in case we accidentally encoded an empty object as an empty array in PHP. If you're
244+
// looking at a bugbot from this message, we're probably missing that key in OnyxKeys::KEYS_REQUIRING_EMPTY_OBJECT
242245
Logger.logAlert(`[ENSURE_BUGBOT] Onyx merge called on key "${key}" whose existing value is an empty array. Will coerce to object.`);
243246
}
244247
if (!isCompatible) {

lib/OnyxUtils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,6 +1345,9 @@ function setWithRetry<TKey extends OnyxKey>({key, value, options}: SetParams<TKe
13451345
// Check if the value is compatible with the existing value in the storage
13461346
const {isCompatible, existingValueType, newValueType, isEmptyArrayCoercion} = utils.checkCompatibilityWithExistingValue(value, existingValue);
13471347
if (isEmptyArrayCoercion) {
1348+
// Setting an object over empty array isn't semantically correct, but we allow it
1349+
// in case we accidentally encoded an empty object as an empty array in PHP. If you're
1350+
// looking at a bugbot from this message, we're probably missing that key in OnyxKeys::KEYS_REQUIRING_EMPTY_OBJECT
13481351
Logger.logAlert(`[ENSURE_BUGBOT] Onyx setWithRetry called on key "${key}" whose existing value is an empty array. Will coerce to object.`);
13491352
}
13501353
if (!isCompatible) {
@@ -1585,6 +1588,9 @@ function mergeCollectionWithPatches<TKey extends CollectionKeyBase>(
15851588
);
15861589

15871590
if (isEmptyArrayCoercion) {
1591+
// Merging an object into an empty array isn't semantically correct, but we allow it
1592+
// in case we accidentally encoded an empty object as an empty array in PHP. If you're
1593+
// looking at a bugbot from this message, we're probably missing that key in OnyxKeys::KEYS_REQUIRING_EMPTY_OBJECT
15881594
Logger.logAlert(`[ENSURE_BUGBOT] Onyx mergeCollection called on key "${key}" whose existing value is an empty array. Will coerce to object.`);
15891595
}
15901596
if (!isCompatible) {

0 commit comments

Comments
 (0)