fix(web): replace hasOpenedDiff useState/useEffect latch with useRef#1104
fix(web): replace hasOpenedDiff useState/useEffect latch with useRef#1104Mergemat wants to merge 1 commit intopingdotgg:mainfrom
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment Tip You can disable sequence diagrams in the walkthrough.Disable the |
a044ffb to
2c4a2cf
Compare
setState inside useEffect schedules an extra render. The value only gates rendering, never drives it, so a ref is the right tool.
2c4a2cf to
e07e402
Compare
Replaces a
useState+useEffectlatch forhasOpenedDiffwith auseRefwritten inline during render.What changed: removed the effect that called
setHasOpenedDiff(true)whendiffOpenwas true. The ref is initialized todiffOpenand set inline:if (diffOpen) hasOpenedDiffRef.current = true.Why: calling
setStateinside auseEffectschedules 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
hasOpenedDiffstate latch with a ref inChatThreadRouteViewReplaces a
useState/useEffectpattern with auseRefto track whether the diff panel has been opened. The ref is initialized to the currentdiffOpenvalue and set synchronously whendiffOpenis true, removing an unnecessary render cycle caused by the prior effect.Macroscope summarized e07e402.