Skip to content

fix(web): replace hasOpenedDiff useState/useEffect latch with useRef#1104

Open
Mergemat wants to merge 1 commit intopingdotgg:mainfrom
Mergemat:fix/has-opened-diff-ref
Open

fix(web): replace hasOpenedDiff useState/useEffect latch with useRef#1104
Mergemat wants to merge 1 commit intopingdotgg:mainfrom
Mergemat:fix/has-opened-diff-ref

Conversation

@Mergemat
Copy link

@Mergemat Mergemat commented Mar 15, 2026

Replaces a useState + useEffect latch for hasOpenedDiff with a useRef written inline during render.

What changed: removed the effect that called setHasOpenedDiff(true) when diffOpen was true. The ref is initialized to diffOpen and set inline: if (diffOpen) hasOpenedDiffRef.current = true.

Why: calling setState inside a useEffect schedules an extra render after the initial one completes. The value is never needed to trigger a re-render — only to gate rendering of diff content — so a ref is the right tool.

Note

Replace hasOpenedDiff state latch with a ref in ChatThreadRouteView

Replaces a useState/useEffect pattern with a useRef to track whether the diff panel has been opened. The ref is initialized to the current diffOpen value and set synchronously when diffOpen is true, removing an unnecessary render cycle caused by the prior effect.

Macroscope summarized e07e402.

@coderabbitai
Copy link

coderabbitai bot commented Mar 15, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 198e071d-e69d-4e87-97cf-7b0e3a34cb83

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Tip

You can disable sequence diagrams in the walkthrough.

Disable the reviews.sequence_diagrams setting to disable sequence diagrams in the walkthrough.

@github-actions github-actions bot added size:S 10-29 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels Mar 15, 2026
@Mergemat Mergemat force-pushed the fix/has-opened-diff-ref branch from a044ffb to 2c4a2cf Compare March 15, 2026 05:16
setState inside useEffect schedules an extra render. The value only gates rendering, never drives it, so a ref is the right tool.
@Mergemat Mergemat force-pushed the fix/has-opened-diff-ref branch from 2c4a2cf to e07e402 Compare March 15, 2026 05:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant