Skip to content

Conversation

@joker23
Copy link

@joker23 joker23 commented Dec 19, 2025

Description

This PR will allow the toolbar to be compatible with the new LD js client sdk.

What does this PR do?

  • Adds '@launchdarkly/js-client-sdk' package so we can reference new/changed types.
  • Adds compat typing so the toolbar plugins do not depend on a specific version of js client sdk
  • Ensured compatibility with existing code by handling type mismatches where necessary.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation (changes to documentation only)
  • 🔧 Refactor (code change that neither fixes a bug nor adds a feature)
  • 🎨 Style (formatting, missing semicolons, etc; no production code change)
  • Performance (code change that improves performance)
  • Test (adding missing tests, refactoring tests; no production code change)
  • 🔨 Chore (updating grunt tasks, build process, etc; no production code change)

Screenshots/Videos


@joker23 joker23 force-pushed the skz/sdk-1565/update-browser-sdk branch from 433d561 to 5d0f08d Compare December 19, 2025 00:40
@joker23 joker23 force-pushed the skz/sdk-1565/update-browser-sdk branch from 5d0f08d to 8402b84 Compare December 22, 2025 16:51

// Subscribe to changes with incremental updates
const handleChange = (changes: Record<string, { current: any }>) => {
// NOTE: we are overloading this function so that it can handle both the old and new browser SDKs
Copy link
Author

Choose a reason for hiding this comment

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

REVIEWER: we'll need to make sure we make super clear what is going on here. Am open to suggestions on what is more standard practice to support different event payloads.

Copy link
Member

Choose a reason for hiding this comment

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

This really would work better with an interface like inspectors, but it isn't convenient with the plugins.

Copy link
Author

Choose a reason for hiding this comment

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

So thinking about this more... This is probably the only place that needs to change to make the toolbar compatible with js client sdk v4 (as well as making sure we have a compatible type def)... So there are 2 options that I am thinking:

  1. Make the current implementation a bit better by doing some kind of type checking (ultimately we would know that it is a v4 change payload if the second param is a string[]
  2. We can also maybe leverage the client metadata (https://launchdarkly.github.io/js-core/packages/sdk/browser/docs/interfaces/LDPluginApplicationMetadata.html), but I guess that depends on whether it is guaranteed to exist in all versions?

@joker23 joker23 force-pushed the skz/sdk-1565/update-browser-sdk branch 3 times, most recently from c9348ce to e6738af Compare December 24, 2025 15:49
@joker23 joker23 force-pushed the skz/sdk-1565/update-browser-sdk branch 3 times, most recently from df4936a to 3d36bb0 Compare January 13, 2026 01:28
@joker23 joker23 requested a review from cspath1 January 13, 2026 01:31
@joker23 joker23 marked this pull request as ready for review January 13, 2026 01:38
@joker23 joker23 requested review from a team and pranjal-jately-ld as code owners January 13, 2026 01:38
@joker23 joker23 marked this pull request as draft January 14, 2026 15:08
@joker23
Copy link
Author

joker23 commented Jan 14, 2026

putting this back into draft mode until we either stabilize the js client sdk OR have a pre-release stream to merge to.

@joker23 joker23 force-pushed the skz/sdk-1565/update-browser-sdk branch 5 times, most recently from 9eef50a to 973abb4 Compare January 21, 2026 21:53
@joker23 joker23 marked this pull request as ready for review January 21, 2026 22:41
@joker23 joker23 changed the title refactor!: updating browser sdk to 4.x feat: make toolbar compatible with js client sdk v4 Jan 21, 2026
@joker23
Copy link
Author

joker23 commented Jan 21, 2026

@launchdarkly/team-fm-next this PR is ready for review... the approach here is to ensure that the toolbar is compatible with both the new and old js client sdks

*/
export interface LDClient {
track(key: string, data?: any, metricValue?: number): void;
identify(ctx: any): Promise<LDIdentifyResult> | Promise<LDFlagSet> | Promise<void>;
Copy link
Contributor

Choose a reason for hiding this comment

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

We can use the LDContext type here.

Suggested change
identify(ctx: any): Promise<LDIdentifyResult> | Promise<LDFlagSet> | Promise<void>;
identify(ctx: LDContext): Promise<LDIdentifyResult> | Promise<LDFlagSet> | Promise<void>;

Copy link
Author

@joker23 joker23 Jan 24, 2026

Choose a reason for hiding this comment

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

The problem with using LDContext directly here is that it conflicts with the type definition in launchdarkly-react-client-sdk which is very old at this point... structurally, it is hard to compat launchdarkly-react-client-sdk, launchdarkly-js-client-sdk and @launchdarkly/react-client-sdk which is why I put the compat client to accept any... we can probably still maintain type safety if we narrow the context when it is being used?

We are looking at updating the React SDK soon so it should be more compatible in the future.

I don't think this suggestion will build.

@pranjal-jately-ld
Copy link
Contributor

Thanks for doing this @joker23 🙏 It's looking good and I've left a couple of minor suggestions. I do have a couple of questions:

  1. Is launchdarkly-js-client-sdk (v3) still needed? Imports come from both packages - is this for users who haven't migrated, or transitional?
  2. Version detection follow-up: A comment above mentions using LDPluginEnvironmentMetadata for cleaner version detection. The question is whether there's a ticket to implement that cleaner approach, or if the current runtime detection is the intended solution for the time being?

@joker23
Copy link
Author

joker23 commented Jan 24, 2026

Thanks @pranjal-jately-ld for the review! To answer the questions:

Is launchdarkly-js-client-sdk (v3) still needed? Imports come from both packages - is this for users who haven't migrated, or transitional?

I think so - I did not update the internal SDK usage as js-client-sdk v4 (at the moment) is still in prerelease. We only import type definitions from @launchdarkly/js-client-sdk here and ensure that when it does release that the toolbar will be compatible

Version detection follow-up: A comment above mentions using LDPluginEnvironmentMetadata for cleaner version detection. The question is whether there's a ticket to implement that cleaner approach, or if the current runtime detection is the intended solution for the time being?

I think the current runtime detection is fine for now as the flag change event payload is an official change between the major versions (it is effectively a slimmed down implementation of type overloading). The version check requires a few changes to the toolbar implementation as the LDPluginEnvironmentMetadata is only exposed to the toolbar on register and there is no mechanism at the moment that references that implementation.

joker23 and others added 10 commits January 28, 2026 14:26
….11.0

- Replaced instances of 'launchdarkly-js-client-sdk' with '@launchdarkly/js-client-sdk' across various files.
- Updated package.json files in demo and toolbar to include the new SDK version.
- Adjusted imports in several components to align with the new SDK structure.
- Ensured compatibility with existing code by handling type mismatches where necessary.
- Changed import paths in test files to reflect the new SDK structure.
- Updated mock implementations to align with the new SDK methods.
- Ensured compatibility with existing tests by adjusting mock behavior.
- Added new compat interfaces so that toolbar could recognize browser v3 and v4 clients.
- Changed import paths to use '@launchdarkly/toolbar' and updated related types.

> Eventually we should probably provide this compat layer in the browser SDK code itself.
…ovider.tsx

Co-authored-by: pranjal-jately-ld <pjately@launchdarkly.com>
@joker23 joker23 force-pushed the skz/sdk-1565/update-browser-sdk branch from a083eb3 to 001edbb Compare January 28, 2026 20:35
@joker23 joker23 force-pushed the skz/sdk-1565/update-browser-sdk branch from d387384 to e5c5389 Compare January 28, 2026 20:49
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.

4 participants