-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
The query gets stuck at fetching
status when re-fetched data has cycles
#6954
Comments
I will prepare a PR since the fix seems quite straightforward: add a |
maybe we need to make it more obvious in the docs, but for if that's not the case, you can:
I think this is something you would do in a custom |
however, I think the query should go into |
@TkDodo yeah, I think it should, because it took me some time to figure out what was the issue with the query, since I didn't know my data wasn't JSON-serializable |
got stuck with this problem for a long time too, would be good to get error in this case |
okay, does someone want to contribute this ? I think a try/catch around here: query/packages/query-core/src/query.ts Line 499 in e3240f0
|
Anyone on this? I think I'm encountering the same issue. For me it gets stuck in "fetching", this happens consistently. |
I think you can feel free to work on it. Putting the query in error state won't fix the problem for you though. What you likely want is to set |
Hey there! 👋🏻 I’m experiencing a similar issue that might be related to this one. In my case, some queries remain in the CleanShot.2024-08-21.at.14.30.39.mp4After running a profiler on the code, I noticed that the Here is my query definition, which is relatively simple: export function useUserList(params?: UserListParams) {
const { filters = {} } = params ?? {};
const queryKey = userKeys.list(filters);
const queryClient = useQueryClient();
return useQuery({
queryKey,
queryFn: async () => {
const oldData = queryClient.getQueryData<Awaited<ReturnType<typeof fetchUserList>> | undefined>(queryKey);
const { data, version } = await fetchUserList({
...filters,
Version: oldData?.version ?? 0,
});
const mergedData = mergeData(oldData?.data, data);
return { data: mergedData, version };
},
});
} My fetcher function looks like this: export async function fetchUserList(filters: UserFilters) {
const request = GetUserList.clone();
// ...
const response = await http.send(request, { version: APIVersion.VIS2009 });
const data = UserListSchema.parse(response.data);
return {
data: indexOnce(data),
version: response.version,
};
} However, I don't see where I'm happy to provide more context or information if needed. Thanks for looking into this! |
After revisiting the documentation on Additionally, I couldn't find any references to |
I don't know if structuralSharing is relevant in vue (cc @DamianOsipiuk). @RomainLanz does your issue go away if you turn it off? One idea would be to turn it off per default in vue, but that seems like a breaking change |
Yes, it does. I will turn it off globally in my |
the PR that adds error management by @robin4a4 looks good but also a bit stale: if someone wants to continue it, please do. |
I didn't have anything breaking, so I will continue testing and push the change to production on Monday and report back again. Linking related discussion for reference: #1709 |
We pushed the change (defaulting to |
We still haven't found any issue. Should we consider removing |
Describe the bug
The query gets stuck at
fetching
status when you try to re-fetch data and it has cycles in it.Your minimal, reproducible example
https://codesandbox.io/p/sandbox/react-query-mfsz4x
Steps to reproduce
fetchStatus
gets stuck atfetching
Expected behavior
The query should change the
fetchStatus
toidle
when re-fetch has been finished.How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Tanstack Query adapter
react-query
TanStack Query version
v5.22.2
TypeScript version
No response
Additional context
As far as I understand, when you turn off
structuralSharing
for the query - the issue will go away.After some digging, I found that default
structuralSharing
functionality is to callreplaceEqualDeep
function. And when there are cycles in the data, this function goes into infinite loop because it recursively calls itself on each data property.The text was updated successfully, but these errors were encountered: