posthog-js icon indicating copy to clipboard operation
posthog-js copied to clipboard

Feature: return a promise from reloadFeatureFlags

Open dbartholomae opened this issue 7 months ago • 5 comments

Hi there!

I'm running into the following problem: When a user signs in, I identify them, and feature flags might change. I didn't find a way to wait for the new feature flags to load. They are already loaded based on the non-identified user, so hasLoadedFlags will already be permanently true, so ensureFlagsLoaded and onFeatureFlags won't help either.

My current suggestion would be to return a Promise from reloadFeatureFlags. This way, I could await that promise right after I call identify.

dbartholomae avatar May 12 '25 21:05 dbartholomae

I believe we were able to do this with a callback previously, but it looks like this was removed in the more recent versions of posthog-react-native?

peterjskaltsis avatar Oct 28 '25 00:10 peterjskaltsis

@dbartholomae which SDK are you using and which version?

marandaneto avatar Nov 01 '25 07:11 marandaneto

This is in a web app, using posthog-js 1.279.0

dbartholomae avatar Nov 03 '25 15:11 dbartholomae

cc @PostHog/team-feature-flags

marandaneto avatar Nov 06 '25 09:11 marandaneto

Hello, I have encountered this issue:

  1. Call setPersonProperties(props)
  2. Call reloadFeatureFlags()
  3. Wait for the onFeatureFlags callback to fire
  4. Immediately call posthog.getFeatureFlag(flagName) => it returns an incorrect value based on the release condition
  5. Calling posthog.getFeatureFlag(flagName) again after some time → it returns the correct value

It seems that the first read after onFeatureFlags does not reflect the updated flag state.

wassim-ben-amor avatar Nov 18 '25 11:11 wassim-ben-amor