@@ -20,6 +20,7 @@ import type {
20
20
Dependencies ,
21
21
Fiber ,
22
22
Dispatcher as DispatcherType ,
23
+ ContextDependencyWithSelect ,
23
24
} from 'react-reconciler/src/ReactInternalTypes' ;
24
25
import type { TransitionStatus } from 'react-reconciler/src/ReactFiberConfig' ;
25
26
@@ -37,7 +38,6 @@ import {
37
38
REACT_CONTEXT_TYPE ,
38
39
} from 'shared/ReactSymbols' ;
39
40
import hasOwnProperty from 'shared/hasOwnProperty' ;
40
- import type { ContextDependencyWithSelect } from '../../react-reconciler/src/ReactInternalTypes' ;
41
41
42
42
type CurrentDispatcherRef = typeof ReactSharedInternals ;
43
43
@@ -76,7 +76,10 @@ function getPrimitiveStackCache(): Map<string, Array<any>> {
76
76
try {
77
77
// Use all hooks here to add them to the hook log.
78
78
Dispatcher . useContext ( ( { _currentValue : null } : any ) ) ;
79
- Dispatcher . useState ( null ) ;
79
+ Dispatcher . unstable_useContextWithBailout (
80
+ ( { _currentValue : null } : any ) ,
81
+ null ,
82
+ ) ;
80
83
Dispatcher . useReducer ( ( s : mixed , a : mixed ) => s , null ) ;
81
84
Dispatcher . useRef ( null ) ;
82
85
if ( typeof Dispatcher . useCacheRefresh === 'function' ) {
@@ -280,6 +283,22 @@ function useContext<T>(context: ReactContext<T>): T {
280
283
return value ;
281
284
}
282
285
286
+ function unstable_useContextWithBailout< T > (
287
+ context: ReactContext< T > ,
288
+ select: (T => Array < mixed > ) | null,
289
+ ): T {
290
+ const value = readContext ( context ) ;
291
+ hookLog . push ( {
292
+ displayName : context . displayName || null ,
293
+ primitive : 'ContextWithBailout' ,
294
+ stackError : new Error ( ) ,
295
+ value : value ,
296
+ debugInfo : null ,
297
+ dispatcherHookName : 'ContextWithBailout' ,
298
+ } ) ;
299
+ return value ;
300
+ }
301
+
283
302
function useState< S > (
284
303
initialState: (() => S ) | S ,
285
304
) : [ S , Dispatch < BasicStateAction < S > > ] {
@@ -753,6 +772,7 @@ const Dispatcher: DispatcherType = {
753
772
useCacheRefresh ,
754
773
useCallback ,
755
774
useContext ,
775
+ unstable_useContextWithBailout ,
756
776
useEffect ,
757
777
useImperativeHandle ,
758
778
useDebugValue ,
@@ -954,6 +974,11 @@ function parseHookName(functionName: void | string): string {
954
974
} else {
955
975
startIndex += 1 ;
956
976
}
977
+
978
+ if ( functionName . slice ( startIndex ) . startsWith ( 'unstable_ ') ) {
979
+ startIndex += 'unstable_' . length ;
980
+ }
981
+
957
982
if ( functionName . slice ( startIndex , startIndex + 3 ) === 'use ') {
958
983
if ( functionName . length - startIndex === 3 ) {
959
984
return 'Use' ;
0 commit comments