@@ -422,19 +422,30 @@ export function getInstanceFromHostFiber(fiber: Fiber): Instance {
422
422
}
423
423
}
424
424
425
+ let searchTarget = null ;
426
+ let searchBoundary = null ;
427
+ function pushSearchTarget ( target : null | Fiber ) : void {
428
+ searchTarget = target ;
429
+ }
430
+ function popSearchTarget ( ) : null | Fiber {
431
+ return searchTarget ;
432
+ }
433
+ function pushSearchBoundary ( value : null | Fiber ) : void {
434
+ searchBoundary = value ;
435
+ }
436
+ function popSearchBoundary ( ) : null | Fiber {
437
+ return searchBoundary ;
438
+ }
439
+
425
440
export function getNextSiblingHostFiber ( fiber : Fiber ) : null | Fiber {
426
- const searchState = { next : null } ;
427
- traverseVisibleHostChildren (
428
- fiber . sibling ,
429
- false ,
430
- findNextSibling ,
431
- searchState ,
432
- ) ;
433
- return searchState . next ;
441
+ traverseVisibleHostChildren ( fiber . sibling , false , findNextSibling ) ;
442
+ const sibling = popSearchTarget ( ) ;
443
+ pushSearchTarget ( null ) ;
444
+ return sibling ;
434
445
}
435
446
436
- function findNextSibling ( child : Fiber , state : { next : null | Fiber } ) : boolean {
437
- state . next = child ;
447
+ function findNextSibling ( child : Fiber ) : boolean {
448
+ pushSearchTarget ( child ) ;
438
449
return true ;
439
450
}
440
451
@@ -467,29 +478,28 @@ export function isFiberPreceding(fiber: Fiber, otherFiber: Fiber): boolean {
467
478
if ( commonAncestor === null ) {
468
479
return false ;
469
480
}
470
- const searchState = { found : false } ;
471
481
traverseVisibleHostChildren (
472
482
commonAncestor ,
473
483
true ,
474
484
isFiberPrecedingCheck ,
475
485
otherFiber ,
476
486
fiber ,
477
- searchState ,
478
487
) ;
479
- return searchState . found ;
488
+ const target = popSearchTarget ( ) ;
489
+ pushSearchTarget ( null ) ;
490
+ return target !== null ;
480
491
}
481
492
482
493
function isFiberPrecedingCheck (
483
494
child : Fiber ,
484
495
target : Fiber ,
485
496
boundary : Fiber ,
486
- state : { found : boolean } ,
487
497
) : boolean {
488
498
if ( child === boundary ) {
489
499
return true ;
490
500
}
491
501
if ( child === target ) {
492
- state . found = true ;
502
+ pushSearchTarget ( child ) ;
493
503
return true ;
494
504
}
495
505
return false ;
@@ -504,30 +514,33 @@ export function isFiberFollowing(fiber: Fiber, otherFiber: Fiber): boolean {
504
514
if ( commonAncestor === null ) {
505
515
return false ;
506
516
}
507
- const searchState = { foundFiber : false , foundOther : false } ;
508
517
traverseVisibleHostChildren (
509
518
commonAncestor ,
510
519
true ,
511
520
isFiberFollowingCheck ,
512
521
otherFiber ,
513
522
fiber ,
514
- searchState ,
515
523
) ;
516
- return searchState . foundOther ;
524
+ const target = popSearchTarget ( ) ;
525
+ pushSearchTarget ( null ) ;
526
+ pushSearchBoundary ( null ) ;
527
+ return target !== null ;
517
528
}
518
529
519
530
function isFiberFollowingCheck (
520
531
child : Fiber ,
521
532
target : Fiber ,
522
533
boundary : Fiber ,
523
- state : { foundFiber : boolean , foundOther : boolean } ,
524
534
) : boolean {
525
535
if ( child === boundary ) {
526
- state . foundFiber = true ;
536
+ pushSearchBoundary ( child ) ;
527
537
return false ;
528
538
}
529
539
if ( child === target ) {
530
- state . foundOther = state . foundFiber ;
540
+ // The target is only following if we already found the boundary.
541
+ if ( popSearchBoundary ( ) !== null ) {
542
+ pushSearchTarget ( child ) ;
543
+ }
531
544
return true ;
532
545
}
533
546
return false ;
0 commit comments