@@ -82,12 +82,18 @@ export interface IClientConfig {
82
82
83
83
export { IAssignmentLogger , IAssignmentEvent , IEppoClient } from '@eppo/js-client-sdk-common' ;
84
84
85
+ // Instantiate the configuration store with memory-only implementation.
86
+ const configurationStore = configurationStorageFactory ( undefined , true ) ;
87
+
85
88
/**
86
89
* Client for assigning experiment variations.
87
90
* @public
88
91
*/
89
92
export class EppoJSClient extends EppoClient {
90
- public static instance : EppoJSClient ;
93
+ // Ensure that the client is instantiated during class loading.
94
+ // Use an empty memory-only configuration store until the `init` method is called,
95
+ // to avoid serving stale data to the user.
96
+ public static instance : EppoJSClient = new EppoJSClient ( configurationStore , undefined , true ) ;
91
97
public static initialized = false ;
92
98
93
99
public getStringAssignment (
@@ -161,8 +167,10 @@ export async function init(config: IClientConfig): Promise<IEppoClient> {
161
167
EppoJSClient . instance . stopPolling ( ) ;
162
168
}
163
169
164
- const configurationStore = configurationStorageFactory ( config . persistentStore ) ;
165
- EppoJSClient . instance = new EppoJSClient ( configurationStore , undefined , true ) ;
170
+ // Set the configuration store to the desired persistent store, if provided.
171
+ // Otherwise the factory method will detect the current environment and instantiate the correct store.
172
+ const configurationStore = configurationStorageFactory ( config . persistentStore , false ) ;
173
+ EppoJSClient . instance . setConfigurationStore ( configurationStore ) ;
166
174
167
175
const requestConfiguration : FlagConfigurationRequestParameters = {
168
176
apiKey : config . apiKey ,
0 commit comments