-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Fix serial passive effects #15650
Fix serial passive effects #15650
Conversation
Currently, we check for pending passive effects inside the `setState` method before we add additional updates to the queue, in case those pending effects also add things to the queue. However, the `setState` method is too late, because the event that caused the update might not have ever fired had the passive effects flushed before we got there. This is the same as the discrete/serial events problem. When a serial update comes in, and there's already a pending serial update, we have to do it before we call the user-provided event handlers. Because the event handlers themselves might change as a result of the pending update. This commit moves the `flushPassiveEffects` call to before the discrete event handlers are called, and removes it from the `setState` method. Non-discrete events will not cause passive effects to flush, which is fine, since by definition they are not order dependent.
@threepointone This is a duplicate of #15644 that I started last week but never opened a PR for. I don't care which one we merge as long as you incorporate the semantic changes and tests in this one. |
I think the only difference between our PRs is that I removed the |
ReactDOM: size: -0.1%, gzip: -0.2% Details of bundled changes.Comparing: af19e2e...cb56090 react-dom
react-art
react-native-renderer
Generated by 🚫 dangerJS |
If you need to treat setState as serial (eg from keyboard window event) how do you opt in? Are making interactiveUpdates a public API? Do we rename it? |
@gaearon In a real test I would simulate a click event. Since ReactNoop doesn't have an event system, I used |
I guess I’m asking what’s the upgrade path for people who wanted to rely on serial behavior and can’t anymore with this change. Shouldn’t that upgrade path be a part of the same release? |
We already lack a first class way to create custom serial event handlers (e.g. key events in #14750). You can get most of the way there with event delegation: attach a single native event listener and wrap all the handlers in You'd still need a way to force flush passive effects. We could expose Regardless, that problem exists independently of the problem fixed by this PR (where |
PR facebook#15650 is a bugfix but it's technically a semantic change that could cause regressions. I don't think it will be an issue, since the previous behavior was both broken and incoherent, but out of an abundance of caution, let's wrap it in a flag so we can easily revert it if necessary.
PR facebook#15650 is a bugfix but it's technically a semantic change that could cause regressions. I don't think it will be an issue, since the previous behavior was both broken and incoherent, but out of an abundance of caution, let's wrap it in a flag so we can easily revert it if necessary.
PR facebook#15650 is a bugfix but it's technically a semantic change that could cause regressions. I don't think it will be an issue, since the previous behavior was both broken and incoherent, but out of an abundance of caution, let's wrap it in a flag so we can easily revert it if necessary.
PR facebook#15650 is a bugfix but it's technically a semantic change that could cause regressions. I don't think it will be an issue, since the previous behavior was both broken and incoherent, but out of an abundance of caution, let's wrap it in a flag so we can easily revert it if necessary.
PR #15650 is a bugfix but it's technically a semantic change that could cause regressions. I don't think it will be an issue, since the previous behavior was both broken and incoherent, but out of an abundance of caution, let's wrap it in a flag so we can easily revert it if necessary.
The change in facebook#15650 has fully rolled out, so we can remove the flag that reverts it.
Flush passive effects before discrete events. Currently, we check for pending passive effects inside the
setState
method before we add additional updates to the queue, in case those pending effects also add things to the queue.However, the
setState
method is too late, because the event that caused the update might not have ever fired had the passive effects flushed before we got there.This is the same as the discrete/serial events problem. When a serial update comes in, and there's already a pending serial update, we have to do it before we call the user-provided event handlers. Because the event handlers themselves might change as a result of the pending update.
This commit moves the
flushPassiveEffects
call to before the discrete event handlers are called, and removes it from thesetState
method. Non-discrete events will not cause passive effects to flush, which is fine, since by definition they are not order dependent.