@@ -21,10 +21,8 @@ import {
2121 LDIdentifyResult ,
2222 LDPluginEnvironmentMetadata ,
2323 LDWaitForInitializationOptions ,
24- LDWaitForInitializationResult ,
2524 MODE_TABLE ,
2625 Platform ,
27- readFlagsFromBootstrap ,
2826 resolveForegroundMode ,
2927 safeRegisterDebugOverridePlugins ,
3028} from '@launchdarkly/js-client-sdk-common' ;
@@ -45,11 +43,6 @@ class BrowserClientImpl extends LDClientImpl {
4543 private readonly _goalManager ?: GoalManager ;
4644 private readonly _plugins ?: LDPlugin [ ] ;
4745
48- private _initialContext ?: LDContext ;
49-
50- // NOTE: This also keeps track of when we tried to initialize the client.
51- private _startPromise ?: Promise < LDWaitForInitializationResult > ;
52-
5346 constructor (
5447 clientSideId : string ,
5548 autoEnvAttributes : AutoEnvAttributes ,
@@ -156,6 +149,7 @@ class BrowserClientImpl extends LDClientImpl {
156149 getImplementationHooks : ( environmentMetadata : LDPluginEnvironmentMetadata ) =>
157150 internal . safeGetHooks ( logger , environmentMetadata , validatedBrowserOptions . plugins ) ,
158151 credentialType : 'clientSideId' ,
152+ requiresStart : true ,
159153 } ) ;
160154
161155 this . setEventSendingEnabled ( true , false ) ;
@@ -234,10 +228,6 @@ class BrowserClientImpl extends LDClientImpl {
234228 }
235229 }
236230
237- setInitialContext ( context : LDContext ) : void {
238- this . _initialContext = context ;
239- }
240-
241231 override async identify ( context : LDContext , identifyOptions ?: LDIdentifyOptions ) : Promise < void > {
242232 return super . identify ( context , identifyOptions ) ;
243233 }
@@ -246,79 +236,11 @@ class BrowserClientImpl extends LDClientImpl {
246236 context : LDContext ,
247237 identifyOptions ?: LDIdentifyOptions ,
248238 ) : Promise < LDIdentifyResult > {
249- if ( ! this . _startPromise ) {
250- this . logger . error (
251- 'Client must be started before it can identify a context, did you forget to call start()?' ,
252- ) ;
253- return { status : 'error' , error : new Error ( 'Identify called before start' ) } ;
254- }
255-
256- const identifyOptionsWithUpdatedDefaults = {
257- ...identifyOptions ,
258- } ;
259- if ( identifyOptions ?. sheddable === undefined ) {
260- identifyOptionsWithUpdatedDefaults . sheddable = true ;
261- }
262-
263- const res = await super . identifyResult ( context , identifyOptionsWithUpdatedDefaults ) ;
264-
239+ const res = await super . identifyResult ( context , identifyOptions ) ;
265240 this . _goalManager ?. startTracking ( ) ;
266241 return res ;
267242 }
268243
269- start ( options ?: LDStartOptions ) : Promise < LDWaitForInitializationResult > {
270- if ( this . initializeResult ) {
271- return Promise . resolve ( this . initializeResult ) ;
272- }
273- if ( this . _startPromise ) {
274- return this . _startPromise ;
275- }
276- if ( ! this . _initialContext ) {
277- this . logger . error ( 'Initial context not set' ) ;
278- return Promise . resolve ( { status : 'failed' , error : new Error ( 'Initial context not set' ) } ) ;
279- }
280-
281- // When we get to this point, we assume this is the first time that start is being
282- // attempted. This line should only be called once during the lifetime of the client.
283- const identifyOptions = {
284- ...( options ?. identifyOptions ?? { } ) ,
285-
286- // Initial identify operations are not sheddable.
287- sheddable : false ,
288- } ;
289-
290- // If the bootstrap data is provided in the start options, and the identify options do not have bootstrap data,
291- // then use the bootstrap data from the start options.
292- if ( options ?. bootstrap && ! identifyOptions . bootstrap ) {
293- identifyOptions . bootstrap = options . bootstrap ;
294- }
295-
296- if ( identifyOptions ?. bootstrap ) {
297- try {
298- if ( ! identifyOptions . bootstrapParsed ) {
299- identifyOptions . bootstrapParsed = readFlagsFromBootstrap (
300- this . logger ,
301- identifyOptions . bootstrap ,
302- ) ;
303- }
304- this . presetFlags ( identifyOptions . bootstrapParsed ! ) ;
305- } catch ( error ) {
306- this . logger . error ( 'Failed to bootstrap data' , error ) ;
307- }
308- }
309-
310- if ( ! this . initializedPromise ) {
311- this . initializedPromise = new Promise ( ( resolve ) => {
312- this . initResolve = resolve ;
313- } ) ;
314- }
315-
316- this . _startPromise = this . promiseWithTimeout ( this . initializedPromise ! , options ?. timeout ?? 5 ) ;
317-
318- this . identifyResult ( this . _initialContext ! , identifyOptions ) ;
319- return this . _startPromise ;
320- }
321-
322244 setConnectionMode ( mode ?: FDv2ConnectionMode ) : void {
323245 if ( ! this . dataManager . setConnectionMode ) {
324246 this . logger . warn (
0 commit comments