-
Notifications
You must be signed in to change notification settings - Fork 14
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
atomsWithQueryAsync
infinite loop
#53
Comments
Can @leweyse take a look? |
For me it seems like the problem lies in the jotai-tanstack-query/src/common.ts Lines 242 to 268 in 721b0b3
|
We just ran into the same problem here. A fix is highly appreciated, since this currently blocks us from going to production with our app. |
I also faced this issue a while ago! Thankfully someone brings up the topic now. |
I believe this issue is present in |
@Aslemammad Can you help? |
I thought I was going insane with this. In my use-case I was using atomsWithQueryAsync as a base atom then have another atom derives its state from the base atom for rendering. Couldn't figure out why it was looping, my initial thoughts was due to the fact that every get(baseAtom) call is triggering a rerun of the initial query and causing whatever is calling get(baseAtom) to rerun and loops. |
Seems the most of APIs are reimplemented in e6f6cb7 and the status atom seems to be gone, so this is not a problem from 0.8.0? |
I've taken a different approach in v0.8.0. atomsWithQueryAsync doesn't exist anymore. This is how I see that pattern: const idAtom = atom<Promise<string>>(async (get) => {
const response = await fetch('/id/from/some/where')
return response.json()
})
const userAtom = atomWithQuery((get) => {
const id = get(unwrap(idAtom)) // id is of type string | undefined
return {
queryKey: ['users', id],
queryFn: async ({ queryKey: [, id] }) => {
const res = await fetch(
`https://jsonplaceholder.typicode.com/users/${id}`
)
return res.json()
},
enabled: !!id, // queryFn will only fire when id is defined
}
}) This is how dependent queries work in tanstack/query. Ref: Dependent Queries |
I have this issue as well. :( |
This issue was resolved for me with 0.8.0, atomWithQueryAsync is removed now. Should probably update the version and migrate to the unwrap approach |
I discovered that there is an infinite loop, when the
queryFn
fromatomsWithQueryAsync
throws an error and I am subscribed to thestatus
-atom.I created a simple reproduction: https://codesandbox.io/p/sandbox/jotai-effect-infinite-loop-simple-forked-xgt3ck
The text was updated successfully, but these errors were encountered: