Skip to content

useQuery().promise will always be a rejected promise if the query is in an error state #8507

Closed as not planned
@KATT

Description

@KATT

Describe the bug

If a query has ever errored, getOptimisticResult() will always return an error status (rather than a pending one)

Your minimal, reproducible example

https://codesandbox.io/p/devbox/winter-darkness-k48yny

Steps to reproduce

  1. Fail a query
  2. Try to use useQuery().promise somewhere else
  3. Component always fails, rather than optimistically fetching when it renders

Expected behavior

If the getOptimisticResult() should reflect the actual optimistic result, it should be pending

How often does this bug happen?

None

Screenshots or Videos

No response

Platform

CodeSandbox

Tanstack Query adapter

None

TanStack Query version

latest

TypeScript version

latest

Additional context

Discovered while trying to fix #8499 and tried to fix in the same PR, but will try to have a stab on doing it separately

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions