perf(editor): Skip client-side PostHog flag refetch when flags are bootstrapped (no-changelog) (#34805)

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Romeo Balta <7095569+romeobalta@users.noreply.github.com>
This commit is contained in:
leonardofficial 2026-08-05 10:38:40 +02:00 committed by GitHub
parent f6663940ed
commit 0e8ff31d27
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 0 deletions

View File

@ -79,6 +79,7 @@ declare global {
api_host?: string;
autocapture?: boolean;
disable_session_recording?: boolean;
advanced_disable_feature_flags?: boolean;
debug?: boolean;
bootstrap?: {
distinctID?: string;

View File

@ -164,6 +164,30 @@ describe('Posthog store', () => {
);
});
it('disables client-side flag refetch when flags are bootstrapped', () => {
const posthog = usePostHog();
posthog.init({ test: 'variant' });
expect(window.posthog?.init).toHaveBeenCalledWith(
DEFAULT_POSTHOG_SETTINGS.apiKey,
expect.objectContaining({
advanced_disable_feature_flags: true,
}),
);
});
it('keeps client-side flag refetch when flags are not bootstrapped', () => {
const posthog = usePostHog();
posthog.init();
expect(window.posthog?.init).toHaveBeenCalledWith(
DEFAULT_POSTHOG_SETTINGS.apiKey,
expect.not.objectContaining({
advanced_disable_feature_flags: expect.anything(),
}),
);
});
it('should identify user', () => {
const posthog = usePostHog();
posthog.init();

View File

@ -189,6 +189,10 @@ export const usePostHog = defineStore('posthog', () => {
distinctID: distinctId,
featureFlags: evaluatedFeatureFlags,
};
// Flags are server-evaluated and bootstrapped; without this, identify()/group()
// in the loaded callback each trigger a billed /flags refetch of values the
// client already has.
options.advanced_disable_feature_flags = true;
}
window.posthog?.init(config.apiKey, {