From 846fe18731da035a0a3a9a4345fb27bfc8c05ec2 Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Tue, 31 Oct 2023 16:44:56 -0400 Subject: [PATCH 1/2] Don't remove nulls in cache merge --- lib/OnyxCache.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OnyxCache.js b/lib/OnyxCache.js index f65da089..bdae5c0a 100644 --- a/lib/OnyxCache.js +++ b/lib/OnyxCache.js @@ -121,7 +121,7 @@ class OnyxCache { // lodash adds a small overhead so we don't use it here // eslint-disable-next-line prefer-object-spread, rulesdir/prefer-underscore-method - this.storageMap = Object.assign({}, utils.fastMerge(this.storageMap, data)); + this.storageMap = Object.assign({}, utils.fastMerge(this.storageMap, data, false)); const storageKeys = this.getAllKeys(); const mergedKeys = _.keys(data); From c5828fbccda270ee2e3b4c2b3624e4bb6f664fa6 Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Tue, 31 Oct 2023 16:59:43 -0400 Subject: [PATCH 2/2] Add test --- tests/unit/onyxCacheTest.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/unit/onyxCacheTest.js b/tests/unit/onyxCacheTest.js index 65fa7ea3..fa03e362 100644 --- a/tests/unit/onyxCacheTest.js +++ b/tests/unit/onyxCacheTest.js @@ -347,6 +347,18 @@ describe('Onyx', () => { expect(() => cache.merge(0)).toThrow(); expect(() => cache.merge({})).not.toThrow(); }); + + it('Should merge `null` values', () => { + // `null` values can override existing values and should also + // be preserved during merges. + cache.set('mockKey', {ID: 5}); + cache.set('mockNullKey', null); + + cache.merge({mockKey: null}); + + expect(cache.getValue('mockKey')).toEqual(null); + expect(cache.getValue('mockNullKey')).toEqual(null); + }); }); describe('hasPendingTask', () => {