Skip to content

Commit fcb875d

Browse files
committed
mock requestAnimationFrame as a temp workaround for #24626
1 parent f534cc6 commit fcb875d

File tree

1 file changed

+16
-0
lines changed
  • packages/react-devtools-extensions/src

1 file changed

+16
-0
lines changed

packages/react-devtools-extensions/src/main.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ const LOCAL_STORAGE_SUPPORTS_PROFILING_KEY =
3030
const isChrome = getBrowserName() === 'Chrome';
3131
const isEdge = getBrowserName() === 'Edge';
3232

33+
// since Chromium v102, requestAnimationFrame no longer fires in devtools_page (i.e. this file)
34+
// mock requestAnimationFrame with setTimeout as a temporary workaround
35+
// https://github.com/facebook/react/issues/24626
36+
// The polyfill is based on https://gist.github.com/jalbam/5fe05443270fa6d8136238ec72accbc0
37+
if (isChrome || isEdge) {
38+
let lastTime = 0;
39+
window.requestAnimationFrame = function(callback, element) {
40+
const now = window.performance.now();
41+
const nextTime = Math.max(lastTime + 16, now);
42+
return setTimeout(function() {
43+
callback((lastTime = nextTime));
44+
}, nextTime - now);
45+
};
46+
window.cancelAnimationFrame = clearTimeout;
47+
}
48+
3349
let panelCreated = false;
3450

3551
// The renderer interface can't read saved component filters directly,

0 commit comments

Comments
 (0)