Skip to content

[FIX] Allow addUserExtraInfo to be called without prior setUserInfo#1288

Merged
cdn34dd merged 2 commits into
developfrom
carlosnogueira/fix/allow-extra-user-info-without-id
May 21, 2026
Merged

[FIX] Allow addUserExtraInfo to be called without prior setUserInfo#1288
cdn34dd merged 2 commits into
developfrom
carlosnogueira/fix/allow-extra-user-info-without-id

Conversation

@cdn34dd
Copy link
Copy Markdown
Contributor

@cdn34dd cdn34dd commented May 20, 2026

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)

  • Feature or bugfix MUST have appropriate tests
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)
  • If this PR is auto-generated, please make sure also to manually update the code related to the change

Copilot AI review requested due to automatic review settings May 20, 2026 17:25
@cdn34dd cdn34dd requested a review from a team as a code owner May 20, 2026 17:25
@datadog-datadog-prod-us1

This comment has been minimized.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 UserInfo typings to allow missing id, while keeping setUserInfo requiring a non-empty id.
  • Updated the JS-side user info storage to support accumulating extraInfo without prior setUserInfo.
  • Added/updated Jest tests covering the new addUserExtraInfo behavior 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.

Comment thread packages/core/src/sdk/UserInfoSingleton/UserInfoSingleton.ts Outdated
@cdn34dd cdn34dd force-pushed the carlosnogueira/fix/allow-extra-user-info-without-id branch from 02d6a80 to 8501692 Compare May 20, 2026 18:15
extraInfo?: Record<string, unknown>;
}): Promise<void> => {
static setUserInfo = async (
userInfo: UserInfo & { id: string }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

@sbarrio sbarrio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔧

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.
Copilot AI review requested due to automatic review settings May 21, 2026 09:25
@cdn34dd cdn34dd force-pushed the carlosnogueira/fix/allow-extra-user-info-without-id branch from 8501692 to 26e6a3e Compare May 21, 2026 09:25
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Comment thread packages/core/src/sdk/UserInfoSingleton/UserInfoSingleton.ts
Comment thread packages/core/src/__tests__/DdSdkReactNative.test.tsx
Comment thread packages/core/src/types.tsx
@cdn34dd cdn34dd force-pushed the carlosnogueira/fix/allow-extra-user-info-without-id branch from 26e6a3e to 81d29b1 Compare May 21, 2026 13:59
@cdn34dd cdn34dd requested a review from sbarrio May 21, 2026 14:00
@cdn34dd cdn34dd merged commit 3e9514a into develop May 21, 2026
11 checks passed
@cdn34dd cdn34dd deleted the carlosnogueira/fix/allow-extra-user-info-without-id branch May 21, 2026 14:22
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.

3 participants