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

environmentManager.md

68 lines1.5 KB

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