Skip to content

A query that was dehydrated as pending ended up rejecting. #8138

Answered by TkDodo
SaadFarooq-Dev asked this question in Q&A
Discussion options

You must be logged in to vote

the problem is that your custom dehydrateOptions also persist erroneous / pending queries. That not only doesn’t work because you can’t serialize Error classes, but it also wants to store pending queries, which puts promises into the cache. Persistence and server-side-rendering use the same hydration approach, so getting promises from the persister back doesn’t really work.

What you want is to only persist successful queries, which we do per default, so:

import { defaultShouldDehydrateQuery } from "@tanstack/react-query";

dehydrateOptions: {
  shouldDehydrateQuery: (query) => {
    return (
      defaultShouldDehydrateQuery(query) &&
      !doNotPersistQueries.includes(query.queryKey[0])…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@SaadFarooq-Dev
Comment options

@SaadFarooq-Dev
Comment options

@SaadFarooq-Dev
Comment options

@TkDodo
Comment options

Answer selected by SaadFarooq-Dev
@SaadFarooq-Dev
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants