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

environmentManager.md

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