Skip to content

Commit

Permalink
Merge pull request #411 from janicduplessis/@janic/fix-cache-merge
Browse files Browse the repository at this point in the history
Don't remove nulls in cache merge
  • Loading branch information
mountiny authored Nov 6, 2023
2 parents d12bfcc + c5828fb commit 25612df
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/OnyxCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/onyxCacheTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 25612df

Please sign in to comment.