Skip to content
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

getQueryData suddenly returns undefined for a query even though no update to query data has occurred #7110

Closed
LukasDeco opened this issue Mar 14, 2024 · 8 comments

Comments

@LukasDeco
Copy link

LukasDeco commented Mar 14, 2024

Describe the bug

In a React component, calling queryClient.getQueryData for a specific query is suddenly returning undefined after previously returning data during subsequent renders, despite no new calls to queryClient.setQueryData for that query. This behavior is observed even when console logging confirms that setQueryData has not been invoked for the affected query, so there is no clear reason why it would turn undefined suddenly.

Your minimal, reproducible example

https://codesandbox.io/p/sandbox/react-query-bug-qw336y?file=%2Fsrc%2FApp.js

Steps to reproduce

  1. Set up a React component that utilizes getQueryData, and call setQueryData in a different part of the application to populate data in the query.
  2. Inside the component, log the result of queryClient.getQueryData('queryKey') to the console during render.
  3. Ensure there are no follow up invocations of queryClient.setQueryData for the 'queryKey' that would suddenly set it to undefined.
  4. Observe the console log during the component's render phase.

Expected behavior

As a user, I expected getQueryData to not return some new value unless something happened to update that query. If this is something to do with a cache becoming stale, that is something I didn't see in the docs.

How often does this bug happen?

Often

Screenshots or Videos

No response

Platform

Browser: Chrome

Tanstack Query adapter

react-query

TanStack Query version

5.24.1

TypeScript version

5.2.2

Additional context

No response

@TkDodo
Copy link
Collaborator

TkDodo commented Mar 14, 2024

can't access that sandbox, please make it public

@frederikhors
Copy link
Contributor

Same problem here @TkDodo unfortunately. In svelte using:

@tanstack/eslint-plugin-query": "5.28.6",
"@tanstack/query-persist-client-core": "5.28.9",
"@tanstack/svelte-query": "5.28.9",
"@tanstack/svelte-query-devtools": "5.28.10",

I'll try to create a reproduction soon.

@frederikhors
Copy link
Contributor

@LukasDeco do you have any work-around? Any fix?

@frederikhors
Copy link
Contributor

I don't know if this is the same issue I'm facing right now. I opened #7204 with a reproduction. @LukasDeco your reproduction is 404.

@TkDodo
Copy link
Collaborator

TkDodo commented Apr 2, 2024

gonna close this because the reproduction is inaccessible.

@TkDodo TkDodo closed this as not planned Won't fix, can't repro, duplicate, stale Apr 2, 2024
@LukasDeco
Copy link
Author

@LukasDeco do you have any work-around? Any fix?

@frederikhors I just had to add some extra logic to catch if it went undefined and then throw it in a useState. It's a bit of a mess.

@LukasDeco
Copy link
Author

@TkDodo I changed to public

@LukasDeco
Copy link
Author

@TkDodo the example is updated to be working now: https://codesandbox.io/p/sandbox/react-query-bug-qw336y?file=%2Fsrc%2FApp.js%3A14%2C26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants