From 7a5c5a24beb7e3968ce47df61116b19b3e4ad3e1 Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Fri, 11 Jul 2025 12:17:25 +0200 Subject: [PATCH 1/2] fix: prevent shared object references in set() and removeNestedNullValues() --- lib/Onyx.ts | 2 +- lib/utils.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/Onyx.ts b/lib/Onyx.ts index 39215bfa9..9a0444fbf 100644 --- a/lib/Onyx.ts +++ b/lib/Onyx.ts @@ -180,7 +180,7 @@ function set(key: TKey, value: OnyxSetInput, options return Promise.resolve(); } - const valueWithoutNestedNullValues = (options?.skipNullRemoval ? value : utils.removeNestedNullValues(value)) as OnyxValue; + const valueWithoutNestedNullValues = (options?.skipNullRemoval ? {...value} : utils.removeNestedNullValues(value)) as OnyxValue; const hasChanged = options?.skipCacheCheck ? true : cache.hasValueChanged(key, valueWithoutNestedNullValues); OnyxUtils.logKeyChanged(OnyxUtils.METHOD.SET, key, value, hasChanged); diff --git a/lib/utils.ts b/lib/utils.ts index c8e69e898..c07032895 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -176,10 +176,14 @@ function removeNestedNullValues | null>(value: return value; } - if (typeof value !== 'object' || Array.isArray(value)) { + if (typeof value !== 'object') { return value; } + if (Array.isArray(value)) { + return [...value] as TValue; + } + const result: Record = {}; // eslint-disable-next-line no-restricted-syntax, guard-for-in From 48d28525a5f2b78b006da87c1598eb7f24e3178b Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Fri, 11 Jul 2025 13:08:07 +0200 Subject: [PATCH 2/2] merge early return conditions --- lib/utils.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/utils.ts b/lib/utils.ts index c07032895..6e1561588 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -172,11 +172,7 @@ function isMergeableObject>(value: unkno /** Deep removes the nested null values from the given value. */ function removeNestedNullValues | null>(value: TValue): TValue { - if (value === null || value === undefined) { - return value; - } - - if (typeof value !== 'object') { + if (value === null || value === undefined || typeof value !== 'object') { return value; }