@@ -7,12 +7,12 @@ import { setupRouter, reset, whenRouteIdle, whenRoutePainted } from 'ember-app-s
7
7
import { gte } from 'ember-compatibility-helpers' ;
8
8
import { getScrollBarWidth } from './utils/scrollbar-width' ;
9
9
10
- let scrollBarWidth = getScrollBarWidth ( ) ;
11
10
const body = document . body ;
12
11
const html = document . documentElement ;
13
12
let ATTEMPTS = 0 ;
14
13
const MAX_ATTEMPTS = 100 ; // rAF runs every 16ms ideally, so 60x a second
15
14
let requestId ;
15
+ let scrollBarWidth = 0 ;
16
16
17
17
/**
18
18
* By default, we start checking to see if the document height is >= the last known `y` position
@@ -25,14 +25,17 @@ let requestId;
25
25
* @void
26
26
*/
27
27
function tryScrollRecursively ( fn , scrollHash ) {
28
- requestId = window . requestAnimationFrame ( ( ) => {
29
- const documentWidth = Math . max ( body . scrollWidth , body . offsetWidth ,
30
- html . clientWidth , html . scrollWidth , html . offsetWidth ) ;
31
- const documentHeight = Math . max ( body . scrollHeight , body . offsetHeight ,
32
- html . clientHeight , html . scrollHeight , html . offsetHeight ) ;
28
+ // read DOM outside of rAF
29
+ const documentWidth = Math . max ( body . scrollWidth , body . offsetWidth ,
30
+ html . clientWidth , html . scrollWidth , html . offsetWidth ) ;
31
+ const documentHeight = Math . max ( body . scrollHeight , body . offsetHeight ,
32
+ html . clientHeight , html . scrollHeight , html . offsetHeight ) ;
33
+ const { innerHeight, innerWidth } = window ;
33
34
34
- if ( documentWidth + scrollBarWidth - window . innerWidth >= scrollHash . x
35
- && documentHeight + scrollBarWidth - window . innerHeight >= scrollHash . y
35
+ requestId = window . requestAnimationFrame ( ( ) => {
36
+ // write DOM (scrollTo causes reflow)
37
+ if ( documentWidth + scrollBarWidth - innerWidth >= scrollHash . x
38
+ && documentHeight + scrollBarWidth - innerHeight >= scrollHash . y
36
39
|| ATTEMPTS >= MAX_ATTEMPTS ) {
37
40
ATTEMPTS = 0 ;
38
41
fn . call ( null , scrollHash . x , scrollHash . y ) ;
@@ -65,6 +68,9 @@ let RouterScrollMixin = Mixin.create({
65
68
this . _routeDidChange ( transition ) ;
66
69
} ) ;
67
70
}
71
+ if ( ! get ( this , 'isFastBoot' ) ) {
72
+ scrollBarWidth = getScrollBarWidth ( ) ;
73
+ }
68
74
} ,
69
75
70
76
destroy ( ) {
0 commit comments