feat: add disableFeatureFlagReload option to identify()#3295
feat: add disableFeatureFlagReload option to identify()#3295
Conversation
When identify() changes the distinct_id, the SDK automatically reloads feature flags. However, the /flags request fires before the person merge triggered by $identify has propagated server-side, causing the server to re-bucket the user under a different variant. This adds a disableFeatureFlagReload option to identify() across the browser, core, and React Native SDKs, allowing callers to suppress the automatic flag reload and let flags refresh on the next session when identities are fully merged.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 No Changeset FoundThis PR doesn't include a changeset. A changeset (and the release label) is required to release a new version. How to add a changesetRun this command and follow the prompts: pnpm changesetRemember: Never use |
|
| new_distinct_id?: string, | ||
| userPropertiesToSet?: Properties, | ||
| userPropertiesToSetOnce?: Properties, | ||
| options?: { disableFeatureFlagReload?: boolean } |
There was a problem hiding this comment.
Use
IdentifyOptions instead of inline type
The inline type { disableFeatureFlagReload?: boolean } duplicates the IdentifyOptions interface already defined in @posthog/types and re-exported from packages/browser/src/types.ts. Using the named type keeps the implementation consistent with the interface declared in packages/types/src/posthog.ts and avoids having to update two places if IdentifyOptions gains new fields.
| options?: { disableFeatureFlagReload?: boolean } | |
| options?: IdentifyOptions |
You'll also need to import IdentifyOptions at the top of this file (it's already re-exported from ./types).
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/browser/src/posthog-core.ts
Line: 2338
Comment:
**Use `IdentifyOptions` instead of inline type**
The inline type `{ disableFeatureFlagReload?: boolean }` duplicates the `IdentifyOptions` interface already defined in `@posthog/types` and re-exported from `packages/browser/src/types.ts`. Using the named type keeps the implementation consistent with the interface declared in `packages/types/src/posthog.ts` and avoids having to update two places if `IdentifyOptions` gains new fields.
```suggestion
options?: IdentifyOptions
```
You'll also need to import `IdentifyOptions` at the top of this file (it's already re-exported from `./types`).
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| if (!options?.disableFeatureFlagReload) { | ||
| this.reloadFeatureFlags() | ||
| } |
There was a problem hiding this comment.
Add inline comment explaining the suppressed reload
This is a significant behavior change — suppressing the /flags network request on identity change. An inline comment should explain why a caller might want to disable the reload here.
| if (!options?.disableFeatureFlagReload) { | |
| this.reloadFeatureFlags() | |
| } | |
| // When disableFeatureFlagReload is true, skip the early /flags | |
| // reload to avoid re-bucketing the user before the $identify | |
| // person-merge has propagated server-side. | |
| if (!options?.disableFeatureFlagReload) { | |
| this.reloadFeatureFlags() | |
| } |
Rule Used: Add inline comments to clarify the purpose of sign... (source)
Learnt From
PostHog/posthog#32083
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/browser/src/posthog-core.ts
Line: 2437-2439
Comment:
**Add inline comment explaining the suppressed reload**
This is a significant behavior change — suppressing the `/flags` network request on identity change. An inline comment should explain why a caller might want to disable the reload here.
```suggestion
// When disableFeatureFlagReload is true, skip the early /flags
// reload to avoid re-bucketing the user before the $identify
// person-merge has propagated server-side.
if (!options?.disableFeatureFlagReload) {
this.reloadFeatureFlags()
}
```
**Rule Used:** Add inline comments to clarify the purpose of sign... ([source](https://app.greptile.com/review/custom-context?memory=4d5b48c5-045d-4693-9cd9-4081bb19508b))
**Learnt From**
[PostHog/posthog#32083](https://github.com/PostHog/posthog/pull/32083)
How can I resolve this? If you propose a fix, please make it concise.| if (!options?.disableFeatureFlagReload) { | ||
| this.reloadFeatureFlags() | ||
| } |
There was a problem hiding this comment.
Add inline comment explaining the suppressed reload
Same pattern as the browser implementation — the conditional reload lacks an explanatory comment, making it harder for future readers to understand the intent without consulting the PR description.
| if (!options?.disableFeatureFlagReload) { | |
| this.reloadFeatureFlags() | |
| } | |
| // When disableFeatureFlagReload is true, skip the early /flags | |
| // reload to avoid re-bucketing the user before the $identify | |
| // person-merge has propagated server-side. | |
| if (!options?.disableFeatureFlagReload) { | |
| this.reloadFeatureFlags() | |
| } |
Rule Used: Add inline comments to clarify the purpose of sign... (source)
Learnt From
PostHog/posthog#32083
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/core/src/posthog-core.ts
Line: 336-338
Comment:
**Add inline comment explaining the suppressed reload**
Same pattern as the browser implementation — the conditional reload lacks an explanatory comment, making it harder for future readers to understand the intent without consulting the PR description.
```suggestion
// When disableFeatureFlagReload is true, skip the early /flags
// reload to avoid re-bucketing the user before the $identify
// person-merge has propagated server-side.
if (!options?.disableFeatureFlagReload) {
this.reloadFeatureFlags()
}
```
**Rule Used:** Add inline comments to clarify the purpose of sign... ([source](https://app.greptile.com/review/custom-context?memory=4d5b48c5-045d-4693-9cd9-4081bb19508b))
**Learnt From**
[PostHog/posthog#32083](https://github.com/PostHog/posthog/pull/32083)
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
|
Size Change: +587 B (+0.01%) Total Size: 6.58 MB
ℹ️ View Unchanged
|
|
On my phone now and didnt review the code yet but i remember some sdks cache person props during the identify call and reload flags with all new/cached props so the reload flags should be evaluated correctly already. |
|
Promptless prepared a documentation update related to this change. Documents the new Review at https://app.gopromptless.ai/suggestions/1db8181d-33d2-46f5-a72e-89e8f9a751e4 |
i think @dustinbyrne implemented that for a few SDKs |
|
Yeah, I'd expect this to be working already without the need to defer reload, otherwise it's a bug. Is this related to experience continuity flags or are you seeing this happen elsewhere? |
|
You're both right — I hadn't looked closely enough. The core SDK already sends Going back to the customer to investigate further. Their setup has three distinct IDs (RN SDK anonymous ID, backend-generated UUID, and Auth0 UUID) with two separate merge paths — the variant flip is likely coming from the backend evaluating flags against a different ID than the frontend during the anonymous phase, not from a client-side reload issue. Closing this. |
Summary
disableFeatureFlagReloadoption toidentify()across browser, core, and React Native SDKsidentify()changes the distinct_id, the SDK unconditionally reloads feature flags. The/flagsrequest fires before the person merge triggered by$identifyhas propagated server-side, which can cause the server to re-bucket the user under a different variant. This option lets callers suppress the automatic reload and let flags refresh on the next session when identities are fully merged.IdentifyOptionstype in@posthog/typesandPostHogIdentifyOptionsin the core packageUsage
Test plan
disableFeatureFlagReload: trueandfalse/flagsrequest when option is setsuper.identify())