diff --git a/packages/react-test-renderer/src/ReactShallowRenderer.js b/packages/react-test-renderer/src/ReactShallowRenderer.js index 06e3f0f99c2dc..7472556c68954 100644 --- a/packages/react-test-renderer/src/ReactShallowRenderer.js +++ b/packages/react-test-renderer/src/ReactShallowRenderer.js @@ -384,7 +384,7 @@ class ReactShallowRenderer { 'an infinite loop.', ); - if (componentIdentity === this._previousComponentIdentity) { + if (componentIdentity === this._currentlyRenderingComponent) { // This is a render phase update. Stash it in a lazily-created map of // queue -> linked list of updates. After this render pass, we'll restart // and apply the stashed updates on top of the work-in-progress hook. @@ -408,13 +408,10 @@ class ReactShallowRenderer { } lastRenderPhaseUpdate.next = update; } - - if (!this._rendering) { - this.render(this._element, this._context); - } } else { // This means an update has happened after the function component has - // returned from a different component. + // returned. On the server this is a no-op. In React Fiber, the update + // would be scheduled for a future render. } } diff --git a/packages/react-test-renderer/src/__tests__/ReactShallowRendererHooks-test.js b/packages/react-test-renderer/src/__tests__/ReactShallowRendererHooks-test.js index 40327640e9617..da352a971e160 100644 --- a/packages/react-test-renderer/src/__tests__/ReactShallowRendererHooks-test.js +++ b/packages/react-test-renderer/src/__tests__/ReactShallowRendererHooks-test.js @@ -90,39 +90,6 @@ describe('ReactShallowRenderer with hooks', () => { ); }); - it('should work with updating a value from useState outside the render', () => { - function SomeComponent({defaultName}) { - const [name, updateName] = React.useState(defaultName); - - return ( -
updateName('Dan')}> -

- Your name is: {name} -

-
- ); - } - - const shallowRenderer = createRenderer(); - const element = ; - const result = shallowRenderer.render(element); - - expect(result.props.children).toEqual( -

- Your name is: Dominic -

, - ); - - result.props.onClick(); - const updated = shallowRenderer.render(element); - - expect(updated.props.children).toEqual( -

- Your name is: Dan -

, - ); - }); - it('should work with useReducer', () => { function reducer(state, action) { switch (action.type) {