From 7e98a67c2251a21918020f89dc8e53f93d04737f Mon Sep 17 00:00:00 2001 From: Tymoteusz Czech <2625371+Tymek@users.noreply.github.com> Date: Mon, 25 Mar 2024 18:36:43 +0100 Subject: [PATCH] fix: variant stickiness --- lib/src/core/client/strategy/strategy.ts | 2 ++ lib/src/core/variant.ts | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) 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); }