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

State update bug in concurrent mode #14698

Merged
merged 2 commits into from
Jan 25, 2019

Conversation

bvaughn
Copy link
Contributor

@bvaughn bvaughn commented Jan 24, 2019

I think this PR captures a bug that was reported internally at Facebook. I believe this code should work for both sync and concurrent mode, but the update fails for concurrent mode.

@@ -1252,7 +1252,7 @@ function mountIndeterminateComponent(
) {
// Only double-render components with Hooks
if (workInProgress.memoizedState !== null) {
renderWithHooks(
value = renderWithHooks(
Copy link
Collaborator

@acdlite acdlite Jan 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do the same for the other occurrences of renderWithHooks

@bvaughn bvaughn force-pushed the concurrent-mode-state-update-bug branch from c2a69ce to 6ac4104 Compare January 24, 2019 23:58
@acdlite
Copy link
Collaborator

acdlite commented Jan 25, 2019

Explanation of why this fix works, for others who are interested:

When you call renderWithHooks during the initial render, React creates state queues for each of the State/Reducer Hooks. Those queues are bound to the dispatch method that is returned by the Hook, which is then closed over by event handlers, which in turn are included as part of the final children result that is returned by the component. These queues are also coupled to the internal list of Hook nodes that is stored on fiber.memoizedState.

The cause of bug was that, in dev, we were calling renderWithHooks a second time, but we weren't using the children that correspond to that call.

@acdlite acdlite merged commit f11a9c1 into facebook:master Jan 25, 2019
@bvaughn bvaughn deleted the concurrent-mode-state-update-bug branch January 25, 2019 00:38
n8schloss pushed a commit to n8schloss/react that referenced this pull request Jan 31, 2019
* State update bug in concurrent mode

* Fix bug introduced by double-rendering Functions using hooks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants