[FIX] Allow addUserExtraInfo to be called without prior setUserInfo#1288
[FIX] Allow addUserExtraInfo to be called without prior setUserInfo#1288cdn34dd wants to merge 1 commit into
Conversation
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
This PR aligns the React Native SDK’s user extra info behavior with iOS/Android by allowing addUserExtraInfo to be called even when no user ID was previously set.
Changes:
- Relaxed
UserInfotypings to allow missingid, while keepingsetUserInforequiring a non-emptyid. - Updated the JS-side user info storage to support accumulating
extraInfowithout priorsetUserInfo. - Added/updated Jest tests covering the new
addUserExtraInfobehavior and the updated default user info state.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/core/src/types.tsx | Makes UserInfo.id optional and updates setUserInfo typing to still require an id. |
| packages/core/src/sdk/UserInfoSingleton/UserInfoSingleton.ts | Stores user info as an object and adds addUserExtraInfo to merge extra attributes. |
| packages/core/src/sdk/UserInfoSingleton/types.ts | Updates internal UserInfo to make id optional. |
| packages/core/src/sdk/UserInfoSingleton/tests/UserInfoSingleton.test.ts | Updates expectations for default/cleared user info to be {}. |
| packages/core/src/DdSdkReactNative.tsx | Removes the JS guard preventing addUserExtraInfo before setUserInfo and adds id validation for setUserInfo. |
| packages/core/src/tests/DdSdkReactNative.test.tsx | Adds a test for addUserExtraInfo without prior setUserInfo and updates clear-user assertions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The JS-side guard in addUserExtraInfo required setUserInfo to be called first, which prevented setting custom user attributes without providing a user ID. This was inconsistent with the native iOS and Android SDKs, which allow addUserExtraInfo to be called independently.
02d6a80 to
8501692
Compare
| extraInfo?: Record<string, unknown>; | ||
| }): Promise<void> => { | ||
| static setUserInfo = async ( | ||
| userInfo: UserInfo & { id: string } |
There was a problem hiding this comment.
I'm not a fan of this but I agree that it may be the only option we have to make this work without making id mandatory at UserInfo level.
I'd leave a comment here in any case explaining why we are enforcing this in this manner and not directly on type definition.
There was a problem hiding this comment.
Sure, I'll add a comment explaining it, but also add it here for future reference.
The basic idea is that we don't want users to be able to specify the other userInfo properties like name or email without setting an id, because if you're setting any of these values you should have an id , but we do want to allow them to add custom properties (as these can be anything) without the need to set an id.
What does this PR do?
Fixes inconsistency between the React Native SDK and the Android and iOS SDKs when it comes to the handling of extra user info.
Motivation
The JS-side guard in addUserExtraInfo required setUserInfo to be called first, which prevented setting custom user attributes without providing a user ID. This was inconsistent with the native iOS and Android SDKs, which allow addUserExtraInfo to be called independently.
Additional Notes
Anything else we should know when reviewing?
Review checklist (to be filled by reviewers)