@@ -426,6 +426,18 @@ function calculateDelayMS(delay: ?number, min = 0, fallback = 0) {
426
426
return Math . max ( min , maybeNumber != null ? maybeNumber : fallback ) ;
427
427
}
428
428
429
+ function isNodeFixedPositioned ( node : Node | null | void ) : boolean {
430
+ return (
431
+ node != null &&
432
+ ( node : any ) . offsetParent === null &&
433
+ ! isNodeDocumentNode ( node . parentNode )
434
+ ) ;
435
+ }
436
+
437
+ function isNodeDocumentNode ( node : Node | null | void ) : boolean {
438
+ return node != null && node . nodeType === Node . DOCUMENT_NODE ;
439
+ }
440
+
429
441
function getAbsoluteBoundingClientRect (
430
442
target : Element ,
431
443
) : { left: number , right : number , bottom : number , top : number } {
@@ -440,25 +452,23 @@ function getAbsoluteBoundingClientRect(
440
452
const parent = node . parentNode ;
441
453
const scrollTop = ( node : any ) . scrollTop ;
442
454
const scrollLeft = ( node : any ) . scrollLeft ;
443
- const isParentDocumentNode =
444
- parent != null && parent . nodeType === Node . DOCUMENT_NODE ;
445
-
446
- // Check if the current node is fixed position, by using
447
- // offsetParent node for a fast-path. Then we need to
448
- // check if it's a scrollable container by checking if
449
- // either scrollLeft or scrollTop are not 0. If it is
450
- // a scrollable container and the parent node is not
451
- // the document, then we can stop traversing the tree.
455
+
456
+ // We first need to check if it's a scrollable container by
457
+ // checking if either scrollLeft or scrollTop are not 0.
458
+ // Then we check if either the current node or its parent
459
+ // are fixed position, using offsetParent node for a fast-path.
460
+ // We need to check both as offsetParent accounts for both
461
+ // itself and the parent; so we need to align with that API.
462
+ // If these all pass, we can stop traversing the tree.
452
463
if (
453
- ! isParentDocumentNode &&
454
- ( node : any ) . offsetParent === null &&
455
- ( scrollLeft !== 0 || scrollTop !== 0 )
464
+ ( scrollLeft !== 0 || scrollTop !== 0 ) &&
465
+ ( isNodeFixedPositioned ( parent ) || isNodeFixedPositioned ( node ) )
456
466
) {
457
467
break ;
458
468
}
459
469
offsetX += scrollLeft ;
460
470
offsetY += scrollTop ;
461
- if ( isParentDocumentNode ) {
471
+ if ( isNodeDocumentNode ( parent ) ) {
462
472
break ;
463
473
}
464
474
node = parent ;
0 commit comments