Skip to content

Commit d63e49f

Browse files
committed
fix[react-devtools/ReactDebugHooks]: support unstable prefixes in hooks and useContextWithBailout
1 parent 7771d3a commit d63e49f

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

packages/react-debug-tools/src/ReactDebugHooks.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import type {
2020
Dependencies,
2121
Fiber,
2222
Dispatcher as DispatcherType,
23+
ContextDependencyWithSelect,
2324
} from 'react-reconciler/src/ReactInternalTypes';
2425
import type {TransitionStatus} from 'react-reconciler/src/ReactFiberConfig';
2526

@@ -37,7 +38,6 @@ import {
3738
REACT_CONTEXT_TYPE,
3839
} from 'shared/ReactSymbols';
3940
import hasOwnProperty from 'shared/hasOwnProperty';
40-
import type {ContextDependencyWithSelect} from '../../react-reconciler/src/ReactInternalTypes';
4141

4242
type CurrentDispatcherRef = typeof ReactSharedInternals;
4343

@@ -76,7 +76,10 @@ function getPrimitiveStackCache(): Map<string, Array<any>> {
7676
try {
7777
// Use all hooks here to add them to the hook log.
7878
Dispatcher.useContext(({_currentValue: null}: any));
79-
Dispatcher.useState(null);
79+
Dispatcher.unstable_useContextWithBailout(
80+
({_currentValue: null}: any),
81+
null,
82+
);
8083
Dispatcher.useReducer((s: mixed, a: mixed) => s, null);
8184
Dispatcher.useRef(null);
8285
if (typeof Dispatcher.useCacheRefresh === 'function') {
@@ -280,6 +283,22 @@ function useContext<T>(context: ReactContext<T>): T {
280283
return value;
281284
}
282285

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+
283302
function useState<S>(
284303
initialState: (() => S) | S,
285304
): [S, Dispatch<BasicStateAction<S>>] {
@@ -753,6 +772,7 @@ const Dispatcher: DispatcherType = {
753772
useCacheRefresh,
754773
useCallback,
755774
useContext,
775+
unstable_useContextWithBailout,
756776
useEffect,
757777
useImperativeHandle,
758778
useDebugValue,
@@ -954,6 +974,11 @@ function parseHookName(functionName: void | string): string {
954974
} else {
955975
startIndex += 1;
956976
}
977+
978+
if (functionName.slice(startIndex).startsWith('unstable_')) {
979+
startIndex += 'unstable_'.length;
980+
}
981+
957982
if (functionName.slice(startIndex, startIndex + 3) === 'use') {
958983
if (functionName.length - startIndex === 3) {
959984
return 'Use';

0 commit comments

Comments
 (0)