From de00a2202a2be7fa6cdb848d44edf762831ab2a5 Mon Sep 17 00:00:00 2001 From: Huu Le <20178761+huult@users.noreply.github.com> Date: Fri, 1 Nov 2024 21:30:41 +0700 Subject: [PATCH] fix update snapshot assignment to merge existing values instead of overwriting --- lib/Onyx.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Onyx.ts b/lib/Onyx.ts index 3f5d75ff..91c44e91 100644 --- a/lib/Onyx.ts +++ b/lib/Onyx.ts @@ -556,7 +556,7 @@ function updateSnapshots(data: OnyxUpdate[]) { return; } - let updatedData = {}; + let updatedData: Record = {}; data.forEach(({key, value}) => { // snapshots are normal keys so we want to skip update if they are written to Onyx @@ -573,7 +573,10 @@ function updateSnapshots(data: OnyxUpdate[]) { return; } - updatedData = {...updatedData, [key]: lodashPick(value, Object.keys(snapshotData[key]))}; + const oldValue = updatedData[key] || {}; + const newValue = lodashPick(value, Object.keys(snapshotData[key])); + + updatedData = {...updatedData, [key]: Object.assign(oldValue, newValue)}; }); // Skip the update if there's no data to be merged