Skip to content

Commit 04d1da2

Browse files
committed
fix: check cross-origin isolation for SharedArrayBuffer
1 parent e2fd460 commit 04d1da2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/scheduler/src/SchedulerProfiling.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ import {NoPriority} from './SchedulerPriorities';
1515
let runIdCounter: number = 0;
1616
let mainThreadIdCounter: number = 0;
1717

18+
// We only use SharedArrayBuffer when cross origin isolation is enabled.
19+
// $FlowFixMe Flow doesn't know about SharedArrayBuffer
20+
const isEnabledSharedArrayBuffer = typeof SharedArrayBuffer === 'function' && typeof window !== 'undefined' && window.crossOriginIsolated === true
21+
1822
const profilingStateSize = 4;
1923
export const sharedProfilingBuffer = enableProfiling
20-
? // $FlowFixMe Flow doesn't know about SharedArrayBuffer
21-
typeof SharedArrayBuffer === 'function'
24+
?
25+
isEnabledSharedArrayBuffer
2226
? new SharedArrayBuffer(profilingStateSize * Int32Array.BYTES_PER_ELEMENT)
2327
: // $FlowFixMe Flow doesn't know about ArrayBuffer
2428
typeof ArrayBuffer === 'function'

0 commit comments

Comments
 (0)