Hi everyone I have been facing an issue in js sdk ...
# ask-questions
f
Hi everyone I have been facing an issue in js sdk and reaching out for help Issue: On updating a feature flag value, getting those values after couple of app session Details: I'm using the feature flag feature of GB in a react native application Currently I don't want to auto refresh the features in a single app session, so while initialising the sdk, I'm passing auto refresh as false and because of that no subscribedInstances are created. The issue is that when I fetch feature,
onNewFeatureData
is called and it sets the newly fetched features only when you have any
subscribedInstances
. Since I don't have any subscribed instances, the values are not set in the same app session but only updates the cache.
Copy code
function onNewFeatureData(
  key: string,
  cacheKey: string,
  data: FeatureApiResponse
): void {
  ......
  updatePersistentCache();

  // Update features for all subscribed GrowthBook instances
  const instances = subscribedInstances.get(key);
  instances && instances.forEach((instance) => refreshInstance(instance, data));
}
Proposed solution: a straight forward solution would be to add a condition to check if auto refresh is enabled or not
Copy code
if (instances) {
		//Update features for all subscribed GrowthBook instances
	  instances.forEach((instance) => setFeaturesOnInstance(instance, data));
	} else {
	  instance && data && setFeaturesOnInstance(instance, data);
	}
I wanted the understand the implications of these changes and is there any other way to solve this issue TIA!
h
Just wondering how you're going about refreshing your features. The instance should be updated each time you call
loadFeatures()
. The proposed fix would not work for cases when multiple SDKs are implemented in the same environment. Not all
instances
are keyed to the same api host and key.
f
So on every app launch I'm initialising hoist and loading features. So the instance would update once in an app session. What would be the usecase for implementing multiple SDks?
h
I'm still not sure what the problem might be here. Wondering if it could be React Native specific that might affect SDK lifecycle or cached feature responses. You might try using
configureCache()
and setting a
maxAge
equal to (or less than!) your
staleTTL
. Multiple SDKs per app instance - there are a few use cases: • You might have 2 different SDK keys associated with different projects that need to be loaded at the same time • You might be running the SDK on a NodeJS server which needs to keep many independent user states per each incoming request/response