Skip to content

feat: surface multivariate variant key and use it as the exposure value#401

Merged
Zaimwa9 merged 3 commits into
feat/event-processorfrom
feat/implement-variant-key
Jun 15, 2026
Merged

feat: surface multivariate variant key and use it as the exposure value#401
Zaimwa9 merged 3 commits into
feat/event-processorfrom
feat/implement-variant-key

Conversation

@Zaimwa9

@Zaimwa9 Zaimwa9 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Thanks for submitting a PR! Please check the boxes below:

  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

  • IFlagsmithFeature.variant — selected variant's key, "control" for the control bucket, omitted otherwise.
  • getExperimentFlag records the variant as the $flag_exposure value; flags without a variant record no exposure.
  • useExperiment re-fires the exposure when the variant changes.

How did you test this code?

Unit tests: variant parsing, exposure values, variant-change re-exposure

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Zaimwa9 Zaimwa9 requested a review from gagantrivedi June 10, 2026 16:03
@Zaimwa9 Zaimwa9 requested a review from a team as a code owner June 10, 2026 16:04
@Zaimwa9 Zaimwa9 requested review from kyle-ssg and removed request for a team June 10, 2026 16:04
@Zaimwa9 Zaimwa9 removed the request for review from kyle-ssg June 10, 2026 16:04
@Zaimwa9 Zaimwa9 marked this pull request as draft June 10, 2026 16:04

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for multivariate flag variants in the Flagsmith SDK. It updates the core SDK to extract and store the variant property on flags, uses the variant value instead of the flag value for experiment exposure tracking, and updates the React hooks (useFlags, useExperiment) to handle and trigger re-renders on variant changes. Additionally, types and tests are updated to support this new feature. Feedback from the review highlights two main areas of improvement: first, in flagsmith-core.ts, if a flag is missing (null), the current logic logs a misleading warning about a missing variant, so it is recommended to check if the flag exists before checking for its variant; second, in react.tsx, the use of .map() to mutate an object is an anti-pattern and should be refactored to use .forEach() for better clarity and performance.

Comment thread flagsmith-core.ts Outdated
Comment thread react.tsx
@Zaimwa9 Zaimwa9 marked this pull request as ready for review June 11, 2026 09:23
@Zaimwa9 Zaimwa9 merged commit 5b9e2d8 into feat/event-processor Jun 15, 2026
1 check passed
@Zaimwa9 Zaimwa9 deleted the feat/implement-variant-key branch June 15, 2026 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants