Skip to content

fix: infer domain from client for useContextMutator setContext#1317

Merged
beeme1mr merged 3 commits intoopen-feature:mainfrom
MattIPv4:fix/set-context-use-client-domain
Jan 16, 2026
Merged

fix: infer domain from client for useContextMutator setContext#1317
beeme1mr merged 3 commits intoopen-feature:mainfrom
MattIPv4:fix/set-context-use-client-domain

Conversation

@MattIPv4
Copy link
Copy Markdown
Member

This PR

As identified when chatting in #1303 (comment), if you pass a Client into <OpenFeatureProvider/>, then useContextMutator#setContext will always see domain as undefined and so will always mutate the default domain even if the client is not for that domain -- instead, we should rely on the domain that the client tells us it is for!

I've also updated the tests generally for useContextMutator slightly, as they were sometimes reusing contexts set by other tests, leading to unexpected failures when I added this new test.

Notes

This, and the provider hook, were the only two things relying on the domain property being exposed in the internal context, so I've removed it to hopefully prevent any future logic from running into this same trap.

Open question that I've left as a TODO, should the hook throw an error if someone tries to use the hook outside of <OpenFeatureProvider/> (if they've not set defaultContext: true)? Though I fear that would make this a breaking change (though arguably it is still a fix as being able to use this outside a hook today feels like a bug, not an intentional design decision)?

@MattIPv4 MattIPv4 requested review from a team as code owners December 11, 2025 18:19
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @MattIPv4, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical bug in the React SDK where useContextMutator would incorrectly apply context changes to the default domain, even when a domain-specific client was explicitly provided to the OpenFeatureProvider. The fix ensures that context mutations are accurately directed to the domain associated with the client, enhancing the reliability and correctness of context management within domain-scoped OpenFeature applications. Additionally, it refines the internal context structure and improves test coverage for these scenarios.

Highlights

  • Context Domain Inference: The useContextMutator hook now correctly infers the domain from the client's metadata when a client is passed to <OpenFeatureProvider/>, ensuring context mutations apply to the intended domain instead of always defaulting.
  • Internal Context Simplification: The domain property has been removed from the internal React context as it was redundant and could lead to incorrect domain inference, simplifying the context structure.
  • Improved Test Coverage: Existing tests for useContextMutator have been updated and a new test case added to specifically verify context updates when an OpenFeatureProvider is configured with a client, preventing context reuse issues between tests.
  • Future Error Handling Consideration: A TODO comment has been added to useContextMutator to consider throwing an error if the hook is used outside <OpenFeatureProvider/> without defaultContext: true, prompting discussion on potential breaking changes for improved usage validation.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

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

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 effectively addresses a bug where useContextMutator#setContext would incorrectly mutate the default domain's context when a Client instance was passed to the OpenFeatureProvider. The fix correctly infers the domain from the client's metadata. I appreciate the additional improvements, such as removing the now-redundant domain property from the internal context, which simplifies the code and prevents similar issues in the future. The updates to the tests to improve isolation and add coverage for the new logic are also excellent. The changes are well-implemented and I have no further suggestions. Great work!

Copy link
Copy Markdown
Member

@lukas-reining lukas-reining left a comment

Choose a reason for hiding this comment

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

The change looks good, thanks @MattIPv4!
Left my opinion regarding the breaking change.

Copy link
Copy Markdown
Member

@beeme1mr beeme1mr left a comment

Choose a reason for hiding this comment

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

Looks good. I'll approve once the TODO has been resolved. Thanks!

@MattIPv4 MattIPv4 force-pushed the fix/set-context-use-client-domain branch from 6059792 to 18cef96 Compare January 15, 2026 19:56
Signed-off-by: MattIPv4 <me@mattcowley.co.uk>
Signed-off-by: MattIPv4 <me@mattcowley.co.uk>
Signed-off-by: MattIPv4 <me@mattcowley.co.uk>
@MattIPv4 MattIPv4 force-pushed the fix/set-context-use-client-domain branch from 18cef96 to 69a2612 Compare January 15, 2026 19:56
@MattIPv4 MattIPv4 requested a review from beeme1mr January 15, 2026 21:27
@beeme1mr beeme1mr closed this Jan 15, 2026
@beeme1mr beeme1mr reopened this Jan 15, 2026
@beeme1mr beeme1mr enabled auto-merge January 15, 2026 23:56
@beeme1mr beeme1mr added this pull request to the merge queue Jan 15, 2026
Merged via the queue into open-feature:main with commit 49e664f Jan 16, 2026
17 checks passed
github-merge-queue bot pushed a commit that referenced this pull request Jan 16, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.2.0](react-sdk-v1.1.0...react-sdk-v1.2.0)
(2026-01-16)


### ✨ New Features

* Add evaluation options to FeatureFlag component
([#1322](#1322))
([f3f3685](f3f3685))
* **react:** add FeatureFlag component
([#1164](#1164))
([e7a5fb5](e7a5fb5))


### 🐛 Bug Fixes

* infer domain from client for useContextMutator setContext
([#1317](#1317))
([49e664f](49e664f))
* remove explicit return type for React `OpenFeatureProvider`
([#1313](#1313))
([fb6cdc9](fb6cdc9))


### 📚 Documentation

* **react:** fix type in declarative testing example
([#1323](#1323))
([aebc2aa](aebc2aa))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Signed-off-by: OpenFeature Bot <109696520+openfeaturebot@users.noreply.github.com>
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.

3 participants