@@ -18,6 +18,7 @@ import {
1818 Platform ,
1919} from '@launchdarkly/js-client-sdk-common' ;
2020
21+ import { readFlagsFromBootstrap } from './bootstrap' ;
2122import { getHref } from './BrowserApi' ;
2223import BrowserDataManager from './BrowserDataManager' ;
2324import { BrowserIdentifyOptions as LDIdentifyOptions } from './BrowserIdentifyOptions' ;
@@ -32,6 +33,7 @@ import BrowserPlatform from './platform/BrowserPlatform';
3233class BrowserClientImpl extends LDClientImpl {
3334 private readonly _goalManager ?: GoalManager ;
3435 private readonly _plugins ?: LDPlugin [ ] ;
36+ private _bootstrapAttempted = false ;
3537
3638 constructor (
3739 clientSideId : string ,
@@ -197,6 +199,12 @@ class BrowserClientImpl extends LDClientImpl {
197199 ) ;
198200 }
199201
202+ /**
203+ * @ignore
204+ * NOTE: this identify is not doing anything as the `makeClient` function maps the
205+ * identify function to identifyResults. We will need to consolidate this function
206+ * in the js-client-sdk-common package.
207+ */
200208 override async identify ( context : LDContext , identifyOptions ?: LDIdentifyOptions ) : Promise < void > {
201209 return super . identify ( context , identifyOptions ) ;
202210 }
@@ -211,6 +219,21 @@ class BrowserClientImpl extends LDClientImpl {
211219 if ( identifyOptions ?. sheddable === undefined ) {
212220 identifyOptionsWithUpdatedDefaults . sheddable = true ;
213221 }
222+
223+ if ( ! this . _bootstrapAttempted && identifyOptionsWithUpdatedDefaults . bootstrap ) {
224+ try {
225+ const bootstrapData = readFlagsFromBootstrap (
226+ this . logger ,
227+ identifyOptionsWithUpdatedDefaults . bootstrap ,
228+ ) ;
229+ this . setBootstrap ( context , bootstrapData ) ;
230+ } catch ( e ) {
231+ this . logger . error ( 'failed to bootstrap data' ) ;
232+ } finally {
233+ this . _bootstrapAttempted = true ;
234+ }
235+ }
236+
214237 const res = await super . identifyResult ( context , identifyOptionsWithUpdatedDefaults ) ;
215238 this . _goalManager ?. startTracking ( ) ;
216239 return res ;
0 commit comments