Bug: Streaming with Server Components documentation references non-existent `shouldRedactErrors` option #9047
Send to my agentDescribe 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:
shouldRedactErrorswas originally used to handle how server errors were passed to the client- In v5, this option seems to have been removed as Next.js now provides better error handling mechanisms by default
- 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#
Steps to reproduce#
- Create a new Next.js 14 project with TanStack Query v5
- Set up the QueryClient configuration following the documentation
- Add the
dehydrateconfiguration as shown in the docs:
dehydrate: {
shouldDehydrateQuery: (query) => defaultShouldDehydrateQuery(query) || query.state.status === 'pending',
shouldRedactErrors: (error) => {
return false;
},
}
- TypeScript will immediately show the error: "Object literal may only specify known properties, and 'shouldRedactErrors' does not exist in type 'DehydrateOptions'"
- Checking the type definitions (
DehydrateOptionsinterface) confirms thatshouldRedactErrorsis 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
TkDodo closed this
TkDodo added labelsinvalid
Thanks for your answer. The screenshot was taken when the issue occurred. After updating to the latest version, the problem was resolved.
then you were very likely using a version from before this was added.
Sign in to join this conversation.
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