Skip to content

The agent that grows with you

fix(desktop): refetch vault sources after closed-to-open remount

KoNit-Kec5c9759022c
diff --git a/apps/desktop/src/app/settings/vault-settings.test.tsx b/apps/desktop/src/app/settings/vault-settings.test.tsx
index a6cd6fa599b..ba355d0aa99 100644
--- a/apps/desktop/src/app/settings/vault-settings.test.tsx
+++ b/apps/desktop/src/app/settings/vault-settings.test.tsx
@@ -1,5 +1,5 @@
import { QueryClientProvider } from '@tanstack/react-query'
-import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
+import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
import { MemoryRouter } from 'react-router'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
@@ -233,4 +233,38 @@ describe('VaultSettings', () => {
await waitFor(() => expect(screen.getByRole('switch', { name: '1Password' })).toBeTruthy())
expect(requestGateway.mock.calls.filter(([method]) => method === 'vault.sources')).toHaveLength(2)
})
+
+ it('refreshes password-manager detection after remounting while the gateway is closed', async () => {
+ let installed = false
+ requestGateway.mockImplementation(async (method: string) => {
+ if (method === 'vault.sources') {
+ return {
+ sources: [
+ {
+ name: 'onepassword',
+ display_name: '1Password',
+ enabled: false,
+ needs_unlock: true,
+ unlocked: false,
+ installed
+ }
+ ]
+ }
+ }
+
+ return { items: [] }
+ })
+
+ const first = renderVault()
+ await screen.findByText('Not detected')
+ first.unmount()
+
+ installed = true
+ $gatewayState.set('closed')
+ renderVault()
+ act(() => $gatewayState.set('open'))
+
+ await waitFor(() => expect(screen.getByRole('switch', { name: '1Password' })).toBeTruthy())
+ expect(requestGateway.mock.calls.filter(([method]) => method === 'vault.sources')).toHaveLength(2)
+ })
})
diff --git a/apps/desktop/src/app/settings/vault-settings.tsx b/apps/desktop/src/app/settings/vault-settings.tsx
index ce0873e6098..f6e63f44763 100644
--- a/apps/desktop/src/app/settings/vault-settings.tsx
+++ b/apps/desktop/src/app/settings/vault-settings.tsx
@@ -188,9 +188,10 @@ export function VaultSettings() {
const { data: sourcesData } = useQuery({
enabled: gatewayState === 'open',
queryKey: VAULT_SOURCES_QUERY_KEY,
- // Manager detection can change while this settings page is closed. Always ask the
- // local backend again on mount instead of reusing the shared cache's 60s fresh value.
- refetchOnMount: 'always',
+ // Manager detection can change while this settings page is closed. Mark this
+ // metadata query immediately stale so remount and closed-to-open recovery
+ // refetch instead of honouring the shared 60s cache.
+ staleTime: 0,
queryFn: async () => {
const result = await requestGateway<{ sources: VaultSource[] }>('vault.sources', {})