You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[CORRECT BEHAVIOR] Click on any of following buttons. You will notice in logs that new state is always visible to parent component and then in child component root -> (parent-reactive | parent-context) -> (child-reactive | child-context)
Update React Context(this uses react context and works fine)
Update React Context Async(this uses react context and works fine)
instead of updating context within handler this has setTimeout to simulate update outside of event handler
Update Reactive(this updates reactive variable within context of event handler and works fine)
[INCORRECT BEHAVIOR] Now click on Update Reactive Async
instead of updating context within handler this has setTimeout to simulate update outside of event handler
With this, child component see state change even before parent. State seem to transition like (child-reactive | child-context) -> (parent-reactive | parent-context) -> (child-reactive | child-context) -> root -> (parent-reactive | parent-context) -> (child-reactive | child-context)
I can confirm that if I wrap it with react dom unstable api for batching updates, it works as expected but I assume that it should have worked without it.
Hi @talha5389! Thanks for the reproduction. It would be helpful if you could also provide the exact steps to reproduce the issue in that reproduction. I can make some assumptions but having steps to follow will help us narrow down what might happening here.
Intended outcome:
Child should not see updated state change before parent similar to how React.useContext works
Actual outcome:
Child sees updated state before parent component and multiple renders are triggered even if only single reactive var is being changed.
How to reproduce the issue:
https://codesandbox.io/s/quirky-williamson-v5d0r?file=/src/App.js
root -> (parent-reactive | parent-context) -> (child-reactive | child-context)
Update React Context
(this uses react context and works fine)Update React Context Async
(this uses react context and works fine)Update Reactive
(this updates reactive variable within context of event handler and works fine)Update Reactive Async
(child-reactive | child-context) -> (parent-reactive | parent-context) -> (child-reactive | child-context) -> root -> (parent-reactive | parent-context) -> (child-reactive | child-context)
null
in updated state before parent does. Here is sandbox to reflect just such scenario https://codesandbox.io/s/naughty-almeida-mow3i?file=/src/App.jsVersions
The text was updated successfully, but these errors were encountered: