Open History to see the last commit
1import { isServer as defaultIsServer } from './utils'
2β
3export type IsServerValue = () => boolean
4β
5let isServerFn: IsServerValue = () => defaultIsServer
6β
7/**
8 * Returns whether the current runtime should be treated as a server environment.
9 */
10export const isServer = (): boolean => isServerFn()
11β
12/**
13 * Manages how TanStack Query detects whether the current runtime should be treated as
14 * server-side, which disables scheduling refetch timers and changes the default `retry` count
15 * and `gcTime`. By default, the detection treats a missing `window` (or the presence of a
16 * `Deno` global) as server.
17 *
18 * Override this for runtimes where that default detection would give the wrong answer β for
19 * example, a Service Worker, where `window` is undefined even though the environment should
20 * behave like a client.
21 *
22 * @example
23 * ```ts
24 * import { environmentManager } from '@tanstack/query-core'
25 *
26 * environmentManager.setIsServer(() => false)
27 * ```
28 */
29export const environmentManager = {
30 isServer,
31 /**
32 * Overrides the server check globally.
33 */
34 setIsServer(isServerValue: IsServerValue): void {
35 isServerFn = isServerValue
36 },
37}