Skip to content

Commit d83e8b7

Browse files
committed
Address comments
1 parent a4d5632 commit d83e8b7

3 files changed

Lines changed: 9 additions & 12 deletions

File tree

lib/OnyxSnapshotCache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class OnyxSnapshotCache {
6464
*/
6565
registerConsumer<TKey extends OnyxKey, TReturnValue>(options: Pick<UseOnyxOptions<TKey, TReturnValue>, 'selector'>): string {
6666
const selectorID = options?.selector ? this.getSelectorID(options.selector) : 'no_selector';
67-
const cacheKey = `${selectorID}`;
67+
const cacheKey = String(selectorID);
6868

6969
// Increment reference count for this cache key
7070
const currentCount = this.cacheKeyRefCounts.get(cacheKey) || 0;

lib/OnyxUtils.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -817,11 +817,12 @@ function retryOperation<TMethod extends RetriableOnyxOperation>(error: Error, on
817817
* Notifies subscribers and writes current value to cache
818818
*/
819819
function broadcastUpdate<TKey extends OnyxKey>(key: TKey, value: OnyxValue<TKey>, hasChanged?: boolean): void {
820-
if (hasChanged) {
821-
cache.set(key, value);
820+
if (!hasChanged) {
821+
return;
822822
}
823823

824-
keyChanged(key, value, () => !!hasChanged);
824+
cache.set(key, value);
825+
keyChanged(key, value);
825826
}
826827

827828
function hasPendingMergeForKey(key: OnyxKey): boolean {

tests/unit/OnyxSnapshotCacheTest.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,10 @@ describe('OnyxSnapshotCache', () => {
4444
const keyWithoutSelector = cache.registerConsumer(optionsWithoutSelector);
4545
const keyWithUndefined = cache.registerConsumer({});
4646

47-
// Different option combinations should produce different cache keys
48-
expect(keyWithSelector).toContain('0'); // Should contain selector ID
49-
expect(keyWithoutSelector).toContain('no_selector'); // Should indicate no selector
50-
expect(keyWithUndefined).toContain('no_selector'); // Should indicate no selector
51-
52-
// Selector key is unique; the two no-selector keys are equal
53-
expect(keyWithSelector).not.toEqual(keyWithoutSelector);
54-
expect(keyWithoutSelector).toEqual(keyWithUndefined);
47+
// Selector cache keys are the selector ID as a string; no-selector consumers share the same key
48+
expect(keyWithSelector).toBe('0');
49+
expect(keyWithoutSelector).toBe('no_selector');
50+
expect(keyWithUndefined).toBe('no_selector');
5551
});
5652

5753
it('should store and retrieve cached results', () => {

0 commit comments

Comments
 (0)