Skip to content

Commit 76c7465

Browse files
devvaannshabose
authored andcommitted
feat: add raf on resize
1 parent 95737b7 commit 76c7465

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,18 @@ function RemoteFunctions(config = {}) {
961961
});
962962
}
963963

964-
window.addEventListener("resize", redrawEverything);
964+
// Throttle resize redraws to one per animation frame — avoids redundant
965+
// layout reads when the browser fires multiple resize events per frame.
966+
let _pendingResizeRAF = null;
967+
function _onWindowResize() {
968+
if (!_pendingResizeRAF) {
969+
_pendingResizeRAF = requestAnimationFrame(function () {
970+
_pendingResizeRAF = null;
971+
redrawEverything();
972+
});
973+
}
974+
}
975+
window.addEventListener("resize", _onWindowResize);
965976

966977
/**
967978
* Constructor

0 commit comments

Comments
 (0)