Skip to content

Commit 971b177

Browse files
authored
Merge pull request Expensify#659 from callstack-internal/fix/set-shared-object-reference
fix: shared object references in set() and removeNestedNullValues
2 parents 8721252 + 48d2852 commit 971b177

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lib/Onyx.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ function set<TKey extends OnyxKey>(key: TKey, value: OnyxSetInput<TKey>, options
180180
return Promise.resolve();
181181
}
182182

183-
const valueWithoutNestedNullValues = (options?.skipNullRemoval ? value : utils.removeNestedNullValues(value)) as OnyxValue<TKey>;
183+
const valueWithoutNestedNullValues = (options?.skipNullRemoval ? {...value} : utils.removeNestedNullValues(value)) as OnyxValue<TKey>;
184184
const hasChanged = options?.skipCacheCheck ? true : cache.hasValueChanged(key, valueWithoutNestedNullValues);
185185

186186
OnyxUtils.logKeyChanged(OnyxUtils.METHOD.SET, key, value, hasChanged);

lib/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,12 @@ function isMergeableObject<TObject extends Record<string, unknown>>(value: unkno
172172

173173
/** Deep removes the nested null values from the given value. */
174174
function removeNestedNullValues<TValue extends OnyxInput<OnyxKey> | null>(value: TValue): TValue {
175-
if (value === null || value === undefined) {
175+
if (value === null || value === undefined || typeof value !== 'object') {
176176
return value;
177177
}
178178

179-
if (typeof value !== 'object' || Array.isArray(value)) {
180-
return value;
179+
if (Array.isArray(value)) {
180+
return [...value] as TValue;
181181
}
182182

183183
const result: Record<string, unknown> = {};

0 commit comments

Comments
 (0)