Skip to content

fix: graceful fallback when statsig client is not initialized - #10

Closed
xingxinglieo wants to merge 6 commits into
mainfrom
fix/graceful-fallback-on-uninitialized
Closed

xingxinglieo wants to merge 6 commits into
mainfrom
fix/graceful-fallback-on-uninitialized

Conversation

@xingxinglieo

Copy link
Copy Markdown
Contributor

Summary

  • FlagStore.resolve() 和 ParamStore.resolve() 在第4步获取远端值时,对 getStatsigClientSync() 加 try-catch 防御
  • Statsig 未初始化时不再抛异常,安全降级返回 fallback 值
  • 修正 client.ts 错误消息中的包名

Background

在 monorepo 的 canvas/agent-share 独立入口中,模块级别的 new AgentSocket() 在 import 求值阶段调用了 flagStore.getFlag('dm'),但此时 initStatsigClient() 尚未被调用,导致 getStatsigClientSync() 抛出 Not initialized 异常,页面崩溃。

根因是 FlagStore.resolve() 和 ParamStore.resolve() 没有对 statsig 未初始化的场景做防御处理。

Test plan

  • pnpm typecheck 通过
  • pnpm test 全部 21 个测试通过
  • 升级 monorepo 依赖后验证 /r/ 分享页不再崩溃

Made with Cursor

xingxinglieo and others added 6 commits February 6, 2026 11:13
- Add build script with tsc
- Update exports to point to dist/
- Add prepublishOnly hook
- Set type: module for ESM output

Co-authored-by: Cursor <cursoragent@cursor.com>
ts-node with commonjs module cannot resolve subpath exports
without a default fallback condition.

Co-authored-by: Cursor <cursoragent@cursor.com>
lodash is CJS-only and breaks named imports in ESM context.

Co-authored-by: Cursor <cursoragent@cursor.com>
FlagStore.resolve() and ParamStore.resolve() now catch the
getStatsigClientSync() throw and return fallback values instead of
crashing, preventing module-level side-effects from blowing up
when the entry point has not called initStatsigClient() yet.

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions

github-actions Bot commented Feb 6, 2026

Copy link
Copy Markdown

📦 Canary version published!

pnpm add statsig@0.0.3-canary.pr10.fd78749
# or
pnpm add statsig@canary

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