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

environmentManager.md

64 lines1.3 KB

1---
2id: environmentManager
3title: environmentManager
4---
5​
6```ts
7const environmentManager: object;
8```
9​
10Defined in: [packages/query-core/src/environmentManager.ts:32](https://github.com/TanStack/query/blob/main/packages/query-core/src/environmentManager.ts#L32)
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`true` if the runtime is treated as a server.
36​
37### setIsServer()
38​
39```ts
40setIsServer(isServerValue: IsServerValue): void;
41```
42​
43Overrides the server check globally.
44​
45#### Parameters
46​
47##### isServerValue
48​
49`IsServerValue`
50​
51A function that returns whether the runtime should be treated as a
52server.
53​
54#### Returns
55​
56`void`
57​
58## Example
59​
60```ts
61import { environmentManager } from '@tanstack/query-core'
62​
63environmentManager.setIsServer(() => false)
64```