Skip to content

[Trivial] WIP fix for infinite re-render#409

Open
GioLogist wants to merge 4 commits intomainfrom
test-infinite-rerender-issue
Open

[Trivial] WIP fix for infinite re-render#409
GioLogist wants to merge 4 commits intomainfrom
test-infinite-rerender-issue

Conversation

@GioLogist
Copy link
Collaborator

[LINEAR_ISSUE_ID_HERE]

Description

Write a description.

Test Plan

  • Locally
  • Unit Tests
  • Manually
  • CI/CD

Screenshots

For BE, include snippets, response payloads and/or curl commands to test endpoints

[FE] Before

[FE] After

[BE] Snippets/Response/Curl


automerge=false

@GioLogist GioLogist requested a review from a team as a code owner December 18, 2025 16:36
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @GioLogist, 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 addresses a potential infinite re-render problem within the B3Provider component. By adjusting the dependency array of the configuration initialization useEffect hook to be empty, the component's setup logic will now execute only once upon mounting, thereby enhancing the stability and performance of the application.

Highlights

  • Preventing Infinite Re-renders: Modified the useEffect hook responsible for initializing the B3 config store to use an empty dependency array. This ensures the configuration is set only once on component mount, resolving potential infinite re-render issues caused by unstable dependencies.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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 aims to fix an infinite re-render issue in the B3Provider component by changing the dependency array of a useEffect hook to be empty. While this does prevent the infinite loop, it introduces a critical issue where the provider's configuration becomes static after the initial render and will not update if its props change. I've provided a suggestion to correctly handle object dependencies to prevent re-renders while still allowing the configuration to be updated.

Comment on lines 71 to 88
useEffect(
() => {
setConfig({
accountOverride,
environment: environment ?? "development",
automaticallySetFirstEoa: !!automaticallySetFirstEoa,
theme,
clientType,
partnerId,
stripePublishableKey,
createClientReferenceId,
enableTurnkey,
defaultPermissions,
});
},
// eslint-disable-line react-hooks/exhaustive-deps
[],
);
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

Changing the useEffect dependency array to [] makes the configuration static after the initial mount. This means any subsequent changes to the B3Provider props will be ignored, leading to a stale configuration in the Zustand store. This can cause subtle and hard-to-debug bugs.

A better approach is to ensure the dependencies are stable. For object props that might be causing the infinite loop, you can use JSON.stringify to create a dependency that changes only when the object's value changes, not just its reference. This fixes the re-render loop while keeping the configuration up-to-date. This will likely require an eslint-disable comment for react-hooks/exhaustive-deps because the values used in the effect (accountOverride, defaultPermissions) don't match the dependencies exactly, but it's a safer pattern.

  useEffect(
    () => {
      setConfig({
        accountOverride,
        environment: environment ?? "development",
        automaticallySetFirstEoa: !!automaticallySetFirstEoa,
        theme,
        clientType,
        partnerId,
        stripePublishableKey,
        createClientReferenceId,
        enableTurnkey,
        defaultPermissions,
      });
    },
    [
      environment,
      automaticallySetFirstEoa,
      theme,
      clientType,
      partnerId,
      stripePublishableKey,
      createClientReferenceId,
      enableTurnkey,
      setConfig,
      JSON.stringify(accountOverride),
      JSON.stringify(defaultPermissions),
    ]
  );

@GioLogist GioLogist force-pushed the test-infinite-rerender-issue branch from 1edbf63 to 01e199a Compare December 18, 2025 16:40
@GioLogist GioLogist force-pushed the test-infinite-rerender-issue branch from 01e199a to df31015 Compare December 18, 2025 16:42
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