@@ -54,7 +54,23 @@ export function getRemoteConfig(app: FirebaseApp = getApp(), options: RemoteConf
5454 throw ERROR_FACTORY . create ( ErrorCode . ALREADY_INITIALIZED ) ;
5555 }
5656 rcProvider . initialize ( { options } ) ;
57- return rcProvider . getImmediate ( ) ;
57+ const rc = rcProvider . getImmediate ( ) as RemoteConfigImpl ;
58+
59+ if ( options . initialFetchResponse ) {
60+ //
61+ rc . _initializePromise = Promise . all ( [
62+ rc . _storage . setLastSuccessfulFetchResponse ( options . initialFetchResponse ) ,
63+ rc . _storage . setActiveConfigEtag ( options . initialFetchResponse ?. eTag || '' ) ,
64+ rc . _storageCache . setLastSuccessfulFetchTimestampMillis ( Date . now ( ) ) ,
65+ rc . _storageCache . setLastFetchStatus ( 'success' ) ,
66+ rc . _storageCache . setActiveConfig ( options . initialFetchResponse ?. config || { } )
67+ ] ) . then ( ) ;
68+ // The storageCache methods above set their in-memory fields sycnhronously, so it's
69+ // safe to declare our initialization complete at this point.
70+ rc . _isInitializationComplete = true ;
71+ }
72+
73+ return rc ;
5874}
5975
6076/**
@@ -153,24 +169,6 @@ export async function fetchConfig(remoteConfig: RemoteConfig): Promise<void> {
153169 }
154170}
155171
156- /**
157- * Manually hydrates the config state without making an async fetch request.
158- * @param remoteConfig - The {@link RemoteConfig} instance.
159- * @param fetchResponse - The fetchResponse containing the config values and eTag
160- * with which to hydrate the internal state.
161- */
162- export async function setConfigState ( remoteConfig : RemoteConfig , fetchResponse : FetchResponse ) {
163- const rc = getModularInstance ( remoteConfig ) as RemoteConfigImpl ;
164- await Promise . all ( [
165- rc . _storage . setLastSuccessfulFetchResponse ( fetchResponse ) ,
166- rc . _storageCache . setLastSuccessfulFetchTimestampMillis ( Date . now ( ) ) ,
167- rc . _storageCache . setLastFetchStatus ( 'success' ) ,
168- // TODO - maybe we just call activate() here?
169- rc . _storage . setActiveConfigEtag ( fetchResponse . eTag || '' ) ,
170- rc . _storageCache . setActiveConfig ( fetchResponse . config || { } ) ,
171- ] ) ;
172- }
173-
174172/**
175173 * Gets all config.
176174 *
0 commit comments