Replies: 1 comment 5 replies
-
See #2740. The key point is SSR, which has less to do with RSC or 'use client'. @dbritto-dev is working on revamping docs, and we would like to add a new guide. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi Zustand team! 👋
I'm working with Next.js 15 App Router and have a question about the official Next.js guide.
Current Understanding
According to the guide, we should use Provider pattern with factory functions to avoid sharing state across requests. However, I'm wondering if this is still necessary when using 'use client' directive.
My Analysis
When we use 'use client', the behavior seems to be:
Server-side: The client component code (including Zustand store) is completely excluded from the server bundle
Client-side: Each browser/tab gets its own independent JavaScript execution context
Memory isolation: Each browser runs in separate processes with separate memory spaces
Is the Provider + factory pattern still necessary when using 'use client'?
It seems like 'use client' already provides:
✅ Server isolation: Store code doesn't execute on server at all
✅ Client isolation: Each browser = separate process = separate memory
✅ Per-request isolation: Each user request gets independent client-side execution
📡 Server (Node.js)
├── Handles multiple requests simultaneously
├── user-store.ts never executes (due to 'use client')
└── No shared state possible ✅
💻 Browser A (User A)
├── Downloads and executes user-store.ts
├── Creates independent store instance A
└── Isolated memory space
💻 Browser B (User B)
├── Downloads and executes user-store.ts
├── Creates independent store instance B
└── Completely separate from Browser A ✅
Current Project Context
Environment:
Specific Questions
Would love to understand the nuanced scenarios where each approach is recommended!
Thanks for the amazing library! 🙏
Beta Was this translation helpful? Give feedback.
All reactions