File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -157,10 +157,22 @@ function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(
157157 ) ;
158158 } , [ previousKey , key , options ?. allowDynamicKey ] ) ;
159159
160+ // Track previous dependencies to prevent infinite loops
161+ const previousDependenciesRef = useRef < DependencyList > ( [ ] ) ;
162+
160163 useEffect ( ( ) => {
161164 // This effect will only run if the `dependencies` array changes. If it changes it will force the hook
162165 // to trigger a `getSnapshot()` update by calling the stored `onStoreChange()` function reference, thus
163166 // re-running the hook and returning the latest value to the consumer.
167+
168+ // Deep equality check to prevent infinite loops when dependencies array reference changes
169+ // but content remains the same
170+ if ( deepEqual ( previousDependenciesRef . current , dependencies ) ) {
171+ return ;
172+ }
173+
174+ previousDependenciesRef . current = dependencies ;
175+
164176 if ( connectionRef . current === null || isConnectingRef . current || ! onStoreChangeFnRef . current ) {
165177 return ;
166178 }
You can’t perform that action at this time.
0 commit comments