From a921e99ef079b2c604f27742d9351bac13cc9965 Mon Sep 17 00:00:00 2001 From: Eoghan Murray Date: Tue, 5 Jan 2021 02:22:38 +0000 Subject: [PATCH] Protect against generation of no-change viewport resize events. (#454) I noticed 8 or 10 of these events being generated in a multi-tab browsing session on Chrome 87.0 on Win10. I'm speculating they were generated as a side effect of changing tabs but I can't recreate --- src/record/observer.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/record/observer.ts b/src/record/observer.ts index de471ba771..895ca39d67 100644 --- a/src/record/observer.ts +++ b/src/record/observer.ts @@ -215,13 +215,19 @@ function initScrollObserver( function initViewportResizeObserver( cb: viewportResizeCallback, ): listenerHandler { + let last_h = -1; + let last_w = -1; const updateDimension = throttle(() => { const height = getWindowHeight(); const width = getWindowWidth(); - cb({ - width: Number(width), - height: Number(height), - }); + if (last_h !== height || last_w != width) { + cb({ + width: Number(width), + height: Number(height), + }); + last_h = height; + last_w = width; + } }, 200); return on('resize', updateDimension, window); }