diff --git a/lib/src/core/client/strategy/strategy.ts b/lib/src/core/client/strategy/strategy.ts index 1257ce4..a4878ce 100644 --- a/lib/src/core/client/strategy/strategy.ts +++ b/lib/src/core/client/strategy/strategy.ts @@ -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 ); diff --git a/lib/src/core/variant.ts b/lib/src/core/variant.ts index a512332..ea20f1a 100644 --- a/lib/src/core/variant.ts +++ b/lib/src/core/variant.ts @@ -62,6 +62,7 @@ function findOverride( export function selectVariantDefinition( groupId: string, + stickiness: string | undefined, variants: VariantDefinition[], context: Context ): VariantDefinition | null { @@ -74,8 +75,6 @@ export function selectVariantDefinition( return variantOverride; } - const { stickiness } = variants[0]; - const target = normalizedValue( getSeed(context, stickiness), groupId, @@ -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); }