question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with state change timing? (preact + react-query)

See original GitHub issue

I have a pretty interesting issue that I stumbled upon when trying to swap recoil with jotai. 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 using preact, react-query, and jotai, but works fine with recoil.

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 of react and recoil instead of jotai: https://codesandbox.io/s/preact-react-query-recoil-sd8pu

And here is the reproduction of the bug which happens only with preact, react-query, and jotai: 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 a mutation 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 with recoil and does not with jotai?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
dai-shicommented, Jun 7, 2022

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.

0reactions
dai-shicommented, Mar 31, 2022

Let’s keep this open for some more time, but it’s likely we close this eventually unless someone works on it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PReact useEffect doesn't trigger on state change
I want to do a recursive function which basically runs each time a folder has a subfolder under it, so I ...
Read more >
React Query as a State Manager | TkDodo's blog
React Query is an async state manager. It can manage any form of asynchronous state - it is happy as long as it...
Read more >
React Query, Solid Query, Svelte Query, Vue Query - TanStack
Powerful asynchronous state management for TS/JS, React, Solid, Vue and Svelte ... Tell TanStack Query where to get your data and how fresh...
Read more >
You Probably Don't Need Derived State – React Blog
For a long time, the lifecycle componentWillReceiveProps was the only way to update state in response to a change in props without an ......
Read more >
React 18 - New Toys, New Footguns, & New Possibilities.
React 18 (18.2.0, at the time of writing), though, takes giant steps towards ... one very blatant UI issue: if you suspend during...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found