Skip to content

Bind all public methods in the FormoAnalytics constructor - #85

Merged
yosriady merged 2 commits into
mainfrom
fix/bind-public-methods
Aug 18, 2026
Merged

Bind all public methods in the FormoAnalytics constructor#85
yosriady merged 2 commits into
mainfrom
fix/bind-public-methods

Conversation

@yosriady

@yosriady yosriady commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Customer report: const { reset } = useFormo() crashed with Cannot set property currentUserId of undefined.

The provider passes the FormoAnalytics instance directly as the React context value, so consumers can destructure methods off it. Only 9 methods were bound in the constructor. reset, cleanup, flush, setTrafficSourceFromUrl, optOutTracking, optInTracking, hasOptedOutTracking, the 3 pushNotification* methods, and isAttributionEnabled lost this when destructured.

Companion fix for the web SDK (same gap): getformo/sdk#334

Changes

  • Bind every public method in the constructor.
  • Add regression tests: each public method must be a bound own property of the instance, and a destructured reset() must clear session state without a throw.

Testing

  • pnpm jest: 21 suites, 393 tests, all pass.
  • pnpm tsc --noEmit: clean.
  • Codex review (gpt-5.5, high): no findings after iteration.
  • E2E in examples/with-react-native (Expo web + Playwright): with published 1.1.0, a destructured reset() crashes with Cannot set properties of undefined (setting 'currentUserId'). With this branch's build overlaid, the SDK initializes fully (Wagmi mode, lifecycle, crash reporter) and the same destructured reset() succeeds.

🤖 Generated with Claude Code

The provider passes the SDK instance directly as the React context
value, so useFormo consumers can destructure methods
(const { reset } = useFormo()). Only 9 methods were bound; reset and
9 other public methods lost `this` when destructured, and reset
crashed with "Cannot set property currentUserId of undefined".

Bind every public method in the constructor and add regression tests
that assert each method is a bound own property and that a
destructured reset() works.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/__tests__/FormoAnalytics.test.ts
@yosriady
yosriady merged commit dd4bc7d into main Aug 18, 2026
13 checks passed
@yosriady
yosriady deleted the fix/bind-public-methods branch August 18, 2026 03:34
@yosriady yosriady mentioned this pull request Aug 18, 2026
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