From e7473a07e30ef0e5e747a3d79567fd6d2fefcd38 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sat, 30 May 2026 01:27:54 -0700 Subject: [PATCH] fix: guard browser profile async state (#3553) --- .../browser-pane/BrowserToolbarMenu.tsx | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/renderer/src/components/browser-pane/BrowserToolbarMenu.tsx b/src/renderer/src/components/browser-pane/BrowserToolbarMenu.tsx index 100b7ef10d5..e3d6da35693 100644 --- a/src/renderer/src/components/browser-pane/BrowserToolbarMenu.tsx +++ b/src/renderer/src/components/browser-pane/BrowserToolbarMenu.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react' +import { useEffect, useRef, useState } from 'react' import { Check, Ellipsis, Import, Monitor, Plus, Settings } from 'lucide-react' import { toast } from 'sonner' import { Button } from '@/components/ui/button' @@ -71,6 +71,7 @@ export function BrowserToolbarMenu({ const [pendingSwitchProfileId, setPendingSwitchProfileId] = useState( undefined ) + const mountedRef = useRef(true) const effectiveProfileId = currentProfileId ?? 'default' @@ -81,6 +82,13 @@ 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) { @@ -114,7 +122,13 @@ export function BrowserToolbarMenu({ try { const profile = await createBrowserSessionProfile('isolated', trimmed) if (!profile) { - toast.error('Failed to create profile.') + if (mountedRef.current) { + toast.error('Failed to create profile.') + } + return + } + + if (!mountedRef.current) { return } @@ -125,7 +139,9 @@ export function BrowserToolbarMenu({ switchBrowserTabProfile(workspaceId, profile.id) toast.success(`Created and switched to ${profile.label} profile`) } finally { - setIsCreatingProfile(false) + if (mountedRef.current) { + setIsCreatingProfile(false) + } } }