Skip to content

Commit 3b1ff51

Browse files
committed
use reference comparison for memoized selectors values
1 parent b653313 commit 3b1ff51

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

lib/useOnyx.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,15 @@ function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(
273273
}
274274

275275
// Optimized equality checking:
276-
// - For memoized selectors, use deep equality since reference equality is too strict when cache is involved
276+
// - Memoized selectors already handle deep equality internally, so we can use fast reference equality
277277
// - Non-selector cases use shallow equality for object reference checks
278278
// - Normalize null to undefined to ensure consistent comparison (both represent "no value")
279279
let areValuesEqual: boolean;
280280
if (memoizedSelector) {
281281
const normalizedPrevious = previousValueRef.current ?? undefined;
282282
const normalizedNew = newValueRef.current ?? undefined;
283-
areValuesEqual = deepEqual(normalizedPrevious, normalizedNew);
283+
areValuesEqual = normalizedPrevious === normalizedNew;
284+
console.log('[p] we are checking the previous value now for key', key, 'is equal?', areValuesEqual);
284285
} else {
285286
areValuesEqual = shallowEqual(previousValueRef.current ?? undefined, newValueRef.current);
286287
}

0 commit comments

Comments
 (0)