-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Recoil state updates are out of sync with React component state #1076
Comments
I'm seeing the same issue in v0.2.0 |
Currently they are updated incrementally. However, a change is landing that also adds support for React's |
@drarmstr sounds great! Does this mean that React 18 will be needed to make use of this change? Any idea when this will land (days, weeks, months?) |
It's already landed in the nightly build, but to test it you'll have to enable the |
I can confirm after editing the bundle manually on the nightly build, it works! @drarmstr is there a way to set flags in |
You should be able to find where the gks variable is set in the built files and patch it there. Sorry we don't have a more sophisticated feature flag system for the open source build yet. |
Experiencing the same issue here! cant wait for the update :) |
Same as above, as we are heavily relying on this feature :) |
If you can't wait for the fix, you could patch-package 0.4.0 by enabling the feature flag and install react@next and react-dom@next which includes the requisite useMutableSource hook. I get a warning about not using the newer ReactDOM.createRoot API so it'll behave like React 17 which is fine by me as I'm not ready to opt into concurrent mode. |
Also see #759 |
Addressed in main branch for 0.6 release. |
Is this issue solved? I am still facing the similar issue here. |
I am trying to set the atom to the localStorage value but it seems like it requires a re-render which would potentially crash the application. Any solution to this, thanks! |
The above displays 32 when onClick handler is called. Tried to opt out of batching with React 18, but still fails getting the latest value. |
Fwiw, I switched to using |
Recoil version: 0.3.1
React version: 17.0.2
If a component has both Recoil state and React component state, and both are updated at once, a full render will occur (including effects and committing to the DOM) with the old Recoil state and the new React component state, before re-rendering with the new Recoil state.
This still occurs when:
ReactDOM.createRoot
)Example code
When clicking the button, you'll see the following being output:
Notice how on the second effect, local state and recoil state are different, despite being set to the same value on the same call.
I would expect the second effect to never occur - if component state and Recoil state are set simultaneously, they should be updated atomically.
Codesandbox demo: https://codesandbox.io/s/sharp-https-3ydwz?file=/src/TestComponent.js
The text was updated successfully, but these errors were encountered: