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

environmentManager.md

61 lines1.3 KB

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