Skip to content

Commit f3678bc

Browse files
author
Brian Vaughn
committed
Added redundant feature flag guards to exported functions to make sure they don't leak into builds
1 parent c3a2c4b commit f3678bc

File tree

1 file changed

+109
-63
lines changed

1 file changed

+109
-63
lines changed

packages/react-reconciler/src/DebugTracing.js

Lines changed: 109 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
import type {Wakeable} from 'shared/ReactTypes';
1111

12+
import {enableDebugTracing} from 'shared/ReactFeatureFlags';
13+
1214
const nativeConsole: Object = console;
1315
let nativeConsoleLog: null | Function = null;
1416

@@ -56,16 +58,24 @@ const REACT_LOGO_STYLE =
5658
'background-color: #20232a; color: #61dafb; padding: 0 2px;';
5759

5860
export function logCommitStarted(priorityLabel: string): void {
59-
group(
60-
`%c⚛️%c commit%c (priority: ${priorityLabel})`,
61-
REACT_LOGO_STYLE,
62-
'',
63-
'font-weight: normal;',
64-
);
61+
if (__DEV__) {
62+
if (enableDebugTracing) {
63+
group(
64+
`%c⚛️%c commit%c (priority: ${priorityLabel})`,
65+
REACT_LOGO_STYLE,
66+
'',
67+
'font-weight: normal;',
68+
);
69+
}
70+
}
6571
}
6672

6773
export function logCommitStopped(): void {
68-
groupEnd();
74+
if (__DEV__) {
75+
if (enableDebugTracing) {
76+
groupEnd();
77+
}
78+
}
6979
}
7080

7181
const PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map;
@@ -83,98 +93,134 @@ export function logComponentSuspended(
8393
componentName: string,
8494
wakeable: Wakeable,
8595
): void {
86-
const id = getWakeableID(wakeable);
87-
const display = (wakeable: any).displayName || wakeable;
88-
log(
89-
`%c⚛️%c ${componentName} suspended`,
90-
REACT_LOGO_STYLE,
91-
'color: #80366d; font-weight: bold;',
92-
id,
93-
display,
94-
);
95-
wakeable.then(
96-
() => {
96+
if (__DEV__) {
97+
if (enableDebugTracing) {
98+
const id = getWakeableID(wakeable);
99+
const display = (wakeable: any).displayName || wakeable;
97100
log(
98-
`%c⚛️%c ${componentName} resolved`,
101+
`%c⚛️%c ${componentName} suspended`,
99102
REACT_LOGO_STYLE,
100103
'color: #80366d; font-weight: bold;',
101104
id,
102105
display,
103106
);
104-
},
105-
() => {
106-
log(
107-
`%c⚛️%c ${componentName} rejected`,
108-
REACT_LOGO_STYLE,
109-
'color: #80366d; font-weight: bold;',
110-
id,
111-
display,
107+
wakeable.then(
108+
() => {
109+
log(
110+
`%c⚛️%c ${componentName} resolved`,
111+
REACT_LOGO_STYLE,
112+
'color: #80366d; font-weight: bold;',
113+
id,
114+
display,
115+
);
116+
},
117+
() => {
118+
log(
119+
`%c⚛️%c ${componentName} rejected`,
120+
REACT_LOGO_STYLE,
121+
'color: #80366d; font-weight: bold;',
122+
id,
123+
display,
124+
);
125+
},
112126
);
113-
},
114-
);
127+
}
128+
}
115129
}
116130

117131
export function logLayoutEffectsStarted(priorityLabel: string): void {
118-
group(
119-
`%c⚛️%c layout effects%c (priority: ${priorityLabel})`,
120-
REACT_LOGO_STYLE,
121-
'',
122-
'font-weight: normal;',
123-
);
132+
if (__DEV__) {
133+
if (enableDebugTracing) {
134+
group(
135+
`%c⚛️%c layout effects%c (priority: ${priorityLabel})`,
136+
REACT_LOGO_STYLE,
137+
'',
138+
'font-weight: normal;',
139+
);
140+
}
141+
}
124142
}
125143

126144
export function logLayoutEffectsStopped(): void {
127-
groupEnd();
145+
if (__DEV__) {
146+
if (enableDebugTracing) {
147+
groupEnd();
148+
}
149+
}
128150
}
129151

130152
export function logPassiveEffectsStarted(priorityLabel: string): void {
131-
group(
132-
`%c⚛️%c passive effects%c (priority: ${priorityLabel})`,
133-
REACT_LOGO_STYLE,
134-
'',
135-
'font-weight: normal;',
136-
);
153+
if (__DEV__) {
154+
if (enableDebugTracing) {
155+
group(
156+
`%c⚛️%c passive effects%c (priority: ${priorityLabel})`,
157+
REACT_LOGO_STYLE,
158+
'',
159+
'font-weight: normal;',
160+
);
161+
}
162+
}
137163
}
138164

139165
export function logPassiveEffectsStopped(): void {
140-
groupEnd();
166+
if (__DEV__) {
167+
if (enableDebugTracing) {
168+
groupEnd();
169+
}
170+
}
141171
}
142172

143173
export function logRenderStarted(priorityLabel: string): void {
144-
group(
145-
`%c⚛️%c render%c (priority: ${priorityLabel})`,
146-
REACT_LOGO_STYLE,
147-
'',
148-
'font-weight: normal;',
149-
);
174+
if (__DEV__) {
175+
if (enableDebugTracing) {
176+
group(
177+
`%c⚛️%c render%c (priority: ${priorityLabel})`,
178+
REACT_LOGO_STYLE,
179+
'',
180+
'font-weight: normal;',
181+
);
182+
}
183+
}
150184
}
151185

152186
export function logRenderStopped(): void {
153-
groupEnd();
187+
if (__DEV__) {
188+
if (enableDebugTracing) {
189+
groupEnd();
190+
}
191+
}
154192
}
155193

156194
export function logForceUpdateScheduled(
157195
componentName: string,
158196
priorityLabel: string,
159197
): void {
160-
log(
161-
`%c⚛️%c ${componentName} forced update %c(priority: ${priorityLabel})`,
162-
REACT_LOGO_STYLE,
163-
'color: #db2e1f; font-weight: bold;',
164-
'',
165-
);
198+
if (__DEV__) {
199+
if (enableDebugTracing) {
200+
log(
201+
`%c⚛️%c ${componentName} forced update %c(priority: ${priorityLabel})`,
202+
REACT_LOGO_STYLE,
203+
'color: #db2e1f; font-weight: bold;',
204+
'',
205+
);
206+
}
207+
}
166208
}
167209

168210
export function logStateUpdateScheduled(
169211
componentName: string,
170212
priorityLabel: string,
171213
payloadOrAction: any,
172214
): void {
173-
log(
174-
`%c⚛️%c ${componentName} updated state %c(priority: ${priorityLabel})`,
175-
REACT_LOGO_STYLE,
176-
'color: #01a252; font-weight: bold;',
177-
'',
178-
payloadOrAction,
179-
);
215+
if (__DEV__) {
216+
if (enableDebugTracing) {
217+
log(
218+
`%c⚛️%c ${componentName} updated state %c(priority: ${priorityLabel})`,
219+
REACT_LOGO_STYLE,
220+
'color: #01a252; font-weight: bold;',
221+
'',
222+
payloadOrAction,
223+
);
224+
}
225+
}
180226
}

0 commit comments

Comments
 (0)