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

environmentManager.md

50 lines1.3 KB

1---
2id: EnvironmentManager
3title: environmentManager
4---
5​
6The `environmentManager` manages how TanStack Query detects whether the current runtime should be treated as server-side.
7​
8By default, it uses the same server detection as the exported `isServer` utility from query-core.
9​
10Use this manager to override server detection globally for runtimes that are not traditional browser/server environments (for example, extension workers).
11​
12Its available methods are:
13​
14- [`isServer`](#environmentmanager-isserver)
15- [`setIsServer`](#environmentmanager-setisserver)
16​
17## `environmentManager.isServer`
18​
19Returns whether the current runtime is treated as a server environment.
20​
21```tsx
22import { environmentManager } from '@tanstack/react-query'
23​
24const server = environmentManager.isServer()
25```
26​
27## `environmentManager.setIsServer`
28​
29Overrides the server check globally.
30​
31```tsx
32import { environmentManager } from '@tanstack/react-query'
33​
34// Override
35environmentManager.setIsServer(() => {
36 return typeof window === 'undefined' && !('chrome' in globalThis)
37})
38```
39​
40**Options**
41​
42- `isServerValue: () => boolean`
43​
44To restore the default behavior, set the function back to query-core's `isServer` utility:
45​
46```tsx
47import { environmentManager, isServer } from '@tanstack/react-query'
48​
49environmentManager.setIsServer(() => isServer)
50```