Skip to content

Commit

Permalink
Put DEV-only code into DEV blocks (#14673)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon authored Jan 23, 2019
1 parent f0befae commit 9944392
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions packages/react-reconciler/src/ReactFiberHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type HookType =

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

let didWarnAboutMismatchedHooksForComponent;
if (__DEV__) {
Expand Down Expand Up @@ -216,7 +216,7 @@ function flushHookMismatchWarnings() {
// and a stack trace so the dev can locate where
// the first mismatch is coming from
if (__DEV__) {
if (currentHookMismatch !== null) {
if (currentHookMismatchInDev !== null) {
let componentName = getComponentName(
((currentlyRenderingFiber: any): Fiber).type,
);
Expand Down Expand Up @@ -280,10 +280,10 @@ function flushHookMismatchWarnings() {
hookStackHeader,
hookStackDiff.join('\n'),
hookStackFooter,
currentHookMismatch,
currentHookMismatchInDev,
);
}
currentHookMismatch = null;
currentHookMismatchInDev = null;
}
}
}
Expand Down Expand Up @@ -475,9 +475,9 @@ function cloneHook(hook: Hook): Hook {
};

if (__DEV__) {
if (!currentHookMismatch) {
if (currentHookMismatchInDev === null) {
if (currentHookNameInDev !== ((hook: any): HookDev)._debugType) {
currentHookMismatch = new Error('tracer').stack
currentHookMismatchInDev = new Error('tracer').stack
.split('\n')
.slice(4)
.join('\n');
Expand Down Expand Up @@ -582,7 +582,9 @@ export function useReducer<S, A>(
}
let fiber = (currentlyRenderingFiber = resolveCurrentlyRenderingFiber());
workInProgressHook = createWorkInProgressHook();
currentHookNameInDev = null;
if (__DEV__) {
currentHookNameInDev = null;
}
let queue: UpdateQueue<S, A> | null = (workInProgressHook.queue: any);
if (queue !== null) {
// Already have a queue, so this is an update.
Expand Down Expand Up @@ -771,7 +773,9 @@ export function useRef<T>(initialValue: T): {current: T} {
currentHookNameInDev = 'useRef';
}
workInProgressHook = createWorkInProgressHook();
currentHookNameInDev = null;
if (__DEV__) {
currentHookNameInDev = null;
}
let ref;

if (workInProgressHook.memoizedState === null) {
Expand Down Expand Up @@ -826,7 +830,9 @@ function useEffectImpl(fiberEffectTag, hookEffectTag, create, deps): void {
const prevDeps = prevEffect.deps;
if (areHookInputsEqual(nextDeps, prevDeps)) {
pushEffect(NoHookEffect, create, destroy, nextDeps);
currentHookNameInDev = null;
if (__DEV__) {
currentHookNameInDev = null;
}
return;
}
}
Expand All @@ -839,7 +845,9 @@ function useEffectImpl(fiberEffectTag, hookEffectTag, create, deps): void {
destroy,
nextDeps,
);
currentHookNameInDev = null;
if (__DEV__) {
currentHookNameInDev = null;
}
}

export function useImperativeHandle<T>(
Expand Down Expand Up @@ -927,7 +935,9 @@ export function useCallback<T>(
}
}
workInProgressHook.memoizedState = [callback, nextDeps];
currentHookNameInDev = null;
if (__DEV__) {
currentHookNameInDev = null;
}
return callback;
}

Expand All @@ -949,7 +959,9 @@ export function useMemo<T>(
if (nextDeps !== null) {
const prevDeps: Array<mixed> | null = prevState[1];
if (areHookInputsEqual(nextDeps, prevDeps)) {
currentHookNameInDev = null;
if (__DEV__) {
currentHookNameInDev = null;
}
return prevState[0];
}
}
Expand All @@ -962,7 +974,9 @@ export function useMemo<T>(
currentlyRenderingFiber = fiber;
unstashContextDependencies();
workInProgressHook.memoizedState = [nextValue, nextDeps];
currentHookNameInDev = null;
if (__DEV__) {
currentHookNameInDev = null;
}
return nextValue;
}

Expand Down

0 comments on commit 9944392

Please sign in to comment.