Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

environmentManager.md

59 lines1.2 KB

1---
2id: environmentManager
3title: environmentManager
4---
5​
6```ts
7const environmentManager: object;
8```
9​
10Defined in: [packages/query-core/src/environmentManager.ts:29](https://github.com/TanStack/query/blob/main/packages/query-core/src/environmentManager.ts#L29)
11​
12Manages how TanStack Query detects whether the current runtime should be treated as
13server-side, which disables scheduling refetch timers and changes the default `retry` count
14and `gcTime`. By default, the detection treats a missing `window` (or the presence of a
15`Deno` global) as server.
16​
17Override this for runtimes where that default detection would give the wrong answer β€” for
18example, a Service Worker, where `window` is undefined even though the environment should
19behave like a client.
20​
21## Type Declaration
22​
23### isServer()
24​
25```ts
26isServer: () => boolean;
27```
28​
29Returns whether the current runtime should be treated as a server environment.
30​
31#### Returns
32​
33`boolean`
34​
35### setIsServer()
36​
37```ts
38setIsServer(isServerValue: IsServerValue): void;
39```
40​
41Overrides the server check globally.
42​
43#### Parameters
44​
45##### isServerValue
46​
47`IsServerValue`
48​
49#### Returns
50​
51`void`
52​
53## Example
54​
55```ts
56import { environmentManager } from '@tanstack/query-core'
57​
58environmentManager.setIsServer(() => false)
59```