react-native-onyx 3.0.101 → 3.0.102
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/OnyxUtils.js +16 -1
- package/package.json +1 -1
package/dist/OnyxUtils.js
CHANGED
|
@@ -1020,13 +1020,28 @@ function updateSnapshots(data, mergeFn) {
|
|
|
1020
1020
|
return [];
|
|
1021
1021
|
const promises = [];
|
|
1022
1022
|
const snapshotCollection = getCachedCollection(snapshotCollectionKey);
|
|
1023
|
+
// Multiset entries are keyless but update every key of their payload, so expand them into
|
|
1024
|
+
// per-key entries to keep cached snapshots in sync with the real Onyx data.
|
|
1025
|
+
const flattenedData = data.flatMap((entry) => {
|
|
1026
|
+
if (entry.onyxMethod === METHOD.MULTI_SET && typeof entry.key !== 'string' && entry.value && typeof entry.value === 'object' && !Array.isArray(entry.value)) {
|
|
1027
|
+
return Object.entries(entry.value).map(([key, value]) => ({ onyxMethod: METHOD.SET, key, value }));
|
|
1028
|
+
}
|
|
1029
|
+
return entry;
|
|
1030
|
+
});
|
|
1023
1031
|
for (const [snapshotEntryKey, snapshotEntryValue] of Object.entries(snapshotCollection)) {
|
|
1024
1032
|
// Snapshots may not be present in cache. We don't know how to update them so we skip.
|
|
1025
1033
|
if (!snapshotEntryValue) {
|
|
1026
1034
|
continue;
|
|
1027
1035
|
}
|
|
1028
1036
|
let updatedData = {};
|
|
1029
|
-
for (const { key, value } of
|
|
1037
|
+
for (const { key, value, onyxMethod } of flattenedData) {
|
|
1038
|
+
if (typeof key !== 'string') {
|
|
1039
|
+
// clear entries legitimately carry no key, and malformed multiset payloads are already logged by update() itself
|
|
1040
|
+
if (onyxMethod !== METHOD.CLEAR && onyxMethod !== METHOD.MULTI_SET) {
|
|
1041
|
+
Logger.logHmmm(`Invalid ${typeof key} key (method: ${onyxMethod}, key: ${String(key).slice(0, 50)}) provided in Onyx update. Skipping snapshot update for this entry.`);
|
|
1042
|
+
}
|
|
1043
|
+
continue;
|
|
1044
|
+
}
|
|
1030
1045
|
// snapshots are normal keys so we want to skip update if they are written to Onyx
|
|
1031
1046
|
if (OnyxKeys_1.default.isCollectionMemberKey(snapshotCollectionKey, key)) {
|
|
1032
1047
|
continue;
|