Skip to content

Commit 8aec60d

Browse files
committed
enable contextTypes on FunctionComponent only
1 parent bede31a commit 8aec60d

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,11 @@ export function inspectHooks<Props>(
621621
let ancestorStackError;
622622
try {
623623
ancestorStackError = new Error();
624-
renderFunction(props, legacyContext);
624+
if (legacyContext && legacyContext !== null) {
625+
renderFunction(props, legacyContext);
626+
} else {
627+
renderFunction(props);
628+
}
625629
} finally {
626630
readHookLog = hookLog;
627631
hookLog = [];
@@ -745,16 +749,25 @@ export function inspectHooksOfFiber(
745749
currentHook = (fiber.memoizedState: Hook);
746750
const contextMap = new Map();
747751
try {
748-
const legacyContext = setupContexts(contextMap, fiber, enableLegacyContext);
749-
if (fiber.tag === ForwardRef) {
752+
if (fiber.tag === FunctionComponent) {
753+
const legacyContext = setupContexts(
754+
contextMap,
755+
fiber,
756+
enableLegacyContext,
757+
);
758+
return inspectHooks(type, props, currentDispatcher, legacyContext);
759+
} else if (fiber.tag === ForwardRef) {
760+
setupContexts(contextMap, fiber);
750761
return inspectHooksOfForwardRef(
751762
type.render,
752763
props,
753764
fiber.ref,
754765
currentDispatcher,
755766
);
767+
} else {
768+
setupContexts(contextMap, fiber);
769+
return inspectHooks(type, props, currentDispatcher);
756770
}
757-
return inspectHooks(type, props, currentDispatcher, legacyContext);
758771
} finally {
759772
currentHook = null;
760773
restoreContexts(contextMap);

0 commit comments

Comments
 (0)