@@ -166,7 +166,6 @@ export const iterableEquality = (
166
166
if ( a . constructor !== b . constructor ) {
167
167
return false ;
168
168
}
169
-
170
169
let length = aStack . length ;
171
170
while ( length -- ) {
172
171
// Linear search. Performance is inversely proportional to the number of
@@ -290,20 +289,25 @@ export const subsetEquality = (
290
289
291
290
return Object . keys ( subset ) . every ( key => {
292
291
if ( isObjectWithKeys ( subset [ key ] ) ) {
293
- if ( seenReferences . get ( subset [ key ] ) ) {
292
+ if ( seenReferences . has ( subset [ key ] ) ) {
294
293
return equals ( object [ key ] , subset [ key ] , [ iterableEquality ] ) ;
295
294
}
296
295
seenReferences . set ( subset [ key ] , true ) ;
297
296
}
298
-
299
- return (
297
+ const result =
300
298
object != null &&
301
299
hasOwnProperty ( object , key ) &&
302
300
equals ( object [ key ] , subset [ key ] , [
303
301
iterableEquality ,
304
302
subsetEqualityWithContext ( seenReferences ) ,
305
- ] )
306
- ) ;
303
+ ] ) ;
304
+ // The main goal of using seenReference is to avoid circular node on tree.
305
+ // It will only happen within a parent and its child, not a node and nodes next to it (same level)
306
+ // We should keep the reference for a parent and its child only
307
+ // Thus we should delete the reference immediately so that it doesn't interfere
308
+ // other nodes within the same level on tree.
309
+ seenReferences . delete ( subset [ key ] ) ;
310
+ return result ;
307
311
} ) ;
308
312
} ;
309
313
0 commit comments