Describe the bug#
When select returns undefined, the promise never resolves.
const { promise } = useQuery({
queryKey: ['projects'],
queryFn: fetchProjects,
select: (xs) => xs[100],
});
const data = React.use(promise);
Your minimal, reproducible example#
https://stackblitz.com/edit/tanstack-query-hockrnrg?file=src%2Findex.tsx&preset=node
Steps to reproduce#
- Go to the reduced test case.
- Observe the promise never resolves.
Expected behavior#
The promise resolves with undefined, maybe? 🤔
I appreciate undefined is not valid JSON…
How often does this bug happen?#
None
Screenshots or Videos#
No response
Platform#
N/A
Tanstack Query adapter#
None
TanStack Query version#
5.90.7
TypeScript version#
No response
Additional context#
Potentially related: https://github.com/TanStack/query/issues/9844
undefinedis not allowed as a cache value, and it’s also not allowed as a return value ofselect. We could document this better or add a runtime warning in development. PRs welcome, but this is expected behavior.