Skip to content

fix: add forceNew option to bypass singleton for SSR#13

Merged
xingxinglieo merged 1 commit into
mainfrom
fix/ssr-singleton-bypass
Mar 10, 2026
Merged

fix: add forceNew option to bypass singleton for SSR#13
xingxinglieo merged 1 commit into
mainfrom
fix/ssr-singleton-bypass

Conversation

@xingxinglieo
Copy link
Copy Markdown
Contributor

Summary

  • Add forceNew option to initStatsigClient that skips singleton cache
  • When forceNew is true, creates a new client instance without storing it in the module-level singleton
  • Fixes SSR hydration mismatch in Next.js production where the singleton persists across requests, causing stale bootstrap data

Usage

// SSR: each request gets fresh client with its own bootstrap
initStatsigClient(key, user, { bootstrap, forceNew: true });

// Client: singleton behavior unchanged
initStatsigClient(key, user, { bootstrap });

🤖 Generated with Claude Code

SSR in production persists module-level singleton across requests,
causing stale bootstrap data. forceNew skips the cache and creates
a fresh client instance without polluting the singleton.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

📦 Canary version published!

pnpm add statsig@0.0.4-canary.pr13.9497b77
# or
pnpm add statsig@canary

@xingxinglieo xingxinglieo merged commit 3cf8cbf into main Mar 10, 2026
5 checks passed
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.

1 participant