From d8b9115549fdd8da6a4035b52c838e472ae59fe7 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Sun, 24 Feb 2019 07:56:48 -0800 Subject: [PATCH] Added missing nextHook() call to react-debug-tools useContext() impl --- .../react-debug-tools/src/ReactDebugHooks.js | 1 + .../ReactHooksInspectionIntegration-test.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/packages/react-debug-tools/src/ReactDebugHooks.js b/packages/react-debug-tools/src/ReactDebugHooks.js index 2dc1ddb02cac2..bec6bc2fe9bc4 100644 --- a/packages/react-debug-tools/src/ReactDebugHooks.js +++ b/packages/react-debug-tools/src/ReactDebugHooks.js @@ -93,6 +93,7 @@ function useContext( context: ReactContext, observedBits: void | number | boolean, ): T { + nextHook(); hookLog.push({ primitive: 'Context', stackError: new Error(), diff --git a/packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js b/packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js index 3c7972aff4df8..1088f1367c7b9 100644 --- a/packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js +++ b/packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js @@ -427,4 +427,20 @@ describe('ReactHooksInspectionIntegration', () => { expect(setterCalls[0]).not.toBe(initial); expect(setterCalls[1]).toBe(initial); }); + + // This test case is based on an open source bug report: + // facebookincubator/redux-react-hook/issues/34#issuecomment-466693787 + it('should properly advance the current hook for useContext', () => { + const MyContext = React.createContext(123); + + function Foo(props) { + React.useContext(MyContext); + const [data] = React.useState({foo: 'abc'}); + return
foo: {data.foo}
; + } + + const renderer = ReactTestRenderer.create(); + const childFiber = renderer.root._currentFiber(); + ReactDebugTools.inspectHooksOfFiber(childFiber); + }); });