Bind all public methods in the FormoAnalytics constructor - #85
Merged
Conversation
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>
There was a problem hiding this comment.
All reported issues were addressed across 2 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Customer report:
const { reset } = useFormo()crashed withCannot set property currentUserId of undefined.The provider passes the
FormoAnalyticsinstance 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 3pushNotification*methods, andisAttributionEnabledlostthiswhen destructured.Companion fix for the web SDK (same gap): getformo/sdk#334
Changes
reset()must clear session state without a throw.Testing
pnpm jest: 21 suites, 393 tests, all pass.pnpm tsc --noEmit: clean.examples/with-react-native(Expo web + Playwright): with published 1.1.0, a destructuredreset()crashes withCannot set properties of undefined (setting 'currentUserId'). With this branch's build overlaid, the SDK initializes fully (Wagmi mode, lifecycle, crash reporter) and the same destructuredreset()succeeds.🤖 Generated with Claude Code