@@ -15,6 +15,7 @@ import { createStyles } from './styles';
1515
1616interface State {
1717 didMountUniversal : boolean ;
18+ scrollbarWidth : number ;
1819}
1920
2021export class Scrollbars extends Component < ScrollbarsProps , State > {
@@ -94,6 +95,7 @@ export class Scrollbars extends Component<ScrollbarsProps, State> {
9495
9596 this . state = {
9697 didMountUniversal : false ,
98+ scrollbarWidth : getScrollbarWidth ( ) ,
9799 } ;
98100 }
99101
@@ -260,7 +262,8 @@ export class Scrollbars extends Component<ScrollbarsProps, State> {
260262
261263 const { view, trackHorizontal, trackVertical, thumbHorizontal, thumbVertical } = this ;
262264 view . addEventListener ( 'scroll' , this . handleScroll ) ;
263- if ( ! getScrollbarWidth ( ) ) return ;
265+
266+ if ( ! this . state . scrollbarWidth ) return ;
264267
265268 trackHorizontal . addEventListener ( 'mouseenter' , this . handleTrackMouseEnter ) ;
266269 trackHorizontal . addEventListener ( 'mouseleave' , this . handleTrackMouseLeave ) ;
@@ -286,7 +289,9 @@ export class Scrollbars extends Component<ScrollbarsProps, State> {
286289 return ;
287290 const { view, trackHorizontal, trackVertical, thumbHorizontal, thumbVertical } = this ;
288291 view . removeEventListener ( 'scroll' , this . handleScroll ) ;
289- if ( ! getScrollbarWidth ( ) ) return ;
292+
293+ if ( ! this . state . scrollbarWidth ) return ;
294+
290295 trackHorizontal . removeEventListener ( 'mouseenter' , this . handleTrackMouseEnter ) ;
291296 trackHorizontal . removeEventListener ( 'mouseleave' , this . handleTrackMouseLeave ) ;
292297 trackHorizontal . removeEventListener ( 'mousedown' , this . handleHorizontalTrackMouseDown ) ;
@@ -504,7 +509,14 @@ export class Scrollbars extends Component<ScrollbarsProps, State> {
504509 _update ( callback ) {
505510 const { onUpdate, hideTracksWhenNotNeeded } = this . props ;
506511 const values = this . getValues ( ) ;
507- if ( getScrollbarWidth ( ) ) {
512+
513+ const freshScrollbarWidth = getScrollbarWidth ( ) ;
514+
515+ if ( this . state . scrollbarWidth !== freshScrollbarWidth ) {
516+ this . setState ( { scrollbarWidth : freshScrollbarWidth } ) ;
517+ }
518+
519+ if ( this . state . scrollbarWidth ) {
508520 const { scrollLeft, clientWidth, scrollWidth } = values ;
509521 const trackHorizontalWidth = getInnerWidth ( this . trackHorizontal ) ;
510522
@@ -543,7 +555,8 @@ export class Scrollbars extends Component<ScrollbarsProps, State> {
543555 }
544556
545557 render ( ) {
546- const scrollbarWidth = getScrollbarWidth ( ) ;
558+ const { scrollbarWidth, didMountUniversal } = this . state ;
559+
547560 /* eslint-disable no-unused-vars */
548561 const {
549562 autoHeight,
@@ -570,12 +583,11 @@ export class Scrollbars extends Component<ScrollbarsProps, State> {
570583 thumbMinSize,
571584 thumbSize,
572585 universal,
586+ disableDefaultStyles,
573587 ...props
574588 } = this . props ;
575589 /* eslint-enable no-unused-vars */
576590
577- const { didMountUniversal } = this . state ;
578-
579591 const {
580592 containerStyleAutoHeight,
581593 containerStyleDefault,
0 commit comments