Skip to content

V9.0.0-beta.3 cannot get string value form key #5030

@harrytran998

Description

@harrytran998

[REQUIRED] Describe your environment

  • Operating System version: MacOs 11.2.3
  • Browser version: 91.0.4472.101
  • Firebase SDK version: ^9.0.0-beta.3
  • Firebase Product: remote-config

[REQUIRED] Describe the problem

Steps to reproduce:

I initialized and fetched data the firebase app successfully with RemoteConfig instance had _storageCache and activeConfig. In IndexedDB of Chrome --> Have values of that.

But when I try to access the value like use getString() or getAll() like the code bellow, the RemoteConfigService always returns like default value ... Hope anyone can help me.

Relevant Code:

import * as firebase from 'firebase/app';
import type { RemoteConfig } from 'firebase/remote-config';
import { fetchAndActivate, getRemoteConfig, getString } from 'firebase/remote-config';

export class RemoteConfigService {
  private instance: RemoteConfig;

  constructor(firebaseConfig: FirebaseConfigEnv) {
    firebase.initializeApp(firebaseConfig);
    const remoteConfig = getRemoteConfig(firebase.getApp());

    remoteConfig.settings.fetchTimeoutMillis = 5000;
    if (process.env.NODE_ENV === 'development') {
      // The default value of 12 hours
      // Firebase suggest 12h in production because avoid to hit the free quota limit
      remoteConfig.settings.minimumFetchIntervalMillis = 36000;
    }

    if (remoteConfig.lastFetchStatus === 'no-fetch-yet') {
      remoteConfig.defaultConfig = FirebaseDefaultConfig;
    }

    this.instance = remoteConfig;
  }

  public async fetchAndActiveConfig() {
    try {
      await fetchAndActivate(this.instance);
    } catch {
      console.log('Unable to fetch remote config. Cached or default values will be used');
    }
  }

  protected getRemoteConfigStringByKey(key: string) {
    const result = getString(this.instance, key);
    return result;
  }

  public getSonmthings() {
    console.log(this.instance);
    const xxx = this.getRemoteConfigStringByKey('somethings');
    return JSON.parse(xxx);
  }

}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions