Changed globalstore to not be split#686
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the Zustand store initialization in src/GlobalStates/GlobalStore.ts to use a global singleton (globalThis) to prevent duplication across Next.js code chunks. Feedback highlights a critical issue where using globalThis on the server side can cause state leakage between concurrent user requests during server-side rendering (SSR). A code suggestion is provided to restrict the global singleton to the client side and instantiate a fresh store on the server.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| export const useGlobalStore = | ||
| globalThis.__appStore ?? (globalThis.__appStore = createStore()) No newline at end of file |
There was a problem hiding this comment.
In Next.js (SSR), globalThis on the server is shared across all concurrent requests. Storing the Zustand store on globalThis on the server can lead to state leakage between different users/requests if the store is ever modified during server-side rendering.
To prevent this, you should only use the globalThis singleton on the client side (where typeof window !== 'undefined'), and create a fresh/isolated store instance on the server side.
| export const useGlobalStore = | |
| globalThis.__appStore ?? (globalThis.__appStore = createStore()) | |
| export const useGlobalStore = | |
| typeof window !== 'undefined' | |
| ? (globalThis.__appStore ?? (globalThis.__appStore = createStore())) | |
| : createStore() |

In #684 the
variablestate inuseGlobalStoregot duplicated during prod and was being passed as "Default" to the webGPU component.This uses a method described here
https://www.prisma.io/docs/orm/more/troubleshooting/nextjs
Keeps
useGlobalStoreas a single global object. Analysis is working in prod.I'm new to globals. But this may be something we want to implement in all stores. Will need to read up on it.