Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DevTools] mock requestAnimationFrame with setTimeout as a temporary fix for #24626 #24633

Merged
merged 2 commits into from
May 31, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/react-devtools-extensions/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ const LOCAL_STORAGE_SUPPORTS_PROFILING_KEY =
const isChrome = getBrowserName() === 'Chrome';
const isEdge = getBrowserName() === 'Edge';

// since Chromium v102, requestAnimationFrame no longer fires in devtools_page (i.e. this file)
// mock requestAnimationFrame with setTimeout as a temporary workaround
// https://github.com/facebook/react/issues/24626
// The polyfill is based on https://gist.github.com/jalbam/5fe05443270fa6d8136238ec72accbc0
if (isChrome || isEdge) {
let lastTime = 0;
window.requestAnimationFrame = function(callback, element) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we could detect the case where Chrome doesn't work correctly, and only apply the polyfill then?

const timeoutID = setTimeout(() => {
  // We probably need to polyfill now.
}, 1000);

requestAnimationFrame(() => {
  clearTimeout(timeoutID);
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea! I'll submit a PR with that improvement tomorrow

const now = window.performance.now();
const nextTime = Math.max(lastTime + 16, now);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Can you put 16 in a variable called FRAME_TIME or something like that so we know what it is in the future?

return setTimeout(function() {
callback((lastTime = nextTime));
}, nextTime - now);
};
window.cancelAnimationFrame = clearTimeout;
}

let panelCreated = false;

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