Skip to content

Commit

Permalink
Protect against generation of no-change viewport resize events.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
eoghanmurray committed Jan 4, 2021
1 parent 76d9f7a commit cc537a3
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/record/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,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);
}
Expand Down

0 comments on commit cc537a3

Please sign in to comment.