Skip to content

Commit

Permalink
fix: variant stickiness
Browse files Browse the repository at this point in the history
  • Loading branch information
Tymek committed Mar 25, 2024
1 parent d1a3ff2 commit 7e98a67
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/src/core/client/strategy/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,10 @@ export class Strategy {
);

if (enabled && Array.isArray(variants) && variants.length > 0) {
const stickiness = variants[0].stickiness || parameters.stickiness;
const variantDefinition = selectVariantDefinition(
parameters.groupId,
stickiness,
variants,
context
);
Expand Down
6 changes: 3 additions & 3 deletions lib/src/core/variant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function findOverride(

export function selectVariantDefinition(
groupId: string,
stickiness: string | undefined,
variants: VariantDefinition[],
context: Context
): VariantDefinition | null {
Expand All @@ -74,8 +75,6 @@ export function selectVariantDefinition(
return variantOverride;
}

const { stickiness } = variants[0];

const target = normalizedValue(
getSeed(context, stickiness),
groupId,
Expand Down Expand Up @@ -103,5 +102,6 @@ export function selectVariant(
feature: FeatureInterface,
context: Context
): VariantDefinition | null {
return selectVariantDefinition(feature.name, feature.variants || [], context);
const stickiness = feature.variants?.[0]?.stickiness ?? undefined;
return selectVariantDefinition(feature.name, stickiness, feature.variants || [], context);
}

0 comments on commit 7e98a67

Please sign in to comment.