fix: infer domain from client for useContextMutator setContext#1317
Conversation
Summary of ChangesHello @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 Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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!
lukas-reining
left a comment
There was a problem hiding this comment.
The change looks good, thanks @MattIPv4!
Left my opinion regarding the breaking change.
beeme1mr
left a comment
There was a problem hiding this comment.
Looks good. I'll approve once the TODO has been resolved. Thanks!
6059792 to
18cef96
Compare
Signed-off-by: MattIPv4 <me@mattcowley.co.uk>
Signed-off-by: MattIPv4 <me@mattcowley.co.uk>
Signed-off-by: MattIPv4 <me@mattcowley.co.uk>
18cef96 to
69a2612
Compare
🤖 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>
This PR
As identified when chatting in #1303 (comment), if you pass a
Clientinto<OpenFeatureProvider/>, thenuseContextMutator#setContextwill always seedomainasundefinedand 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
useContextMutatorslightly, 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
domainproperty 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 setdefaultContext: 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)?