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