Skip to content
Source
Sign inSign up
TanStack/query

Bug: Streaming with Server Components documentation references non-existent `shouldRedactErrors` option #9047

Send to my agent
Closeddkmqflx(GitHub profile, opens in a new tab) opened this issue 3 comments

Describe the bug

Bug Report: shouldRedactErrors Documentation Mismatch with v5

Description

The official documentation for Streaming with Server Components includes code that throws a TypeScript error in v5. Specifically, the shouldRedactErrors option in dehydrate configuration is no longer valid in v5, but it's still present in the documentation.

Error Message

Object literal may only specify known properties, and 'shouldRedactErrors' does not exist in type 'DehydrateOptions'.

Current Documentation Code

// app/get-query-client.ts
import {
  isServer,
  QueryClient,
  defaultShouldDehydrateQuery,
} from '@tanstack/react-query'

function makeQueryClient() {
  return new QueryClient({
    defaultOptions: {
      queries: {
        staleTime: 60 * 1000,
      },
      dehydrate: {
        // include pending queries in dehydration
        shouldDehydrateQuery: (query) =>
          defaultShouldDehydrateQuery(query) ||
          query.state.status === 'pending',
        shouldRedactErrors: (error) => {
          // We should not catch Next.js server errors
          // as that's how Next.js detects dynamic pages
          // so we cannot redact them.
          // Next.js also automatically redacts errors for us
          // with better digests.
          return false
        },
      },
    },
  })
}

let browserQueryClient: QueryClient | undefined = undefined

export function getQueryClient() {
  if (isServer) {
    // Server: always make a new query client
    return makeQueryClient()
  } else {
    // Browser: make a new query client if we don't already have one
    // This is very important, so we don't re-make a new client if React
    // suspends during the initial render. This may not be needed if we
    // have a suspense boundary BELOW the creation of the query client
    if (!browserQueryClient) browserQueryClient = makeQueryClient()
    return browserQueryClient
  }
}

I checked the type definition of dehydrate and confirmed that shouldRedactErrors is not included in its type definitions.

I have a question about this documentation issue: Can we still use Streaming SSR without the shouldRedactErrors option in v5?

From my understanding:

  1. shouldRedactErrors was originally used to handle how server errors were passed to the client
  2. In v5, this option seems to have been removed as Next.js now provides better error handling mechanisms by default
  3. Streaming SSR should work fine with just:
dehydrate: {
  shouldDehydrateQuery: (query) => 
    defaultShouldDehydrateQuery(query) || 
    query.state.status === 'pending'
}

Could you confirm if this understanding is correct? It would be helpful to know if there are any implications or additional considerations for error handling in Streaming SSR without this option.

Your minimal, reproducible example

https://www.typescriptlang.org/play/?#code/PTAEEMAdOBzBTALgWgI4Fd4CcCeyDGANgJbwB2iAdIgM4BQxAtpAPZaKgDedooxNAZWwA3bABoeoAIqZcAYRLlEE3gBN4AM3DpCiAQAsWO1QBF4+nKqzhE8GdhwSAvqA1YWjUAHIAAonBkNP74ANbAWPDg+CgYDl50dBroZNHELGSgjOAhdrI4CqQUABQAlFySEYjoWBlk8ADu0nkFSkXcvGqa2roA8pCIaYEAXOUdHbFYpDQj7WMdQeCE8AAqTPAjAGwADKAAVKAAjFvHKnNOp2PqFlY266NzvCB8KYTo6qCQ5KrEZLCgE1NnqArpZrAN0pIHjRDMYzNcwbkHCMihMcGUALwAPkhD2BXR0ehhhFM5lBt3suBReTKAB8aTiHqjKAtbMz-FUaKB0dzvJ8yN9fl4LnNoUZiQAleCqKKIACiWHcWGmoCK2EVGMx91xoCeAHV4KBRcZQGQWBx8DZ8PpQAA5eAADyoACtOTQRNhQGq2PRtY8wOBOYh9DYvJzDI07Y7KC68bZopzVDgyOBGMR8B9wAgfb6njQWKB6gaLWRTRwItLoqAg-BGJQGXMnpHnZzFnmIOhEB4bGnFoQcKByzLOV6la42KB0NntU96sQg6AAEZIWxYYHELO0Ou+gdIaoZLSEN313jneunsbn0BOEp0JwJJYcBfuepurAU-KKCgjd8tCigGkTvymg-FKXKAeoGggaoCQOqw7CuMkqTpKACCID+n6IKU9zEBoKr8EIWCiFgZSzH6oAEURIyLPU4A4JyWQ5BAJoNP8eSgEQhSIDilR7pk2SIvIGGlJILjwIeBqkTqYAAELPq+IwMQa4DMY0qLsRhfC4YWwLpF4HCLBE4CJqAwaiKA6TwDiTzLPo-B8JyRH9kwcH+BQYiGvm2mqLpZbwMgilMXUjQcUommgJKMpWWANCTnyqgJtUPx-NWzxzsQiw7kBWCUKANl2Vk-alouBp1FKoE4QWlljE8plKYasXkG6i5GPy4C4KA0mygAMj0upVvoRaGeCGQsLhKVqSFFA4hVRQAIRPiwL7YOhnFlAtS1vs0GnonxOQra0N5jDxNSLnJy1bZxIm3kAA

Steps to reproduce

  1. Create a new Next.js 14 project with TanStack Query v5
  2. Set up the QueryClient configuration following the documentation
  3. Add the dehydrate configuration as shown in the docs:
dehydrate: {
  shouldDehydrateQuery: (query) => defaultShouldDehydrateQuery(query) || query.state.status === 'pending',
  shouldRedactErrors: (error) => {
    return false;
  },
}
  1. TypeScript will immediately show the error: "Object literal may only specify known properties, and 'shouldRedactErrors' does not exist in type 'DehydrateOptions'"
  2. Checking the type definitions (DehydrateOptions interface) confirms that shouldRedactErrors is not a valid option in v5

Expected behavior

The documentation should be updated to reflect v5's API, where shouldRedactErrors is no longer needed as Next.js now handles server errors differently.

This appears to be a documentation issue where the example hasn't been updated to match v5's API changes. The code works after removing the shouldRedactErrors option.

How often does this bug happen?

None

Screenshots or Videos

No response

Platform

  • OS: MacOS
  • Browser: Chrome

Tanstack Query adapter

react-query

TanStack Query version

"@tanstack/react-query": "^5.64.1",

TypeScript version

"typescript": "^5",

Additional context

No response

  1. There is no error in your provided reproduction and the optional definitely exists:

    https://github.com/TanStack/query/blob/e73d5b419ea4f1b1970affddbe28807899095422/packages/query-core/src/hydration.ts#L25

  2. TkDodo closed this

  3. TkDodo added labelsinvalid

  4. Image

    Thanks for your answer. The screenshot was taken when the issue occurred. After updating to the latest version, the problem was resolved.

  5. then you were very likely using a version from before this was added.

Sign in to join this conversation.