Skip to content

Commit

Permalink
fix: variant stickiness (#70)
Browse files Browse the repository at this point in the history
* fix: variant stickiness
* chore: update client specification
  • Loading branch information
Tymek authored Mar 26, 2024
1 parent d1a3ff2 commit 4f03289
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@types/react": "18.2.63",
"@types/react-dom": "18.2.19",
"@types/semver": "7.5.8",
"@unleash/client-specification": "5.1.0",
"@unleash/client-specification": "5.1.4",
"@vitest/coverage-v8": "^1.3.1",
"eslint-config-custom": "workspace:*",
"next": "14.1.2",
Expand Down
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);
}
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4f03289

Please sign in to comment.