Files
upstream-mirror 3a013ccdfe
Some checks failed
autofix.ci / autofix (push) Failing after 4s
Release / Release (push) Has been skipped
GitHub Actions Security Analysis / Run zizmor (push) Failing after 2s
snapshot of https://github.com/TanStack/query.git (main, 2026-09-16; blobs > 131072B omitted)
2026-09-16 01:13:08 +05:00

54 lines
1.3 KiB
TypeScript

import { Temporal } from '@js-temporal/polyfill'
import { QueryClient, defaultShouldDehydrateQuery } from '@tanstack/react-query'
import { createTson } from 'tupleson'
import type { TsonType } from 'tupleson'
const plainDate = {
deserialize: (v) => Temporal.PlainDate.from(v),
key: 'PlainDate',
serialize: (v) => v.toJSON(),
test: (v) => v instanceof Temporal.PlainDate,
} satisfies TsonType<Temporal.PlainDate, string>
export const countRef = {
current: 0,
}
export const tson = createTson({
types: [plainDate],
})
export function makeQueryClient() {
return new QueryClient({
defaultOptions: {
hydrate: {
/**
* Called when the query is rebuilt from a prefetched
* promise, before the query data is put into the cache.
*/
deserializeData: (data) => {
return tson.deserialize(data)
},
},
queries: {
staleTime: 60 * 1000,
},
dehydrate: {
serializeData: (data) => {
return tson.serialize(data)
},
shouldDehydrateQuery: (query) => {
return (
defaultShouldDehydrateQuery(query) ||
query.state.status === 'pending'
)
},
shouldRedactErrors: (error) => {
// Next.js automatically redacts errors for us
return false
},
},
},
})
}