Skip to content

Conversation

@MattIPv4
Copy link
Member

@MattIPv4 MattIPv4 commented Dec 2, 2025

This PR

Updates the no-op logic in useContextMutator's setContext method to compare against the actual previous context as returned by OpenFeature itself, rather than just the previous context that that specific use of useContextMutator had in its ref (#1301 (comment)).

Building on #1301, this should allow for setContext to be called with a method, and for that method to return the context it was provided, to guarantee a no-op always.

@MattIPv4 MattIPv4 requested review from a team as code owners December 2, 2025 22:28
@gemini-code-assist
Copy link
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 refines the context mutation mechanism within the React SDK, specifically addressing how useContextMutator handles updates. It ensures that context updates are only triggered when there's an actual change in the context value, preventing redundant operations and improving efficiency, especially when using functional updates. This builds upon previous work to make context management more robust.

Highlights

  • Improved Context Mutation Logic: The useContextMutator hook's setContext method now accurately determines the 'previous context' by directly querying OpenFeature.getContext. This ensures that the comparison for a no-op update is based on the actual current state of the context, rather than a potentially stale useRef value.
  • Accurate Functional Context Updates: When setContext is called with a function, the function now receives the actual current context from OpenFeature, allowing for more precise and reliable context transformations.
  • No-Op Optimization: The change prevents unnecessary context updates and associated side effects (like re-renders or ProviderEvents.Reconciling events) if the functional update returns a context identical to the current one.
  • New Test Case for No-Op Behavior: A new test has been added to provider.spec.tsx to explicitly verify that setContext correctly performs a no-op when a functional update yields an unchanged context.
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
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 correctly updates the no-op logic in useContextMutator to compare against the actual current context from the OpenFeature SDK, rather than a locally stored one. This is a good fix that prevents potential bugs. The tests are also well-updated to cover the new logic. I have two suggestions for improvement: one to correctly handle the async nature of setContext, and another for a minor cleanup in the tests.

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.

1 participant