Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "[ShallowRenderer] Queue/rerender on dispatched action after render component with hooks" #14839

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions packages/react-test-renderer/src/ReactShallowRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div onClick={() => updateName('Dan')}>
<p>
Your name is: <span>{name}</span>
</p>
</div>
);
}

const shallowRenderer = createRenderer();
const element = <SomeComponent defaultName={'Dominic'} />;
const result = shallowRenderer.render(element);

expect(result.props.children).toEqual(
<p>
Your name is: <span>Dominic</span>
</p>,
);

result.props.onClick();
const updated = shallowRenderer.render(element);

expect(updated.props.children).toEqual(
<p>
Your name is: <span>Dan</span>
</p>,
);
});

it('should work with useReducer', () => {
function reducer(state, action) {
switch (action.type) {
Expand Down