Skip to content

Commit 9944392

Browse files
authored
Put DEV-only code into DEV blocks (#14673)
1 parent f0befae commit 9944392

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

packages/react-reconciler/src/ReactFiberHooks.js

+27-13
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ type HookType =
7272

7373
// the first instance of a hook mismatch in a component,
7474
// represented by a portion of it's stacktrace
75-
let currentHookMismatch = null;
75+
let currentHookMismatchInDev = null;
7676

7777
let didWarnAboutMismatchedHooksForComponent;
7878
if (__DEV__) {
@@ -216,7 +216,7 @@ function flushHookMismatchWarnings() {
216216
// and a stack trace so the dev can locate where
217217
// the first mismatch is coming from
218218
if (__DEV__) {
219-
if (currentHookMismatch !== null) {
219+
if (currentHookMismatchInDev !== null) {
220220
let componentName = getComponentName(
221221
((currentlyRenderingFiber: any): Fiber).type,
222222
);
@@ -280,10 +280,10 @@ function flushHookMismatchWarnings() {
280280
hookStackHeader,
281281
hookStackDiff.join('\n'),
282282
hookStackFooter,
283-
currentHookMismatch,
283+
currentHookMismatchInDev,
284284
);
285285
}
286-
currentHookMismatch = null;
286+
currentHookMismatchInDev = null;
287287
}
288288
}
289289
}
@@ -475,9 +475,9 @@ function cloneHook(hook: Hook): Hook {
475475
};
476476

477477
if (__DEV__) {
478-
if (!currentHookMismatch) {
478+
if (currentHookMismatchInDev === null) {
479479
if (currentHookNameInDev !== ((hook: any): HookDev)._debugType) {
480-
currentHookMismatch = new Error('tracer').stack
480+
currentHookMismatchInDev = new Error('tracer').stack
481481
.split('\n')
482482
.slice(4)
483483
.join('\n');
@@ -582,7 +582,9 @@ export function useReducer<S, A>(
582582
}
583583
let fiber = (currentlyRenderingFiber = resolveCurrentlyRenderingFiber());
584584
workInProgressHook = createWorkInProgressHook();
585-
currentHookNameInDev = null;
585+
if (__DEV__) {
586+
currentHookNameInDev = null;
587+
}
586588
let queue: UpdateQueue<S, A> | null = (workInProgressHook.queue: any);
587589
if (queue !== null) {
588590
// Already have a queue, so this is an update.
@@ -771,7 +773,9 @@ export function useRef<T>(initialValue: T): {current: T} {
771773
currentHookNameInDev = 'useRef';
772774
}
773775
workInProgressHook = createWorkInProgressHook();
774-
currentHookNameInDev = null;
776+
if (__DEV__) {
777+
currentHookNameInDev = null;
778+
}
775779
let ref;
776780

777781
if (workInProgressHook.memoizedState === null) {
@@ -826,7 +830,9 @@ function useEffectImpl(fiberEffectTag, hookEffectTag, create, deps): void {
826830
const prevDeps = prevEffect.deps;
827831
if (areHookInputsEqual(nextDeps, prevDeps)) {
828832
pushEffect(NoHookEffect, create, destroy, nextDeps);
829-
currentHookNameInDev = null;
833+
if (__DEV__) {
834+
currentHookNameInDev = null;
835+
}
830836
return;
831837
}
832838
}
@@ -839,7 +845,9 @@ function useEffectImpl(fiberEffectTag, hookEffectTag, create, deps): void {
839845
destroy,
840846
nextDeps,
841847
);
842-
currentHookNameInDev = null;
848+
if (__DEV__) {
849+
currentHookNameInDev = null;
850+
}
843851
}
844852

845853
export function useImperativeHandle<T>(
@@ -927,7 +935,9 @@ export function useCallback<T>(
927935
}
928936
}
929937
workInProgressHook.memoizedState = [callback, nextDeps];
930-
currentHookNameInDev = null;
938+
if (__DEV__) {
939+
currentHookNameInDev = null;
940+
}
931941
return callback;
932942
}
933943

@@ -949,7 +959,9 @@ export function useMemo<T>(
949959
if (nextDeps !== null) {
950960
const prevDeps: Array<mixed> | null = prevState[1];
951961
if (areHookInputsEqual(nextDeps, prevDeps)) {
952-
currentHookNameInDev = null;
962+
if (__DEV__) {
963+
currentHookNameInDev = null;
964+
}
953965
return prevState[0];
954966
}
955967
}
@@ -962,7 +974,9 @@ export function useMemo<T>(
962974
currentlyRenderingFiber = fiber;
963975
unstashContextDependencies();
964976
workInProgressHook.memoizedState = [nextValue, nextDeps];
965-
currentHookNameInDev = null;
977+
if (__DEV__) {
978+
currentHookNameInDev = null;
979+
}
966980
return nextValue;
967981
}
968982

0 commit comments

Comments
 (0)