perf: reuse mounted ref in notice cards (#3577)

This commit is contained in:
Neil
2026-05-30 02:36:59 -07:00
committed by GitHub
parent 947ce98e39
commit e17c6e6d04
2 changed files with 6 additions and 18 deletions
@@ -33,11 +33,12 @@
// off), the notice never returns, because the cohort condition
// (`optedIn === null`) clears in all three resolving paths.
import { useEffect, useRef, useState } from 'react'
import { useState } from 'react'
import { X } from 'lucide-react'
import { Button } from './ui/button'
import { acknowledgeBanner, PRIVACY_URL, setOptIn as telemetrySetOptIn } from '../lib/telemetry'
import { useMountedRef } from '@/hooks/useMountedRef'
type FirstLaunchBannerProps = {
onResolve: () => void
@@ -57,14 +58,7 @@ export function FirstLaunchBanner({
// wasted IPC round-trip, but the guard also blocks a Turn-off click
// arriving mid-flight after an acknowledge (or vice versa).
const [inFlight, setInFlight] = useState(false)
const mountedRef = useRef(true)
useEffect(() => {
mountedRef.current = true
return () => {
mountedRef.current = false
}
}, [])
const mountedRef = useMountedRef()
const handleAcknowledge = async (): Promise<void> => {
if (inFlight) {
+3 -9
View File
@@ -1,8 +1,9 @@
import { useEffect, useRef, useState } from 'react'
import { useEffect, useState } from 'react'
import { Star, X } from 'lucide-react'
import { Card } from './ui/card'
import { Button } from './ui/button'
import { useAppStore } from '../store'
import { useMountedRef } from '@/hooks/useMountedRef'
/**
* Persistent "star Orca on GitHub" notification card.
@@ -19,7 +20,7 @@ export function StarNagCard(): React.JSX.Element | null {
const [visible, setVisible] = useState(false)
const [busy, setBusy] = useState(false)
const [error, setError] = useState(false)
const mountedRef = useRef(true)
const mountedRef = useMountedRef()
// Why: UpdateCard lives at the same bottom-right slot. When it is visible
// (any non-idle / non-not-available state), stack the star-nag card above
// it instead of overlapping — we must not cover a pending update prompt
@@ -27,13 +28,6 @@ export function StarNagCard(): React.JSX.Element | null {
const updateStatus = useAppStore((s) => s.updateStatus)
const updateCardVisible = updateStatus.state !== 'idle' && updateStatus.state !== 'not-available'
useEffect(() => {
mountedRef.current = true
return () => {
mountedRef.current = false
}
}, [])
useEffect(() => {
return window.api.starNag.onShow(() => {
setError(false)