-
Notifications
You must be signed in to change notification settings - Fork 58
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
Context value updates are done in a second render #69
Comments
This was not the case before 1.3.0: https://codesandbox.io/s/currying-resonance-73njnm Before 1.3.0 there were still two renders for subscribers, but the correct value was already available in the first render |
Yeah, it's a known limitation in v1.3. To my knowledge, there's no way to resolve this in userland without breaking things in concurrent rendering. |
Is it because of writing to refs at render time ? are you aware of any work in React to help make this safer ? |
It's because we use useLayoutEffect for propagation. |
Repro: https://codesandbox.io/s/fragrant-leaf-we1pvb?file=/src/App.js
Since the value ref is only updated in an effect, there are 2 renders that are required for a subscriber to get the correct updated value.
This can cause some very hard to debug issues, such as implementing an collapsibe or a popover where the
open
value is passed through context selector.The text was updated successfully, but these errors were encountered: