fix: store context parameter in initialize for segment evaluation #41
Merged
dylanlerch merged 2 commits intomainfrom Mar 4, 2026
Merged
fix: store context parameter in initialize for segment evaluation #41dylanlerch merged 2 commits intomainfrom
dylanlerch merged 2 commits intomainfrom
Conversation
initialize() ignored the context parameter passed by the OpenFeature SDK, causing segment-based toggles to fall back to their default value on initial load. This created a race condition where flag evaluations between provider READY and a separate setContext call would fail segment matching.
dylanlerch
requested changes
Feb 25, 2026
dylanlerch
approved these changes
Mar 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
We identified a race condition during between
setProviderAndWaitandsetContextfor segment-based targeting.The race condition happened like this:
await OpenFeature.setProviderAndWait(provider)- provider becomes READY,this.contextis{}await OpenFeature.setContext({serverUri: ...})- callsonContextChange, setsthis.contextBetween steps 1 and 2, the provider is READY and React hooks immediately evaluate flags.
The React SDK's
useBooleanFlagValuehook attachesContextChangedevent handlers inuseEffect(which runs after render).If the
ContextChangedevent from step 2 fires beforeuseEffectattaches handlers, the hook never re-evaluates.The initial evaluation uses
this.context = {}, somatchesSegment()returnsfalseand the toggle appears disabled.So in summary, it fixes these 2 bugs.
this.contextwas always{}regardless of how you called the SDKsetContextaftersetProviderAndWait, creating a window where evaluations happen with no contextBecause of the library bug even using "correct" calling order of (setting context before the provider) didn't work - the context was passed to initialize but thrown away.
Result
initialize()to take acontextparameter passed by the OpenFeature SDK and update the context