Skip to content

Commit

Permalink
Protect against generation of no-change viewport resize events. (rrwe…
Browse files Browse the repository at this point in the history
…b-io#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
  • Loading branch information
eoghanmurray committed Feb 22, 2021
1 parent 8f93b98 commit a921e99
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 @@ -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);
}
Expand Down

0 comments on commit a921e99

Please sign in to comment.