mirror of
https://github.com/n8n-io/n8n.git
synced 2026-10-19 16:55:02 +02:00
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:
parent
f6663940ed
commit
0e8ff31d27
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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, {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user