Skip to content

Conversation

@joker23
Copy link
Contributor

@joker23 joker23 commented Dec 19, 2025

  • removes the browser compat dependency on svelte sdk

sdk-1703
sdk-1691


Note

Switches the Svelte SDK to the v4 browser API, replacing compat initialize with createClient/start, using the initialized event, and updating types/tests.

  • Svelte SDK client (packages/sdk/svelte/src/lib/client/SvelteLDClient.ts):
    • Replace compat import with @launchdarkly/js-client-sdk and use createClient + start().
    • Listen for initialized (was ready) and change events to manage loading and flags.
    • initialize(clientId, context, options?) now accepts LDOptions and returns { initializing }.
    • Rename factory from createLD to init; export LD = init().
    • Type updates: use LDFlagSet, LDFlagValue, LDContext, LDOptions from core SDK.
  • Tests (packages/sdk/svelte/__tests__/lib/client/SvelteLDClient.test.ts):
    • Mock @launchdarkly/js-client-sdk and createClient; expect createClient(clientId, context, undefined) and initialized event.
    • Add start to mock client; update assertions for event name changes and behavior.

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

@joker23 joker23 requested a review from a team as a code owner December 19, 2025 16:30
@github-actions
Copy link
Contributor

@launchdarkly/browser size report
This is the brotli compressed size of the ESM build.
Compressed size: 169118 bytes
Compressed size limit: 200000
Uncompressed size: 789399 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

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

@github-actions
Copy link
Contributor

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

coreLdClient!.on('ready', () => {
function initialize(clientId: LDClientID, context: LDContext, options?: LDOptions) {
coreLdClient = createClientSdk(clientId, context, options);
coreLdClient.on('initialized', () => {
Copy link

Choose a reason for hiding this comment

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

Bug: Initialization failure leaves loading state stuck forever

The migration from the compat SDK's 'ready' event to the non-compat SDK's 'initialized' event changes error handling behavior. In the compat SDK, 'ready' always fires regardless of success or failure. In the non-compat SDK, 'initialized' only fires on successful initialization. If initialization fails (network issues, invalid credentials, etc.), the loading store will never be set to false, leaving the initializing state permanently true. This could cause UI components to remain in a loading state indefinitely. The code needs to also handle the 'error' event or use an alternative approach to detect when initialization completes regardless of outcome.

Fix in Cursor Fix in Web

});

coreLdClient.start();

Copy link

Choose a reason for hiding this comment

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

Bug: identify method return type changed breaking existing code

The migration changes the return type of the identify function. The compat SDK's identify method returned Promise<LDFlagSet> (the actual flag values), while the non-compat SDK's identify returns Promise<LDIdentifyResult> (a status object like { status: 'completed' }). Any existing code that relied on the return value of LD.identify() to access flag values will now silently receive a status object instead, causing undefined values when accessing flag keys.

Fix in Cursor Fix in Web

- removes the browser compat dependency on svelte sdk
@joker23 joker23 force-pushed the skz/sdk-1703/svelte-sdk-dep branch from b3c84c1 to bcde547 Compare December 19, 2025 16:44

beforeEach(() => {
// mocks the initialize function to return the mockLDClient
(initialize as Mock<typeof initialize>).mockReturnValue(
Copy link

Choose a reason for hiding this comment

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

Bug: Test emits wrong event after API migration

The migration from the compat API to browser 4.x changed the initialization event from 'ready' to 'initialized', but one test case was missed. Line 134 still emits mockLDEventEmitter.emit('ready') while the implementation now listens for 'initialized'. This causes the test to not properly trigger the initialization callback, though it may pass coincidentally due to state leaking from other tests that correctly emit 'initialized'.

Fix in Cursor Fix in Web

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.

2 participants