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
This commit is contained in:
@@ -215,13 +215,19 @@ function initScrollObserver(
|
|||||||
function initViewportResizeObserver(
|
function initViewportResizeObserver(
|
||||||
cb: viewportResizeCallback,
|
cb: viewportResizeCallback,
|
||||||
): listenerHandler {
|
): listenerHandler {
|
||||||
|
let last_h = -1;
|
||||||
|
let last_w = -1;
|
||||||
const updateDimension = throttle(() => {
|
const updateDimension = throttle(() => {
|
||||||
const height = getWindowHeight();
|
const height = getWindowHeight();
|
||||||
const width = getWindowWidth();
|
const width = getWindowWidth();
|
||||||
|
if (last_h !== height || last_w != width) {
|
||||||
cb({
|
cb({
|
||||||
width: Number(width),
|
width: Number(width),
|
||||||
height: Number(height),
|
height: Number(height),
|
||||||
});
|
});
|
||||||
|
last_h = height;
|
||||||
|
last_w = width;
|
||||||
|
}
|
||||||
}, 200);
|
}, 200);
|
||||||
return on('resize', updateDimension, window);
|
return on('resize', updateDimension, window);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user