Skip to content

The agent that grows with you

fix(desktop): every Custom Endpoints completion is dropped once its profile view unmounts

teknium155c92fa32a46
diff --git a/apps/desktop/src/app/settings/custom-endpoints-settings.test.tsx b/apps/desktop/src/app/settings/custom-endpoints-settings.test.tsx
index a24aa436044..8aa6f4b5771 100644
--- a/apps/desktop/src/app/settings/custom-endpoints-settings.test.tsx
+++ b/apps/desktop/src/app/settings/custom-endpoints-settings.test.tsx
@@ -10,13 +10,15 @@ const notify = vi.fn()
const notifyError = vi.fn()
const triggerHaptic = vi.fn()
-vi.mock('@/hermes', () => ({
+vi.mock('@/hermes', async importOriginal => ({
+ ...(await importOriginal<Record<string, unknown>>()),
activateCustomEndpoint: vi.fn(),
deleteCustomEndpoint: vi.fn(),
getCustomEndpoints: (...args: unknown[]) => getCustomEndpoints(...args),
saveCustomEndpoint: (...args: unknown[]) => saveCustomEndpoint(...args),
validateCustomEndpoint: vi.fn()
}))
+vi.mock('./profile-scope', () => ({ ActiveProfileNote: () => null }))
vi.mock('@/lib/haptics', () => ({ triggerHaptic: (...args: unknown[]) => triggerHaptic(...args) }))
vi.mock('@/store/notifications', () => ({
notify: (...args: unknown[]) => notify(...args),
diff --git a/apps/desktop/src/app/settings/custom-endpoints-settings.tsx b/apps/desktop/src/app/settings/custom-endpoints-settings.tsx
index 0ce4123e4b4..6259c73f425 100644
--- a/apps/desktop/src/app/settings/custom-endpoints-settings.tsx
+++ b/apps/desktop/src/app/settings/custom-endpoints-settings.tsx
@@ -91,7 +91,10 @@ export function CustomEndpointsSettings({ onConfigSaved, onMainModelChanged }: C
async function refresh() {
const data = await getCustomEndpoints()
- setEndpoints(data.endpoints)
+
+ if (mounted.current) {
+ setEndpoints(data.endpoints)
+ }
}
// eslint-disable-next-line no-restricted-syntax -- lifecycle guard drops stale async completions; it does not mirror an atom
@@ -170,6 +173,11 @@ export function CustomEndpointsSettings({ onConfigSaved, onMainModelChanged }: C
try {
setTesting(true)
const response = await validateCustomEndpoint(toPayload(form))
+
+ if (!mounted.current) {
+ return
+ }
+
setDiscoveredModels(response.models)
if (response.ok) {
@@ -190,9 +198,13 @@ export function CustomEndpointsSettings({ onConfigSaved, onMainModelChanged }: C
})
}
} catch (err) {
- notifyError(err, 'Validation failed')
+ if (mounted.current) {
+ notifyError(err, 'Validation failed')
+ }
} finally {
- setTesting(false)
+ if (mounted.current) {
+ setTesting(false)
+ }
}
}
@@ -200,14 +212,28 @@ export function CustomEndpointsSettings({ onConfigSaved, onMainModelChanged }: C
try {
setActivating(endpoint.id)
const response = await activateCustomEndpoint(endpoint.id)
+
+ if (!mounted.current) {
+ return
+ }
+
await refresh()
+
+ if (!mounted.current) {
+ return
+ }
+
onConfigSaved?.()
onMainModelChanged?.(response.provider, response.model)
triggerHaptic('success')
} catch (err) {
- notifyError(err, 'Activation failed')
+ if (mounted.current) {
+ notifyError(err, 'Activation failed')
+ }
} finally {
- setActivating(null)
+ if (mounted.current) {
+ setActivating(null)
+ }
}
}
@@ -220,6 +246,11 @@ export function CustomEndpointsSettings({ onConfigSaved, onMainModelChanged }: C
try {
setDeleting(endpoint.id)
const response = await deleteCustomEndpoint(endpoint.id)
+
+ if (!mounted.current) {
+ return
+ }
+
setEndpoints(response.endpoints)
if (form.id === endpoint.id) {
@@ -230,9 +261,13 @@ export function CustomEndpointsSettings({ onConfigSaved, onMainModelChanged }: C
onConfigSaved?.()
triggerHaptic('success')
} catch (err) {
- notifyError(err, 'Delete failed')
+ if (mounted.current) {
+ notifyError(err, 'Delete failed')
+ }
} finally {
- setDeleting(null)
+ if (mounted.current) {
+ setDeleting(null)
+ }
}
}