GeezerVison is showing github.com — fix: use SharedArrayBuffer only when cross-origin isolation is enable… · react/react@8fa0ccc
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: packages/scheduler/src/SchedulerProfiling.js +9-4Lines changed: 9 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -15,13 +15,18 @@ import {NoPriority} from './SchedulerPriorities'; |
15 | 15 | let runIdCounter: number = 0; |
16 | 16 | let mainThreadIdCounter: number = 0; |
17 | 17 |
|
| 18 | +const isEnabledSharedArrayBuffer = |
| 19 | + // $FlowFixMe Flow doesn't know about SharedArrayBuffer |
| 20 | + typeof SharedArrayBuffer === 'function' && |
| 21 | + // We only use SharedArrayBuffer when cross origin isolation is enabled. |
| 22 | + typeof window !== 'undefined' && |
| 23 | + window.crossOriginIsolated === true; |
| 24 | + |
18 | 25 | const profilingStateSize = 4; |
19 | 26 | export const sharedProfilingBuffer = enableProfiling |
20 | | - ? // $FlowFixMe Flow doesn't know about SharedArrayBuffer |
21 | | - typeof SharedArrayBuffer === 'function' |
| 27 | + ? isEnabledSharedArrayBuffer |
22 | 28 | ? new SharedArrayBuffer(profilingStateSize * Int32Array.BYTES_PER_ELEMENT) |
23 | | - : // $FlowFixMe Flow doesn't know about ArrayBuffer |
24 | | - typeof ArrayBuffer === 'function' |
| 29 | + : typeof ArrayBuffer === 'function' |
25 | 30 | ? new ArrayBuffer(profilingStateSize * Int32Array.BYTES_PER_ELEMENT) |
26 | 31 | : null // Don't crash the init path on IE9 |
27 | 32 | : null; |
|