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