Closed neilkakkar closed 3 months ago
@neilkakkar the v3 SDK does not have the initAsync
anymore, so the issue "there was no way to tell whether PostHog had initialized" does not apply anymore.
https://posthog.com/docs/libraries/react-native#example-1-boolean-feature-flags
useFeatureFlag
will only return undefined
for the very first time since the flags will be cached after loading and later always return the values from the cache.
Another option is reloading flags and await
or then
for it https://posthog.com/docs/libraries/react-native#reloading-flags.
The last option is to disable preloadFeatureFlags
and again reload feature flags and await
or then
manually, so the feature flags will never return undefined unless the request fails or something, does that help?
@neilkakkar did you figure this issue? the ticket is still open
closed the ticket, thanks, hasn't come up there again. I haven't tried implementing myself, but I think there was a 2nd ticket they created where this conversation happened. Think we can close this until it comes up again
Bug description
From a customer:
When using the usePosthog hook there was no way to tell whether PostHog had initialized and was ready for us to ask about the feature flag variant, we when our app started up we were getting undefined for the feature flags, so we were falling back to the app’s locally set default variant (“control”). Then when the user created their account ( and logged in) it would cause a refresh of feature flags, which could kick them into the other variant (“v2").
We’ve just released a new build of the app that does PostHog.initAsync with preloadFeatureFlags: true and then awaits postHogClient.reloadFeatureFlagsAsync(). We delay rendering our welcome screen until that completes and manually pass the returned values into the PostHogProvider.
This is leading to annoying developer experience for flags - when its ideally something we should handle ourselves. Investigate what has changed here, and if we need to update the code / usage snippets to follow a pattern that works seamlessly.
Related sub-libraries
Additional context
See https://posthoghelp.zendesk.com/agent/tickets/12490
Thank you for your bug report – we love squashing them!