Skip to content

Commit 50781c2

Browse files
committed
Gate performance.measure usage on DEV and existence of the API
1 parent 73346e7 commit 50781c2

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

packages/react-client/src/ReactFlightPerformanceTrack.js

+6-1
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

+24-4
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,12 @@ export function logComponentErrored(
201201
// Skip
202202
return;
203203
}
204-
if (__DEV__) {
204+
if (
205+
__DEV__ &&
206+
typeof performance !== 'undefined' &&
207+
// $FlowFixMe[method-unbinding]
208+
typeof performance.measure === 'function'
209+
) {
205210
const properties = [];
206211
for (let i = 0; i < errors.length; i++) {
207212
const capturedValue = errors[i];
@@ -256,7 +261,12 @@ function logComponentEffectErrored(
256261
// Skip
257262
return;
258263
}
259-
if (__DEV__) {
264+
if (
265+
__DEV__ &&
266+
typeof performance !== 'undefined' &&
267+
// $FlowFixMe[method-unbinding]
268+
typeof performance.measure === 'function'
269+
) {
260270
const properties = [];
261271
for (let i = 0; i < errors.length; i++) {
262272
const capturedValue = errors[i];
@@ -596,7 +606,12 @@ export function logRecoveredRenderPhase(
596606
hydrationFailed: boolean,
597607
): void {
598608
if (supportsUserTiming) {
599-
if (__DEV__) {
609+
if (
610+
__DEV__ &&
611+
typeof performance !== 'undefined' &&
612+
// $FlowFixMe[method-unbinding]
613+
typeof performance.measure === 'function'
614+
) {
600615
const properties = [];
601616
for (let i = 0; i < recoverableErrors.length; i++) {
602617
const capturedValue = recoverableErrors[i];
@@ -715,7 +730,12 @@ export function logCommitErrored(
715730
passive: boolean,
716731
): void {
717732
if (supportsUserTiming) {
718-
if (__DEV__) {
733+
if (
734+
__DEV__ &&
735+
typeof performance !== 'undefined' &&
736+
// $FlowFixMe[method-unbinding]
737+
typeof performance.measure === 'function'
738+
) {
719739
const properties = [];
720740
for (let i = 0; i < errors.length; i++) {
721741
const capturedValue = errors[i];

0 commit comments

Comments
 (0)