Sitelet https://github.com/react/react/pull/9634
Skip to content

[Fiber] Fix to call deferred callbackQueue even if updates are aborted - #9634

Merged
acdlite merged 2 commits into
react:masterfrom
koba04:tests-for-set-state-callback
May 12, 2017
Merged

acdlite merged 2 commits into
react:masterfrom
koba04:tests-for-set-state-callback

Conversation

@koba04

@koba04 koba04 commented May 9, 2017

Copy link
Copy Markdown
Contributor

Currently, setState callback has never been called when the update is interrupted.
This PR is fixed it and added a test for reproducing it.

@koba04
koba04 force-pushed the tests-for-set-state-callback branch from 58e55c3 to 871540f Compare May 9, 2017 11:57
inst.setState({text: 'bar'}, () => callbackList.push('text'));

// Flush part of the work
ReactNoop.flushDeferredPri(20 + 5);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you add an assertion to make sure the update processed, but wasn't committed yet? Maybe by passing an updater function to setState instead of a plain object.

@acdlite acdlite left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks! The fix looks good. Fix the test and I'll merge.

@koba04

koba04 commented May 10, 2017

Copy link
Copy Markdown
Contributor Author

@acdlite Thanks! I've added an assertion for that.

@acdlite
acdlite merged commit 17ab69c into react:master May 12, 2017
@sebmarkbage

Copy link
Copy Markdown
Contributor

What happens if this gets aborted and begins many times?

This mutation of something that we received from the outside looks suspicious to me: https://github.com/facebook/react/pull/9634/files#diff-58ab36183b601ad6f7c27ed4c7d96278R468

It just to be ok because knew we always started with a fresh array but now we don't. Won't we just keep adding things to it?

@acdlite

acdlite commented May 13, 2017 •

Copy link
Copy Markdown
Collaborator

Won't we just keep adding things to it?

Hmm I don't think so. When we begin work on a queue, we advance the first update in the list. If we begin the queue again, we start at first. So the only time we process the same update twice is if we clone from current, and the callbackList is reset whenever we clone.

But I agree this is a bit confusing now. I've cleaned this up a bit in the branch I'm working on.

@koba04
koba04 deleted the tests-for-set-state-callback branch May 15, 2017 00:58
@koba04

koba04 commented May 15, 2017

Copy link
Copy Markdown
Contributor Author

Thanks!!

This mutation of something that we received from the outside looks suspicious to me

I'll add a test for this if necessary.

mrizwanashiq pushed a commit to mrizwanashiq/react that referenced this pull request Jun 25, 2026
react#9634)

* Fix to call deferred callbackQueue even if updates are aborted

* Add an assertion to make sure the update processed, but wasn't committed yet
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.

4 participants