Skip to content

Commit be1fd48

Browse files
authored
[DevTools] mock requestAnimationFrame with setTimeout as a temporary fix for #24626 (#24633)
* mock requestAnimationFrame as a temp workaround for #24626 * give name to constant variable
1 parent 0b54555 commit be1fd48

File tree

1 file changed

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

1 file changed

+17
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,23 @@ 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+
const FRAME_TIME = 16;
39+
let lastTime = 0;
40+
window.requestAnimationFrame = function(callback, element) {
41+
const now = window.performance.now();
42+
const nextTime = Math.max(lastTime + FRAME_TIME, now);
43+
return setTimeout(function() {
44+
callback((lastTime = nextTime));
45+
}, nextTime - now);
46+
};
47+
window.cancelAnimationFrame = clearTimeout;
48+
}
49+
3350
let panelCreated = false;
3451

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

0 commit comments

Comments
 (0)