Skip to content

Commit

Permalink
fix: Web Experiment - only apply antiflicker for active experiments o…
Browse files Browse the repository at this point in the history
…n page (#155)
  • Loading branch information
tyiuhc authored Jan 16, 2025
1 parent 6c7c3ba commit 5d6f5d1
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions packages/experiment-tag/src/experiment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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');
Expand Down

0 comments on commit 5d6f5d1

Please sign in to comment.