-
Notifications
You must be signed in to change notification settings - Fork 39
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
Data discrepancy between bootstrapped data and front-end data #314
Comments
@bjfresh hello, thanks for the issue.
If you need fresh flags, you can just use reloadFeatureFlagsAsync and await the promise to be resolved, this is better with If you still want to do bootstrapping, here it is explained, and here it shows that you need to init the SDK with the The bootstrap values are overwritten once the client requests and receives the fresh flags. Since I don't have access to your code nor I can see how Thanks. |
Ah, whoops, meant to include initializePostHog. We are indeed bootstrapping with distinctId: import { POSTHOG_HOST_SERVER, POSTHOG_API_KEY } from "@/constants"
import PostHog from "posthog-react-native"
import { getAddress } from "viem"
export async function initializePostHogClient({
profileTBA,
username,
featureFlags,
}: {
profileTBA: `0x${string}`
username?: string
featureFlags?: Record<string, string | boolean>
}) {
const uniqueIdentifier = getAddress(profileTBA)
const customIdentifiers = {
profileTBA: uniqueIdentifier,
username,
}
// Initialize the PostHog client with bootstrap options
const initPostHog = async () => {
const postHogClient = new PostHog(POSTHOG_API_KEY as string, {
host: POSTHOG_HOST_SERVER,
disabled: __DEV__,
bootstrap: {
distinctId: uniqueIdentifier,
isIdentifiedId: true,
featureFlags,
},
})
await postHogClient.ready()
// console.log({ distinctID: postHogClient.getDistinctId() })
return postHogClient
}
const postHogClient = await initPostHog()
// Only identify once we've confirmed the client is ready
postHogClient.identify(uniqueIdentifier, customIdentifiers)
return postHogClient
} and all of the flag data is as expected before re-fetching. Before refetch in const isEnabledQuery = useQuery({
queryKey: ["posthog", "getFeatureFlag", key, profileTBA],
queryFn: () => {
console.log({
// isFeatureEnabled: PostHogClient?.isFeatureEnabled(key),
distinctId: PostHogClient?.getDistinctId(),
getFeatureFlag: PostHogClient?.getFeatureFlag(key),
})
return Boolean(
PostHogClient?.onFeatureFlags(
() => PostHogClient?.getFeatureFlag(key) ?? false,
),
)
},
enabled: shouldFetch,
staleTime: 0,
}) I'm also seeing that I get different values based on whether |
sorry for the delay, the sample has a bunch of conditions, and using bootstrap flags, it's hard to understand what is going on by just reading the code. |
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.
The text was updated successfully, but these errors were encountered: