Skip to content

fix: Input select state-rendering fix#6402

Merged
raunakab merged 8 commits intomainfrom
input-select-fix
Nov 23, 2025
Merged

fix: Input select state-rendering fix#6402
raunakab merged 8 commits intomainfrom
input-select-fix

Conversation

@raunakab
Copy link
Copy Markdown
Contributor

@raunakab raunakab commented Nov 23, 2025

Description

Hotfix for infinite loop issue for InputSelect.


Summary by cubic

Fixes an infinite re-render loop in InputSelect by registering only the selected item's display via refs. Also resolves controlled/uncontrolled non-persistence and prevents UI freezes with unstable children.

Written for commit 9d81733. Summary will update automatically on new commits.

@raunakab raunakab requested a review from a team as a code owner November 23, 2025 18:30
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Nov 23, 2025

Greptile Overview

Greptile Summary

Fixed infinite re-render loop in InputSelect component caused by unstable icon references in InputSelect.Item children.

  • Added deduplication check in registerItem callback that skips state updates if item value is already registered
  • Prevents infinite loops when InputSelect.Item receives React elements with unstable references (e.g., icon={createIcon(option.icon)})
  • The issue was introduced in PR fix: Fix non-persistence issue with input-select #6398 which changed from useRef to useState for the item registry to trigger re-renders
  • With useState, each registration triggers a re-render, which causes items with unstable props to re-register, creating a loop
  • The fix returns early from setItems if the item is already registered, breaking the cycle

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix is a targeted, defensive check that prevents unnecessary state updates without changing any functional behavior. The deduplication logic is sound and handles the edge case of unstable references gracefully. This is a simple hotfix that addresses the root cause of the infinite loop introduced in the previous PR.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
web/src/refresh-components/inputs/InputSelect.tsx 5/5 Added deduplication check in registerItem to prevent infinite re-renders from unstable icon references

Sequence Diagram

sequenceDiagram
    participant Parent as Parent Component
    participant InputSelect as InputSelect Root
    participant Item as InputSelect.Item
    participant registerItem as registerItem callback
    
    Note over Parent,registerItem: Initial Render (PR #6398)
    Parent->>InputSelect: Render with items
    InputSelect->>Item: Mount Item component
    Item->>registerItem: Call with {value, children, icon}
    registerItem->>InputSelect: setItems (triggers re-render)
    InputSelect->>Item: Re-render Item
    Item->>registerItem: Call with NEW icon reference
    Note over registerItem: Icon created via createIcon() has<br/>unstable reference on each render
    registerItem->>InputSelect: setItems (triggers re-render)
    Note over InputSelect,registerItem: ⚠️ INFINITE LOOP
    
    Note over Parent,registerItem: After This Fix (PR #6402)
    Parent->>InputSelect: Render with items
    InputSelect->>Item: Mount Item component
    Item->>registerItem: Call with {value, children, icon}
    Note over registerItem: Check: prev.has(item.value)?
    registerItem->>InputSelect: setItems (triggers re-render)
    InputSelect->>Item: Re-render Item
    Item->>registerItem: Call with NEW icon reference
    Note over registerItem: Check: prev.has(item.value)?<br/>✓ Already registered, return prev
    Note over registerItem: No state update = No re-render
    Note over InputSelect,registerItem: ✅ Loop prevented
Loading

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@raunakab
Copy link
Copy Markdown
Contributor Author

@cubic-dev-ai, could you please review this? Thanks!

@cubic-dev-ai
Copy link
Copy Markdown
Contributor

cubic-dev-ai bot commented Nov 23, 2025

@cubic-dev-ai, could you please review this? Thanks!

@raunakab I've started the AI code review. It'll take a few minutes to complete.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file

Prompt for AI agents (all 1 issues)

Understand the root cause of the following 1 issues and fix them.


<file name="web/src/refresh-components/inputs/InputSelect.tsx">

<violation number="1" location="web/src/refresh-components/inputs/InputSelect.tsx:173">
The early-return guard never triggers because `registerItem` is only invoked after its cleanup has already removed the previous entry, so the infinite re-register/unregister loop still occurs when `children` has an unstable reference. The hotfix does not fix the reported issue.</violation>
</file>

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

@raunakab
Copy link
Copy Markdown
Contributor Author

@cubic-dev-ai, please re-review this again.

@cubic-dev-ai
Copy link
Copy Markdown
Contributor

cubic-dev-ai bot commented Nov 23, 2025

@cubic-dev-ai, please re-review this again.

@raunakab I've started the AI code review. It'll take a few minutes to complete.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file

Prompt for AI agents (all 1 issues)

Understand the root cause of the following 1 issues and fix them.


<file name="web/src/refresh-components/inputs/InputSelect.tsx">

<violation number="1" location="web/src/refresh-components/inputs/InputSelect.tsx:406">
Removing children/icon from the effect dependencies means the selected-item registry never updates when those props change, so the trigger can show stale labels/icons for items whose content updates after mount.</violation>
</file>

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

@raunakab raunakab changed the title Input select fix fix: Input select state-rendering fix Nov 23, 2025
@raunakab
Copy link
Copy Markdown
Contributor Author

@cubic-dev-ai, please review this one again!

@raunakab raunakab enabled auto-merge November 23, 2025 19:44
@cubic-dev-ai
Copy link
Copy Markdown
Contributor

cubic-dev-ai bot commented Nov 23, 2025

@cubic-dev-ai, please review this one again!

@raunakab I've started the AI code review. It'll take a few minutes to complete.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file

Prompt for AI agents (all 1 issues)

Understand the root cause of the following 1 issues and fix them.


<file name="web/src/refresh-components/inputs/InputSelect.tsx">

<violation number="1" location="web/src/refresh-components/inputs/InputSelect.tsx:253">
Selected option label/icon stay stuck if those props change because `displayContent` only depends on the selectedItemDisplay object, so the trigger never re-renders with the updated ref contents.</violation>
</file>

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

@raunakab
Copy link
Copy Markdown
Contributor Author

@cubic-dev-ai, please review this one again!

@cubic-dev-ai
Copy link
Copy Markdown
Contributor

cubic-dev-ai bot commented Nov 23, 2025

@cubic-dev-ai, please review this one again!

@raunakab I've started the AI code review. It'll take a few minutes to complete.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 4 files

@raunakab raunakab disabled auto-merge November 23, 2025 20:32
@raunakab raunakab merged commit 920db6b into main Nov 23, 2025
68 of 70 checks passed
@raunakab raunakab deleted the input-select-fix branch November 23, 2025 20:32
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