Skip to content

Commit f2b0a64

Browse files
committed
Address comments
1 parent 478c55e commit f2b0a64

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

lib/OnyxUtils.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ let lastSubscriptionID = 0;
100100
// Connections can be made before `Onyx.init`. They would wait for this task before resolving
101101
const deferredInitTask = createDeferredTask();
102102

103-
// Holds a set of collection member IDs which updates will be ignored when using Onyx methods.
103+
// Collection member IDs that Onyx should silently ignore across all operations — reads, writes, cache, and subscriber
104+
// notifications. This is used to filter out keys formed from invalid/default IDs (e.g. "-1", "0",
105+
// "undefined", "null", "NaN") that can appear when an ID variable is accidentally coerced to string.
104106
let skippableCollectionMemberIDs = new Set<string>();
105107
// Holds a set of keys that should always be merged into snapshot entries.
106108
let snapshotMergeKeys = new Set<string>();
@@ -1119,7 +1121,7 @@ function initializeWithDefaultKeyStates(): Promise<void> {
11191121
.then((pairs) => {
11201122
const allDataFromStorage: Record<string, unknown> = {};
11211123
for (const [key, value] of pairs) {
1122-
// RAM-only keys should never be loaded from storage as they may have stale persisted data
1124+
// RAM-only keys should not be cached from storage as they may have stale persisted data
11231125
// from before the key was migrated to RAM-only.
11241126
if (isRamOnlyKey(key)) {
11251127
continue;
@@ -1159,7 +1161,9 @@ function initializeWithDefaultKeyStates(): Promise<void> {
11591161

11601162
// Notify subscribers about default key states so that any subscriber that connected
11611163
// before init (e.g. during module load) receives the merged default values immediately
1162-
for (const [key, value] of Object.entries(merged ?? {})) keyChanged(key, value);
1164+
for (const [key, value] of Object.entries(merged ?? {})) {
1165+
keyChanged(key, value);
1166+
}
11631167
})
11641168
.catch((error) => {
11651169
Logger.logAlert(`Failed to load data from storage during init. The app will boot with default key states only. Error: ${error}`);
@@ -1175,7 +1179,9 @@ function initializeWithDefaultKeyStates(): Promise<void> {
11751179

11761180
// Notify subscribers about default key states so that any subscriber that connected
11771181
// before init (e.g. during module load) receives the merged default values immediately
1178-
for (const [key, value] of Object.entries(defaultKeyStates)) keyChanged(key, value);
1182+
for (const [key, value] of Object.entries(defaultKeyStates)) {
1183+
keyChanged(key, value);
1184+
}
11791185
});
11801186
}
11811187

lib/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,9 @@ type InitOptions = {
421421
enableDevTools?: boolean;
422422

423423
/**
424-
* Array of collection member IDs which updates will be ignored when using Onyx methods.
425-
* Additionally, any subscribers from these keys to won't receive any data from Onyx.
424+
* Array of collection member IDs that Onyx should silently ignore across all operations.
425+
* This prevents keys formed from invalid or default IDs (e.g. "-1", "0", "undefined") from
426+
* polluting cache or triggering subscriber notifications.
426427
*/
427428
skippableCollectionMemberIDs?: string[];
428429

0 commit comments

Comments
 (0)