Describe the bug#
Firstly, thank you for your work on this library! I am currently using a pull approach to seed the query cache, and I have encountered a specific issue. When a user enters a page, I call ensureQueryData, passing in an initialData value, which may be undefined. The issue I am facing is that ensureQueryData always triggers a fetch when the data is not already in the cache, even when initialData is provided (non undefined).
Below is a simplified example in pseudo-code to illustrate the issue:
const query = queries.postById.getOptions(id);
await queryClient.ensureQueryData({
...query,
initialData: utils.findInPages(queries.postList.getKey(), byId(id)),
});
Your minimal, reproducible example#
Stackblitz
Steps to reproduce#
https://stackblitz.com/edit/vitejs-vite-cnkcntdk?file=src%2FApp.tsx
Expected behavior#
Since I am providing initialData, the expected behavior is for the query client to store the initialData in the cache and bypass the fetch process.
How often does this bug happen?#
Every time
Screenshots or Videos#
No response
Platform#
- OS: macOS
- Browser: Chrome 131
Tanstack Query adapter#
react-query
TanStack Query version#
5.62.3
TypeScript version#
No response
Additional context#
No response
good point. we need to fix that.