Open bjfresh opened 20 hours ago
@bjfresh hello, thanks for the issue.
// Fetch the user's feature flags from the server so we can bootstrap the PostHog client // This helps ensure that the PostHog client is ready to go with accurate flag data when we need it // Without this, the data may not be ready in time for the first feature flag check and the flag may be inaccurate
If you need fresh flags, you can just use reloadFeatureFlagsAsync and await the promise to be resolved, this is better with preloadFeatureFlags: false
so you don't reload a 2nd time.
This is also only an issue for the very first time the SDK is installed and the app is opened, after the 1st successful flags have been pulled, the SDK caches in the disk and it will use the cached values on the next app restart in case the request to get new flags again is still in process or failed.
If you still want to do bootstrapping, here it is explained, and here it shows that you need to init the SDK with the bootstrap
and featureFlags
object.
I don't see the bootstrap
values in your code snippet, so I am unsure this would work, also if you'd need feature flags with payloads, you'd need to bootstrap using the featureFlagPayloads
value as well.
The bootstrap values are overwritten once the client requests and receives the fresh flags. The flags will only be the same if the client is also using the same distinctId, so you also have to bootstrap with distinctId.
Since I don't have access to your code nor I can see how initializePostHogClient
is created.
Can you provide a MRE so we can try and reproduce the issue? please remove all the logic that is not needed, the less the better, just a way to show off the problem.
Thanks.
Bug description
Data discrepancy between bootstrapped data and front-end data
How to reproduce
On server:
Bootstrap + init React Native client:
Client-side query for getFeatureFlag:
Before fetching, logic confirms:
Both server-side and client-side clients are instantiated with profileTBA as distinctId.
So the data should be identical, but we're seeing results where the value differs. In effect, we bootstrap the client with the correct data, and then on refetch it makes the data incorrect. This is for an isAdmin flag attached to a cohort, so it's important as protection.
Related sub-libraries
Thanks in advance for any assistance.