perf: reuse mounted ref in browser toolbar menu

This commit is contained in:
Neil
2026-05-30 02:54:58 -07:00
parent 949a101f8b
commit fbb640f372
@@ -1,4 +1,4 @@
import { useEffect, useRef, useState } from 'react'
import { useState } from 'react'
import { Check, Ellipsis, Import, Monitor, Plus, Settings } from 'lucide-react'
import { toast } from 'sonner'
import { Button } from '@/components/ui/button'
@@ -25,6 +25,7 @@ import {
DropdownMenuTrigger
} from '@/components/ui/dropdown-menu'
import { useAppStore } from '@/store'
import { useMountedRef } from '@/hooks/useMountedRef'
import { BROWSER_FAMILY_LABELS } from '../../../../shared/constants'
import type { BrowserViewportPresetId } from '../../../../shared/types'
import {
@@ -71,7 +72,7 @@ export function BrowserToolbarMenu({
const [pendingSwitchProfileId, setPendingSwitchProfileId] = useState<string | null | undefined>(
undefined
)
const mountedRef = useRef(true)
const mountedRef = useMountedRef()
const effectiveProfileId = currentProfileId ?? 'default'
@@ -82,13 +83,6 @@ export function BrowserToolbarMenu({
? [defaultProfile, ...browserSessionProfiles.filter((p) => p.id !== 'default')]
: browserSessionProfiles
useEffect(() => {
mountedRef.current = true
return () => {
mountedRef.current = false
}
}, [])
const handleSwitchProfile = (profileId: string | null): void => {
const targetId = profileId ?? 'default'
if (targetId === effectiveProfileId) {