Description
React version: v17.0.1
Steps To Reproduce
npx create-react-app myapp
cd myapp && npm start
- Open http://localhost:3000 in Chrome 88 or 89, regular or Incognito mode
- Open DevTools: the warning is displayed
Link to code example: https://react-z95km1.stackblitz.io/
https://stackblitz.com/edit/react-z95km1
The current behavior
Warning: scheduler.development.js:298 [Deprecation] SharedArrayBuffer will require cross-origin isolation as of M91, around May 2021. See https://developer.chrome.com/blog/enabling-shared-array-buffer/ for more details.
The expected behavior
No warning will be shown.
As the warning shows, Chrome will require cross-origin isolation starting version 91 in order to use SharedArrayBuffer. To enable cross-origin isolation, the page needs to be loaded with COOP and COEP headers which I believe is out of React's control. You can learn more about this at https://developer.chrome.com/blog/enabling-shared-array-buffer/.
As it's confusing for React users to see this warning every time they open the page, I'd propose two things:
- Suppress the message by using SAB only when cross-origin isolation is enabled. You can check it by
self.crossOriginIsolated
boolean flag. - Document that the page needs to send COOP and COEP headers to profile performance using SharedArrayBuffer. You can find an actionable guide here: https://web.dev/cross-origin-isolation-guide/
The problematic code is here: https://github.com/facebook/react/blob/master/packages/scheduler/src/SchedulerProfiling.js#L21-L22
FWIW, with cross-origin isolation, you'll be able to use JS Self-Profiling API too.
cc: @acomminos @maudnals