-
-
Notifications
You must be signed in to change notification settings - Fork 617
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
Issue with state change timing? (preact + react-query) #570
Comments
Hello @visualfanatic! |
@Aslemammad My question is if the issue is only about preact + async stuff. |
I fixed it by scheduling the set function in the macro task(task) phase. codesandbox export const pageState = atom(1, (get, set, update) => {
setTimeout(() => set(pageState, update(get(pageState))));
}); What's your opinion now? Edit: It didn't work when I scheduled it into the microtask phase (Promise.resolve); maybe there's a problem in Preact scheduling? |
Wow, you rock. Yeah, probably preact uses microtask for batching.
This issue is about preact + async stuff, but not preact + async atoms. |
Please try again with recoil 0.4 when it's out. |
https://codesandbox.io/s/preact-react-query-recoil-forked-88klx works fine with recoil 0.4 |
Hmm, thought turning off batching helps, but not. @Aslemammad Do you think we can reproduce the issue without react-query? |
@Aslemammad Althought this is marked btw, recoil is v0.5 now. |
v1.5.0 doesn't change the behavior. This is probably because jotai uses the subtle behavior of |
Let's keep this open for some more time, but it's likely we close this eventually unless someone works on it. |
With latest versions, it behaves still the same: https://codesandbox.io/s/preact-react-query-jotai-forked-u36uoe However, recoil one also behaves the same with latest versions: https://codesandbox.io/s/preact-react-query-recoil-forked-klowl7 So, I'd assume the issue is not on our end, but on preact(-compat). Closing. |
I have a pretty interesting issue that I stumbled upon when trying to swap
recoil
withjotai
. I am still not sure if I am posting this to the right repo as this bug might be in something else. It happens for me when usingpreact
,react-query
, andjotai
, but works fine withrecoil
.I prepared a simple reproduction of this bug, but first here is how it should behave:
https://codesandbox.io/s/react-react-query-jotai-fwhj3 (
react
+react-query
+jotai
)You should be able to go through three steps and then back to the beginning. There is an async function executed before going from one step to another that in the reproduction is just a
Promise
that resolves after 1 second.Here is a similar app that uses
preact
instead ofreact
andrecoil
instead ofjotai
:https://codesandbox.io/s/preact-react-query-recoil-sd8pu
And here is the reproduction of the bug which happens only with
preact
,react-query
, andjotai
:https://codesandbox.io/s/preact-react-query-jotai-5nsfu
As you can hopefully see, after the async function resolves and the second step is shown, the button in the second step is disabled as the
useIsMutating
function still thinks that there is amutation
running.It looks like the second step's logic is run after the
setPage
triggers the change of the currently displayed step, and after that is done the component is displayed with the old data.This might be an issue in
preact
, but why does it work withrecoil
and does not withjotai
?The text was updated successfully, but these errors were encountered: