feat: surface multivariate variant key and use it as the exposure value#401
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
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.
…ant keys as absent
Thanks for submitting a PR! Please check the boxes below:
docs/if required so people know about the feature.Changes
IFlagsmithFeature.variant— selected variant's key,"control"for the control bucket, omitted otherwise.getExperimentFlagrecords the variant as the$flag_exposurevalue; flags without a variant record no exposure.useExperimentre-fires the exposure when the variant changes.How did you test this code?
Unit tests: variant parsing, exposure values, variant-change re-exposure