@samitouri / QOS-React-2 / commits / 9944392285

Put DEV-only code into DEV blocks (#14673)

Dan Abramov committed Jan 23, 2019 at 16:59 UTC 99443922856f74b521cb3a90360a6a5a3a695694
1 file changed +27 -13
packages/react-reconciler/src/ReactFiberHooks.js
+27 -13
@@ -72,7 +72,7 @@ type HookType =
72
73 // the first instance of a hook mismatch in a component,
74 // represented by a portion of it's stacktrace
75 -let currentHookMismatch = null;
75 +let currentHookMismatchInDev = null;
76
77 let didWarnAboutMismatchedHooksForComponent;
78 if (__DEV__) {
@@ -216,7 +216,7 @@ function flushHookMismatchWarnings() {
216 // and a stack trace so the dev can locate where
217 // the first mismatch is coming from
218 if (__DEV__) {
219 - if (currentHookMismatch !== null) {
219 + if (currentHookMismatchInDev !== null) {
220 let componentName = getComponentName(
221 ((currentlyRenderingFiber: any): Fiber).type,
222 );
@@ -280,10 +280,10 @@ function flushHookMismatchWarnings() {
280 hookStackHeader,
281 hookStackDiff.join('\n'),
282 hookStackFooter,
283 - currentHookMismatch,
283 + currentHookMismatchInDev,
284 );
285 }
286 - currentHookMismatch = null;
286 + currentHookMismatchInDev = null;
287 }
288 }
289 }
@@ -475,9 +475,9 @@ function cloneHook(hook: Hook): Hook {
475 };
476
477 if (__DEV__) {
478 - if (!currentHookMismatch) {
478 + if (currentHookMismatchInDev === null) {
479 if (currentHookNameInDev !== ((hook: any): HookDev)._debugType) {
480 - currentHookMismatch = new Error('tracer').stack
480 + currentHookMismatchInDev = new Error('tracer').stack
481 .split('\n')
482 .slice(4)
483 .join('\n');
@@ -582,7 +582,9 @@ export function useReducer<S, A>(
582 }
583 let fiber = (currentlyRenderingFiber = resolveCurrentlyRenderingFiber());
584 workInProgressHook = createWorkInProgressHook();
585 - currentHookNameInDev = null;
585 + if (__DEV__) {
586 + currentHookNameInDev = null;
587 + }
588 let queue: UpdateQueue<S, A> | null = (workInProgressHook.queue: any);
589 if (queue !== null) {
590 // Already have a queue, so this is an update.
@@ -771,7 +773,9 @@ export function useRef<T>(initialValue: T): {current: T} {
773 currentHookNameInDev = 'useRef';
774 }
775 workInProgressHook = createWorkInProgressHook();
774 - currentHookNameInDev = null;
776 + if (__DEV__) {
777 + currentHookNameInDev = null;
778 + }
779 let ref;
780
781 if (workInProgressHook.memoizedState === null) {
@@ -826,7 +830,9 @@ function useEffectImpl(fiberEffectTag, hookEffectTag, create, deps): void {
830 const prevDeps = prevEffect.deps;
831 if (areHookInputsEqual(nextDeps, prevDeps)) {
832 pushEffect(NoHookEffect, create, destroy, nextDeps);
829 - currentHookNameInDev = null;
833 + if (__DEV__) {
834 + currentHookNameInDev = null;
835 + }
836 return;
837 }
838 }
@@ -839,7 +845,9 @@ function useEffectImpl(fiberEffectTag, hookEffectTag, create, deps): void {
845 destroy,
846 nextDeps,
847 );
842 - currentHookNameInDev = null;
848 + if (__DEV__) {
849 + currentHookNameInDev = null;
850 + }
851 }
852
853 export function useImperativeHandle<T>(
@@ -927,7 +935,9 @@ export function useCallback<T>(
935 }
936 }
937 workInProgressHook.memoizedState = [callback, nextDeps];
930 - currentHookNameInDev = null;
938 + if (__DEV__) {
939 + currentHookNameInDev = null;
940 + }
941 return callback;
942 }
943
@@ -949,7 +959,9 @@ export function useMemo<T>(
959 if (nextDeps !== null) {
960 const prevDeps: Array<mixed> | null = prevState[1];
961 if (areHookInputsEqual(nextDeps, prevDeps)) {
952 - currentHookNameInDev = null;
962 + if (__DEV__) {
963 + currentHookNameInDev = null;
964 + }
965 return prevState[0];
966 }
967 }
@@ -962,7 +974,9 @@ export function useMemo<T>(
974 currentlyRenderingFiber = fiber;
975 unstashContextDependencies();
976 workInProgressHook.memoizedState = [nextValue, nextDeps];
965 - currentHookNameInDev = null;
977 + if (__DEV__) {
978 + currentHookNameInDev = null;
979 + }
980 return nextValue;
981 }
982