From b851dd6ff2059fecc76c39b5cee4cc5006f47a6d Mon Sep 17 00:00:00 2001 From: tyiuhc Date: Wed, 15 Jan 2025 13:25:20 -0800 Subject: [PATCH] fix: Web Experiment - only apply antiflicker for active experiments on page --- packages/experiment-tag/src/experiment.ts | 25 +++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/packages/experiment-tag/src/experiment.ts b/packages/experiment-tag/src/experiment.ts index 6a1bcfe..c622e56 100644 --- a/packages/experiment-tag/src/experiment.ts +++ b/packages/experiment-tag/src/experiment.ts @@ -131,14 +131,6 @@ export const initializeExperiment = async ( // allow local evaluation for remote flags metadata.evaluationMode = 'local'; - - // Check if any remote flags are blocking - if (!isRemoteBlocking && metadata.blockingEvaluation) { - isRemoteBlocking = true; - - // Apply anti-flicker CSS to prevent UI flicker - applyAntiFlickerCss(); - } } else { // Add locally evaluable flags to the local flag set localFlagKeys.add(key); @@ -162,6 +154,23 @@ export const initializeExperiment = async ( ...config, }); + // evaluate variants for page targeting + const variants: Variants = globalScope.webExperiment.all(); + + for (const [key, variant] of Object.entries(variants)) { + // only apply antiflicker for remote flags active on the page + if ( + remoteFlagKeys.has(key) && + variant.metadata?.blockingEvaluation && + variant.metadata?.segmentName !== 'Page not targeted' && + variant.metadata?.segmentName !== 'Page is excluded' + ) { + isRemoteBlocking = true; + // Apply anti-flicker CSS to prevent UI flicker + applyAntiFlickerCss(); + } + } + // If no integration has been set, use an amplitude integration. if (!globalScope.experimentIntegration) { const connector = AnalyticsConnector.getInstance('$default_instance');