From c73be965a021fcc51e766b90bdab90bd11cf43ff Mon Sep 17 00:00:00 2001 From: Adrien Denat Date: Wed, 13 Nov 2019 16:37:19 -0300 Subject: [PATCH] fix: rework raq hack to fix instantiation not happening if element hidden (fix #406) --- packages/simplebar/src/simplebar.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/simplebar/src/simplebar.js b/packages/simplebar/src/simplebar.js index 623941bc..386923f4 100755 --- a/packages/simplebar/src/simplebar.js +++ b/packages/simplebar/src/simplebar.js @@ -293,17 +293,20 @@ export default class SimpleBar { window.addEventListener('resize', this.onWindowResize); // Hack for https://github.com/WICG/ResizeObserver/issues/38 - let ignoredCallbacks = 0; + let resizeObserverStarted = false; this.resizeObserver = new ResizeObserver(() => { - ignoredCallbacks++; - if (ignoredCallbacks === 1) return; + if (!resizeObserverStarted) return; this.recalculate(); }); this.resizeObserver.observe(this.el); this.resizeObserver.observe(this.contentEl); + window.requestAnimationFrame(() => { + resizeObserverStarted = true; + }); + // This is required to detect horizontal scroll. Vertical scroll only needs the resizeObserver. this.mutationObserver = new MutationObserver(this.recalculate);