Skip to content

Commit e6a16c8

Browse files
committed
Gate performance.measure usage on DEV and existence of the API
1 parent 2846f24 commit e6a16c8

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

packages/react-client/src/ReactFlightPerformanceTrack.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,12 @@ export function logComponentErrored(
104104
const isPrimaryEnv = env === rootEnv;
105105
const entryName =
106106
isPrimaryEnv || env === undefined ? name : name + ' [' + env + ']';
107-
if (__DEV__) {
107+
if (
108+
__DEV__ &&
109+
typeof performance !== 'undefined' &&
110+
// $FlowFixMe[method-unbinding]
111+
typeof performance.measure === 'function'
112+
) {
108113
const message =
109114
typeof error === 'object' &&
110115
error !== null &&

packages/react-reconciler/src/ReactFiberPerformanceTrack.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,12 @@ export function logComponentErrored(
151151
// Skip
152152
return;
153153
}
154-
if (__DEV__) {
154+
if (
155+
__DEV__ &&
156+
typeof performance !== 'undefined' &&
157+
// $FlowFixMe[method-unbinding]
158+
typeof performance.measure === 'function'
159+
) {
155160
const properties = [];
156161
for (let i = 0; i < errors.length; i++) {
157162
const capturedValue = errors[i];
@@ -206,7 +211,12 @@ function logComponentEffectErrored(
206211
// Skip
207212
return;
208213
}
209-
if (__DEV__) {
214+
if (
215+
__DEV__ &&
216+
typeof performance !== 'undefined' &&
217+
// $FlowFixMe[method-unbinding]
218+
typeof performance.measure === 'function'
219+
) {
210220
const properties = [];
211221
for (let i = 0; i < errors.length; i++) {
212222
const capturedValue = errors[i];
@@ -538,7 +548,12 @@ export function logRecoveredRenderPhase(
538548
hydrationFailed: boolean,
539549
): void {
540550
if (supportsUserTiming) {
541-
if (__DEV__) {
551+
if (
552+
__DEV__ &&
553+
typeof performance !== 'undefined' &&
554+
// $FlowFixMe[method-unbinding]
555+
typeof performance.measure === 'function'
556+
) {
542557
const properties = [];
543558
for (let i = 0; i < recoverableErrors.length; i++) {
544559
const capturedValue = recoverableErrors[i];
@@ -655,7 +670,12 @@ export function logCommitErrored(
655670
passive: boolean,
656671
): void {
657672
if (supportsUserTiming) {
658-
if (__DEV__) {
673+
if (
674+
__DEV__ &&
675+
typeof performance !== 'undefined' &&
676+
// $FlowFixMe[method-unbinding]
677+
typeof performance.measure === 'function'
678+
) {
659679
const properties = [];
660680
for (let i = 0; i < errors.length; i++) {
661681
const capturedValue = errors[i];

0 commit comments

Comments
 (0)