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

Context value updates are done in a second render #69

Closed
ling1726 opened this issue Feb 28, 2022 · 4 comments
Closed

Context value updates are done in a second render #69

ling1726 opened this issue Feb 28, 2022 · 4 comments

Comments

@ling1726
Copy link

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.

@ling1726
Copy link
Author

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

@dai-shi
Copy link
Owner

dai-shi commented Feb 28, 2022

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.

@ling1726
Copy link
Author

ling1726 commented Mar 1, 2022

Is it because of writing to refs at render time ? are you aware of any work in React to help make this safer ?

@dai-shi
Copy link
Owner

dai-shi commented Mar 1, 2022

It's because we use useLayoutEffect for propagation.
Some references:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants