Skip to content

feat: adding start() method to common client sdk package#1244

Open
joker23 wants to merge 2 commits intomainfrom
skz/sdk-1759/client-start
Open

feat: adding start() method to common client sdk package#1244
joker23 wants to merge 2 commits intomainfrom
skz/sdk-1759/client-start

Conversation

@joker23
Copy link
Copy Markdown
Contributor

@joker23 joker23 commented Apr 3, 2026

This PR will consolidate the start() method into the shared client sdk package.

To do this we also:

  • introduce an internal option called requiresStart which should be true for new SDKs (and only RN has it default false)
  • requiresStart is, effectively, a feature flag for whether the SDK is using the new create + start initialization pattern
  • consolidated the unit tests for the start method into client common
  • moved start method out of browser and electron sdks

Note

Medium Risk
Centralizes client initialization and adds a new requiresStart gate that changes when identify is allowed, affecting startup/bootstrapping behavior across browser and electron SDKs. Moderate risk due to changes in core init/identify flow and promise/timeout handling, though covered by new shared unit tests.

Overview
Consolidates start() into the shared LDClientImpl so browser/electron no longer maintain their own initialization logic; start() is now idempotent, caches its promise/result, and supports bootstrap flag presetting (including reason data) from either top-level bootstrap or identifyOptions.bootstrap.

Adds an internal requiresStart option (enabled for browser and electron) that blocks identify() calls before start() and, when enabled, defaults post-start identify calls to sheddable: true unless explicitly set.

Updates browser/electron SDKs to wire requiresStart, use setInitialContext, and trims/adjusts SDK-specific tests; a new shared test suite (LDClientImpl.start.test.ts) covers start()/bootstrap behavior, the requiresStart guard, and waitForInitialization integration.

Reviewed by Cursor Bugbot for commit 66673ed. Bugbot is set up for automated code reviews on this repo. Configure here.


Open with Devin

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

@launchdarkly/js-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 25661 bytes
Compressed size limit: 29000
Uncompressed size: 126143 bytes

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

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

@joker23 joker23 force-pushed the skz/sdk-1759/client-start branch from 1a440b9 to d249ad8 Compare April 3, 2026 23:36
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

@launchdarkly/js-client-sdk size report
This is the brotli compressed size of the ESM build.
Compressed size: 31726 bytes
Compressed size limit: 34000
Uncompressed size: 113012 bytes

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

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

@joker23
Copy link
Copy Markdown
Contributor Author

joker23 commented Apr 3, 2026

@cursor review

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit d249ad8. Configure here.

@joker23 joker23 force-pushed the skz/sdk-1759/client-start branch from d249ad8 to 8f1e564 Compare April 6, 2026 18:54
@joker23 joker23 marked this pull request as ready for review April 6, 2026 19:25
@joker23 joker23 requested a review from a team as a code owner April 6, 2026 19:25
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.

mostly moving all of the start tests to common

* When true, the SDK requires `start()` to be called before `identify()`.
* Set this value to `true` to use the new initialization pattern.
*/
requiresStart?: boolean;
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.

added this to compat react native... this was the only way I found that would leave RN alone

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 5 additional findings.

Open in Devin Review

@joker23 joker23 force-pushed the skz/sdk-1759/client-start branch from 8f1e564 to 111c7e2 Compare April 7, 2026 15:26
cursor[bot]

This comment was marked as resolved.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't know that I like changes to this file simultaneous to the change. From a validation perspective I would prefer this be unchanged. And then potentially these be de-duplicated. That said I am not certain they really should be de-duplicated.

const noTimeout = identifyOptions?.timeout === undefined && identifyOptions?.noTimeout === true;
if (this._requiresStart && !this.startPromise) {
this.logger.error(
'Client must be started before it can identify a context, did you forget to call start()?',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would prefer something that didn't contain 'forget'.

Suggested change
'Client must be started before it can identify a context, did you forget to call start()?',
'The client must be started before a context can be identified. Call start() prior to identifying a context.',

Or maybe something like:

The client has not been started. Please call start() before identifying subsequent contexts.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Though something simpler than "subsequent" might be better.

I'm basically after 2 things:

  1. Don't assume/imply they knew the correct operation.
  2. If possible be clear that identify isn't for the first context. Only when changing contexts is required.

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