Skip to content

Commit 3f79832

Browse files
authored
Merge pull request #637 from huult/61584-chat-section-not-updating
fix chat section not updating
2 parents e2762ac + bd3458b commit 3f79832

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

lib/Onyx.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ function multiSet(data: OnyxMultiSetInput): Promise<void> {
238238

239239
const updatePromises = keyValuePairsToSet.map(([key, value]) => {
240240
const prevValue = cache.get(key, false);
241+
// When we use multiSet to set a key we want to clear the current delta changes from Onyx.merge that were queued
242+
// before the value was set. If Onyx.merge is currently reading the old value from storage, it will then not apply the changes.
243+
if (OnyxUtils.hasPendingMergeForKey(key)) {
244+
delete OnyxUtils.getMergeQueue()[key];
245+
}
241246

242247
// Update cache and optimistically inform subscribers on the next tick
243248
cache.set(key, value);

tests/unit/onyxTest.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,5 +2029,25 @@ describe('Onyx', () => {
20292029
[`${ONYX_KEYS.COLLECTION.TEST_KEY}entry2`]: {id: 'entry2_id', name: 'entry2_name'},
20302030
});
20312031
});
2032+
it('should clear pending merge for a key during multiSet()', async () => {
2033+
const testKey = `${ONYX_KEYS.COLLECTION.TEST_KEY}entry1`;
2034+
2035+
// Mock the merge queue with the correct type
2036+
const mockMergeQueue: Record<string, unknown[]> = {
2037+
[testKey]: [{some: 'mergeData'}],
2038+
};
2039+
2040+
// Mock the utility functions
2041+
jest.spyOn(OnyxUtils, 'hasPendingMergeForKey').mockImplementation((key) => key === testKey);
2042+
jest.spyOn(OnyxUtils, 'getMergeQueue').mockImplementation(() => mockMergeQueue);
2043+
2044+
await Onyx.multiSet({
2045+
[testKey]: {id: 'entry1_id', name: 'entry1_name'},
2046+
});
2047+
2048+
expect(mockMergeQueue[testKey]).toBeUndefined();
2049+
2050+
jest.restoreAllMocks();
2051+
});
20322052
});
20332053
});

0 commit comments

Comments
 (0)