Skip to content

Changed globalstore to not be split#686

Merged
TheJeran merged 2 commits into
mainfrom
jp/forceGlobalStore
Jul 17, 2026
Merged

Changed globalstore to not be split#686
TheJeran merged 2 commits into
mainfrom
jp/forceGlobalStore

Conversation

@TheJeran

Copy link
Copy Markdown
Collaborator

In #684 the variable state in useGlobalStore got 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 useGlobalStore as 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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +207 to +208
export const useGlobalStore =
globalThis.__appStore ?? (globalThis.__appStore = createStore()) No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
export const useGlobalStore =
globalThis.__appStore ?? (globalThis.__appStore = createStore())
export const useGlobalStore =
typeof window !== 'undefined'
? (globalThis.__appStore ?? (globalThis.__appStore = createStore()))
: createStore()

@TheJeran
TheJeran merged commit fc5107f into main Jul 17, 2026
6 checks passed
@TheJeran
TheJeran deleted the jp/forceGlobalStore branch July 17, 2026 13:00
@lazarusA

lazarusA commented Jul 17, 2026

Copy link
Copy Markdown
Member

no.

Screenshot 2026-07-17 at 15 07 33

please, always check locally before merging

rm -rf out
npm run build
npx serve@latest out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants