From 79d6ba2f7e1901e6df726e14b895fc499c169f05 Mon Sep 17 00:00:00 2001 From: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com> Date: Thu, 8 Oct 2026 16:16:51 -0400 Subject: [PATCH] fix(commands): load each location's commands instead of trusting the builtin seed The commands query seeded every new directory key with the builtin commands as initialData. With the app's 10s staleTime, React Query treated that seed as freshly fetched data, so switching to a session in another project never requested that location's commands and the slash menu showed only the builtins until some later invalidation. Mark the seed as stale with initialDataUpdatedAt: 0 so each directory fetches its commands on mount. --- frontend/src/hooks/useCommands.test.tsx | 21 +++++++++++++++++++++ frontend/src/hooks/useCommands.ts | 1 + 2 files changed, 22 insertions(+) diff --git a/frontend/src/hooks/useCommands.test.tsx b/frontend/src/hooks/useCommands.test.tsx index fb1e97c7..faec4757 100644 --- a/frontend/src/hooks/useCommands.test.tsx +++ b/frontend/src/hooks/useCommands.test.tsx @@ -130,6 +130,27 @@ describe('useCommands', () => { }) }) + it('loads commands for a newly selected directory even when queries have a stale time', async () => { + vi.mocked(listCommands).mockImplementation(async (directory) => [ + { name: directory === '/repo-b' ? 'from-b' : 'from-a', description: '' }, + ]) + const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false, staleTime: 60_000 } } }) + const wrapper = ({ children }: { children: React.ReactNode }) => ( + {children} + ) + + const { result, rerender } = renderHook(({ directory }) => useCommands({ directory }), { + wrapper, + initialProps: { directory: '/repo-a' }, + }) + await waitFor(() => expect(result.current.findCommand('from-a')).toBeDefined()) + + rerender({ directory: '/repo-b' }) + + await waitFor(() => expect(result.current.findCommand('from-b')).toBeDefined()) + expect(listCommands).toHaveBeenCalledWith('/repo-b') + }) + it('finds only exact command names, ignoring case', () => { const { result } = renderHook(() => useCommands({ enabled: false }), { wrapper: createWrapper() }) diff --git a/frontend/src/hooks/useCommands.ts b/frontend/src/hooks/useCommands.ts index 5c4dc09f..bdc0f2ab 100644 --- a/frontend/src/hooks/useCommands.ts +++ b/frontend/src/hooks/useCommands.ts @@ -33,6 +33,7 @@ export function useCommands(options: UseCommandsOptions = {}) { }, enabled, initialData: SORTED_BUILTIN_COMMANDS, + initialDataUpdatedAt: 0, }) const searchCommands = useCallback((query: string) => rankByMatch(commands, query, {