-
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
use-subscription causes UI tearing in some random cases #16396
Comments
cc @bvaughn |
This is an interesting case. For me, the first mutation pair (that doesn't tear) proceeds like so:
For the second mutation pair (the one that tears) the sequence is different in an important way:
I could "fix" the tearing in this case by reading the value in the outer change handler (outside of the state updater function, rather than inside of it) and I probably should make this change anyway. I'd like to better understand why this is happening first though. I'm not sure yet why the different behavior occurs. It looks like React doesn't eagerly compute the state in the second case because The good news is that I can catch this in a test. I had trouble at first, until I realized that the first interruption didn't cause the tear - but the second one did. (Test also requires two.) |
cc @milankinen @dai-shi Have you retried the latest version of |
I tried with v1.1.0 and confirmed that tearing is fixed. Still check4 is failing. It might be rare edge cases. |
Hm. I don't have time to look now (preparing for a conf talk) but what you're describing sounds unexpected. If a parent renders, but it's children don't- React shouldn't commit anything to the DOM (until the children render). Can you point me at that specific test case? (As a reminder for when the conf talk is done?) |
This comment has been minimized.
This comment has been minimized.
@tsolman You subscribed yourself to this issue. You can unsubscribe from it by clicking the "Unsubscribe" button. No one can do that for you. |
Seems to fix my issue. Thank you! 👍 |
@bvaughn (I enjoyed the video of your talk at react conf 2019!) Here's some pointers: I'm not sure if you can get the intention behind it (it's simple though.) |
Reducing the repro to a single failing case would probably be helpful, if it wouldn't be too much trouble :) |
@bvaughn Here's the sandbox. https://codesandbox.io/s/nice-tharp-6f6es Strangely, I see tearing with it. (because it's DEV??) Clicking "force update" while counting up tears and stops counting. |
This is no longer happening. Not sure, but react@experimental is updated?
This is still happening. |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Referring to this twitter conversation, it seems that
use-subscription
can cause "UI tearing" in some random cases due to a (possible) race condition w.r.t. the combination ofsubscribe
andgetCurrentValue
in internal usage.Here is a minimalistic application demonstrating the behaviour: https://github.com/milankinen/use-subscription-tearing-demo
What is the expected behavior?
I'd expect counters in the example application to always render same number.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
Tested React version: 16.9.0 (haven't tested with older ones)
OS: OSX 10.14.6
Hardware: MacBook Pro (Retina, 15-inch, Mid 2015) 2.8 GHz Intel Core i7 & 16GB RAM
Browser: Chrome Version 76.0.3809.100 (Official Build) (64-bit)
@bvaughn
The text was updated successfully, but these errors were encountered: