Skip to content

throwOnError: () => false, avoids query refetch on mount if an error is already set, and there is no data yet (no stale time) #10094

@GitonioDev

Description

@GitonioDev

Describe the bug

When setting throwOnError: () => false, it will not refetch the query if there is an error set and there is no data
however the throwOnError: false works, but then hydrated errors via the HydrationBoundary will directly retry and wont check the hydrated error state

See this is my logic to get the error instance back again

    merged.queries.forEach((query) => {
        if (query.state.error) {
            query.state.error = deserializeApplicationError(query.state.error);
        }
        if (query.state.fetchFailureReason) {
            query.state.fetchFailureReason = deserializeApplicationError(query.state.fetchFailureReason);
        }
    });

But it only prevents a retry if i set throwOnError: () => false if i set throwOnError: false the normal behavoir of queries work again so that when there was an error fetched it will just fetch again on an mount but then the query is retried directly without it being checked against the retry: function

Your minimal, reproducible example

Steps to reproduce

  1. Create a Blank react query project
  2. Make a query with throwOnError: () => false
  3. Fetch an error on the very beginning (no data yet)
  4. Try to remount the query see it will not refetch it

Expected behavior

I want that with throwOnError: false, it should also respect the hydrated errors so that it checks it against the retry: and sees oh i dont need to retry this kind of error because retry: false, and i also did not fogot to set shouldDehydrateQuery to true if i dont want to retry the query to prevent a loading state

How often does this bug happen?

None

Screenshots or Videos

No response

Platform

  • OS: Windows
  • Browser: Firefox

Tanstack Query adapter

react-query

TanStack Query version

v5.83.0

TypeScript version

v5.9.2

Additional context

No response

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