React · Senior · Question 37 of 75
Why can't you use a single global QueryClient for all requests on the server?
- ✓Correct answer: One user's cache can leak into another user's response
- 2A global client doesn't support async requests
- 3Next.js forbids module-level variables in server code
Explanation
The server handles requests from different users in one process, and a shared cache would mix their data. Create a client per request (e.g. via React's cache() in RSC). In the browser, on the contrary, there's one client for the whole app.