-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useFeatureFlagEnabled returns an incorrect value when flag is enabled #1714
Comments
Hi @mwickman , thanks for the report. I am digging into this, in the meantime could you also provide a snippet where you use |
Thanks for the code @mwickman ! Quick follow-up, are you able to tell if your hook is returning I am looking into a similar report from another PostHog user and we've realized that the lack of a default value (due to compatibility w/ NextJS) causes hooks to return Let me know if you agree that this is the same root cause / symptom or something else - I'm already working on addressing that specific issue so hopefully I can help you both out with the same code change! |
Thanks so much Haven! In my case I do not see the issue on first render, but after a number of renders have already occurred and the user has signed out, where we call posthog.reset(). I would actually like to get back I suspect my problem is related to the posthog.reset() that we do when signing out. The flow is roughly like this:
|
Ah, yes the IMO, this is actually intended behavior. Typically, bootstrapped values are passed from a server-side call which would be user-specific. So, we wouldn't want this SDK to re-populate old bootstrapped values as they could be completely wrong for the newly logged out user. For now, if you need bootstrap values to persist after a logout, I'd recommend either re-initializing the SDK with your bootstrap values after the signout, or if you want to permanent overrides, you can just use |
So you are saying that if I have a feature flag set to True in posthog, then call reset(), its expected that I'll no longer get my feature flag values back correctly from that point? That is what I'm experiencing; after the reset() call a flag which should be enabled for all users is returning false. What should I call to have the flags start getting returned correctly again? Thanks again for the help! |
Hi, thank you for your hard work on this library!
I'm using posthog-js and posthog-js/react, version ^1.215.1
I have a feature flag which is enabled, and sometimes useFeatureFlagEnabled returns false when the value of my flag has never been set to false. This is easy to recreate when I log the user out.
Typescript indicates that useFeatureFlagEnabled can return a boolean or undefined, and it seems logical to me it would return undefined instead of false if it has not yet fetched a value. However in the network tools I can see that I've fetched from /decide multiple times and each time the only value returned was
true
, but the hook still gavefalse
.Perhaps I just need clarification that we should never expect to get back undefined, and that false will be returned if posthog has failed to fetch flags, but I struggled to find any documentation about this. Otherwise it appears to be a bug that posthog would return a value it never received from its server.
update: I've tried to solve the problem by bootstrapping the flag values but still see

false
returned when it seems like there should be no scenarios left where that is a possible return value.Thank you,
Matt
The text was updated successfully, but these errors were encountered: