@@ -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,6 +76,13 @@ 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
+ if ( typeof Dispatcher . unstable_useContextWithBailout === 'function' ) {
80
+ // This type check is for Flow only.
81
+ Dispatcher . unstable_useContextWithBailout (
82
+ ( { _currentValue : null } : any ) ,
83
+ null ,
84
+ ) ;
85
+ }
79
86
Dispatcher . useState ( null ) ;
80
87
Dispatcher . useReducer ( ( s : mixed , a : mixed ) => s , null ) ;
81
88
Dispatcher . useRef ( null ) ;
@@ -280,6 +287,22 @@ function useContext<T>(context: ReactContext<T>): T {
280
287
return value ;
281
288
}
282
289
290
+ function unstable_useContextWithBailout< T > (
291
+ context: ReactContext< T > ,
292
+ select: (T => Array < mixed > ) | null,
293
+ ): T {
294
+ const value = readContext ( context ) ;
295
+ hookLog . push ( {
296
+ displayName : context . displayName || null ,
297
+ primitive : 'ContextWithBailout' ,
298
+ stackError : new Error ( ) ,
299
+ value : value ,
300
+ debugInfo : null ,
301
+ dispatcherHookName : 'ContextWithBailout' ,
302
+ } ) ;
303
+ return value ;
304
+ }
305
+
283
306
function useState< S > (
284
307
initialState: (() => S ) | S ,
285
308
) : [ S , Dispatch < BasicStateAction < S > > ] {
@@ -753,6 +776,7 @@ const Dispatcher: DispatcherType = {
753
776
useCacheRefresh ,
754
777
useCallback ,
755
778
useContext ,
779
+ unstable_useContextWithBailout ,
756
780
useEffect ,
757
781
useImperativeHandle ,
758
782
useDebugValue ,
@@ -954,6 +978,11 @@ function parseHookName(functionName: void | string): string {
954
978
} else {
955
979
startIndex += 1 ;
956
980
}
981
+
982
+ if ( functionName . slice ( startIndex ) . startsWith ( 'unstable_ ') ) {
983
+ startIndex += 'unstable_' . length ;
984
+ }
985
+
957
986
if ( functionName . slice ( startIndex , startIndex + 3 ) === 'use ') {
958
987
if ( functionName . length - startIndex === 3 ) {
959
988
return 'Use' ;
0 commit comments