Skip to content

Conversation

@joker23
Copy link
Contributor

@joker23 joker23 commented Dec 24, 2025

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

sdk-1709

Describe the solution you've provided

  • Changed the identify and identifyResult methods in LDClient to accept LDContextWithAnonymous instead of LDContext, allowing for more flexible context handling.
  • Introduced LDContextWithAnonymous type in a new LDContext.ts file to define contexts that may not have a key.
  • Updated documentation around the anonymous context type to explain that client side sdks will assign a key to a context that does not have one.
  • Updated browser SDK to use new context type for identification functions
  • updated unit tests to ensure that anonymous contexts with undefined keys can be processed

Provide a clear and concise description of what you expect to happen.

Additional context

This change is prompted by seeing the type inconsistencies between v3 and v4 browser sdk. Since we have an ensureKey function that will fedrate a context id to the context if it does not have one, then we should also be able to support passing in contexts that do not have keys.


Note

Aligns identify APIs to accept contexts without pre-generated keys and centralizes typing for anonymous contexts.

  • Adds LDContextWithAnonymous type in shared/sdk-client/src/api/LDContext and re-exports from package entry points
  • Updates identify/identifyResult signatures in LDClient, LDClientImpl, BrowserClient, and createClient to use LDContextWithAnonymous
  • Updates ensureKey to accept LDContextWithAnonymous and generate keys for anonymous single/multi-kind contexts
  • Adjusts browser/tests to pass anonymous contexts without empty key and updates related imports
  • Minor doc/type export tweaks in common.ts, index.ts, and API surfaces

Written by Cursor Bugbot for commit 10d285d. This will update automatically on new commits. Configure here.

@joker23 joker23 requested a review from a team as a code owner December 24, 2025 21:00
@github-actions
Copy link
Contributor

github-actions bot commented Dec 24, 2025

@launchdarkly/browser size report
This is the brotli compressed size of the ESM build.
Compressed size: 171262 bytes
Compressed size limit: 200000
Uncompressed size: 798483 bytes

@github-actions
Copy link
Contributor

@launchdarkly/js-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 25394 bytes
Compressed size limit: 26000
Uncompressed size: 124693 bytes

@github-actions
Copy link
Contributor

github-actions bot commented Dec 24, 2025

@launchdarkly/js-client-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 19359 bytes
Compressed size limit: 20000
Uncompressed size: 99863 bytes

@github-actions
Copy link
Contributor

github-actions bot commented Dec 24, 2025

@launchdarkly/js-client-sdk size report
This is the brotli compressed size of the ESM build.
Compressed size: 23334 bytes
Compressed size limit: 25000
Uncompressed size: 81374 bytes

Copy link
Member

Choose a reason for hiding this comment

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

I think this typing looks good for a multi-kind context, but not for a single kind context. In that this typing for a single kind would make key appear to be not an available option.

I wonder if we should just be using basically a copy of the single/multi context kinds with key correct specified as being optional. Then converting that for internal use?

Though, I suppose, it could be an Omit and then & { key?: string }. I want to make sure we have somewhat intelligible code completion though.

Copy link
Member

Choose a reason for hiding this comment

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

Or it could be type singleKindOptionalKey = Omit<LDSingleKindContextBase, 'key'> | LDSingleKindContextBase

Though again I am not sure how good the intellisense for that would be. Maybe fine.

Copy link
Contributor Author

@joker23 joker23 Jan 7, 2026

Choose a reason for hiding this comment

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

I think there is something fundamentally wrong here... so the ensureKey function will ONLY federate the context with a key if the context is anonymous:

So given that perhaps the correct thing to do is create an anonymous context interface, eg:

interface anonymousSingleKindContext extends Omit<LDSingleKindContextBase, 'key'> {
  key?: string;
  anonymous: boolean;
}

And do the same for multi of course

Then ultimately the LDContext that could be used in a client side identify will be:

type LDContextWithAnonymous =
  | LDSingleKindContext                         // original single kind context
  | anonymousSingleKindContext          // anon context that could be missing key
  | multiKindContextWithAnonymous;

@kinyoklion FYI

Copy link
Member

Choose a reason for hiding this comment

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

This seems like the right path.

We do need to also consider what the impact of this will be consumption side. My reflex is that it should be exported as LDContext, but if not, then we need to make sure that LDContext doesn't upset the structural typing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ended up going the route of introducing a new type since I think there is still some value in having a context type that can match a context that is "ensured". Typescript is a bit finicky.

@joker23 joker23 force-pushed the skz/sdk-1709/client-sdk-context branch from c423aaf to a4097a4 Compare January 7, 2026 21:53
- Changed the `identify` and `identifyResult` methods in `LDClient` to accept `LDContextPartial` instead of `LDContext`, allowing for more flexible context handling.
- Introduced `LDContextPartial` type in a new `LDContext.ts` file to define contexts that may not have a key.
- Updated documentation around the partial context to explain that client side sdks will assign a key to a context that does not have one.
@joker23 joker23 force-pushed the skz/sdk-1709/client-sdk-context branch from a4097a4 to 7cfcaad Compare January 7, 2026 22:02
@joker23 joker23 force-pushed the skz/sdk-1709/client-sdk-context branch from 7cfcaad to 10d285d Compare January 7, 2026 22:04
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