Skip to content

Fix infinite re-render loop in NameManagerDialog (React #185) - #39

Merged
Ocean82 merged 1 commit into
mainfrom
fix/name-manager-rerender-loop
Sep 22, 2026
Merged

Ocean82 merged 1 commit into
mainfrom
fix/name-manager-rerender-loop

Conversation

@Ocean82

@Ocean82 Ocean82 commented Sep 22, 2026 •

Copy link
Copy Markdown
Owner

The namedRanges selector returned a fresh [] on every render when the value was undefined, failing Zustand's Object.is check and looping forever. Use a stable module-level constant instead. Also document the same trap on getPinnedMessages.

Summary by Sourcery

Use a stable fallback for missing named ranges and document safe usage of dynamically allocated selector results.

Bug Fixes:

  • Prevent the NameManagerDialog from entering an infinite re-render loop when named ranges are unavailable.
  • Document the selector usage constraint for getPinnedMessages to prevent similar Zustand re-render loops.

The namedRanges selector returned a fresh [] on every render when the value was undefined, failing Zustand's Object.is check and looping forever. Use a stable module-level constant instead. Also document the same trap on getPinnedMessages.
Copilot AI lite review requested due to automatic review settings September 22, 2026 18:35
@sourcery-ai

sourcery-ai Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Fixes the NameManagerDialog infinite re-render loop by replacing its per-render empty-array fallback with a stable module-level reference, and documents the equivalent Zustand selector pitfall for getPinnedMessages.

Sequence diagram for the stable Zustand selector fallback

sequenceDiagram
    participant React
    participant NameManagerDialog
    participant Zustand
    React->>NameManagerDialog: render()
    NameManagerDialog->>Zustand: useStore(selector)
    Zustand-->>NameManagerDialog: workbook.namedRanges or EMPTY_NAMED_RANGES
    Zustand->>Zustand: Object.is compares selected reference
    alt namedRanges is undefined
        Zustand-->>Zustand: Stable EMPTY_NAMED_RANGES reference
    else namedRanges exists
        Zustand-->>Zustand: Existing namedRanges reference
    end
    Zustand-->>React: No unnecessary re-render
Loading

File-Level Changes

Change Details Files
Stabilize the fallback returned by the named-ranges Zustand selector to prevent React infinite re-renders.
  • Add a module-level empty named-range array with stable identity.
  • Use the stable fallback when workbook named ranges are undefined.
src/components/NameManagerDialog.tsx
Document the referential-equality hazard for selectors that invoke array-producing store methods.
  • Explain that calling getPinnedMessages inside a selector creates a fresh array and can trigger React error #185.
  • Recommend selecting the function reference and invoking it in an effect or handler, or using shallow comparison.
src/store/slices/chatSlice.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 9df90802-18ce-403f-bb5d-3d58d6494a3e


Comment @coderabbitai help to get the list of available commands.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@Ocean82
Ocean82 merged commit 32cc0ad into main Sep 22, 2026
5 checks passed
@Ocean82
Ocean82 deleted the fix/name-manager-rerender-loop branch September 22, 2026 18:39
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.

2 participants