Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(desktop): r7-m4 preserve navigation during folder denial

Josué8a9350020a02
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx
index 9627d569a..d3f5e09f4 100644
--- a/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx
+++ b/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx
@@ -2058,6 +2058,62 @@ describe('useGfsBrowserController', () => {
expect(lastHarnessQueryClient?.getQueryData(childrenKey)).toBeUndefined()
})
+ it('does not let an old folder denial cancel a pending destination navigation', async () => {
+ const root = await resolveResource(
+ resolvedDirectory('root', 'Root', { gfsUri: 'gfs://main/root' })
+ )
+ const folderB = await resolveResource(
+ resolvedDirectory('folder-b', 'Folder B', { gfsUri: 'gfs://main/folder-b' })
+ )
+ let finishNavigation!: (resource: typeof folderB) => void
+ const pendingNavigation = new Promise<typeof folderB>(resolve => {
+ finishNavigation = resolve
+ })
+ const resolve = vi
+ .fn()
+ .mockResolvedValueOnce(root)
+ .mockImplementationOnce(() => pendingNavigation)
+ const listChildren = vi
+ .fn()
+ .mockResolvedValueOnce(await listChildrenPage([childView('leaf', 'leaf.md', 'file')]))
+ .mockRejectedValueOnce(new Error('403 Forbidden: resource unavailable httpStatus=403'))
+ .mockResolvedValue({ items: [], nextCursor: null })
+ Object.defineProperty(window, 'clerum', {
+ configurable: true,
+ value: {
+ gfs: {
+ listAccessible: vi.fn(async () => ({ items: [], nextCursor: null })),
+ resolve,
+ listChildren,
+ affordances: vi.fn(async () => ({
+ held: ['read'],
+ canDelegate: false,
+ grantableBits: [],
+ canCreateShare: false,
+ })),
+ },
+ },
+ })
+
+ render(<Probe />, { wrapper: ProductionHarness })
+ await act(async () => screen.getByRole('button', { name: 'open' }).click())
+ await waitFor(() => expect(screen.getByTestId('current').textContent).toBe('root'))
+ await waitFor(() => expect(listChildren).toHaveBeenCalledTimes(1))
+ screen.getByRole('button', { name: 'open user destination' }).click()
+ await waitFor(() => expect(resolve).toHaveBeenCalledTimes(2))
+
+ void lastHarnessQueryClient?.invalidateQueries({
+ exact: true,
+ queryKey: desktopQueryKeys.gfsChildren(':user-a:team-a', 'root', 'main'),
+ })
+ await waitFor(() => expect(listChildren).toHaveBeenCalledTimes(2))
+ await act(async () => finishNavigation(folderB))
+
+ await waitFor(() => expect(screen.getByTestId('current').textContent).toBe('folder-b'))
+ expect(screen.getByTestId('current-name').textContent).toBe('Folder B')
+ expect(screen.getByTestId('open-error').textContent).toBe('none')
+ })
+
it('revalidates accessible resources on remount even under production cache defaults', async () => {
const listAccessible = vi.fn(async () => ({ items: [], nextCursor: null }))
Object.defineProperty(window, 'clerum', {
diff --git a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts
index 415f4f3fa..47e18dc2b 100644
--- a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts
+++ b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts
@@ -306,6 +306,7 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
const openUriGenerationRef = useRef(0)
const foregroundOpenUriPendingRef = useRef<number | null>(null)
const backgroundOpenUriGenerationRef = useRef(0)
+ const pendingDeniedResourceIdRef = useRef<string | null>(null)
// Any browser-location update supersedes an in-flight URI resolution. This
// includes navigation through the tree/crumbs as well as metadata updates,
// so an older refresh (including a late 403/404) cannot overwrite a newer
@@ -583,18 +584,25 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
}, [queryClient])
const clearInaccessibleGfsLocation = useCallback(() => {
const resourceId = currentCrumbRef.current?.resourceId
- if (resourceId && sessionScope) {
- queryClient.removeQueries({
- exact: true,
- queryKey: desktopQueryKeys.gfsChildren(sessionScope, resourceId, DRIVE),
- })
- }
+ pendingDeniedResourceIdRef.current = resourceId ?? null
// A resource-scoped denial is not loss of the authenticated session.
// Keep accessible roots and other GFS scopes intact, and avoid the
// foreground navigation setter so a background denial cannot advance it.
setCrumbsState([])
setOpenError('This folder or file is no longer available.')
- }, [queryClient, sessionScope])
+ }, [])
+ useEffect(() => {
+ const resourceId = pendingDeniedResourceIdRef.current
+ if (!resourceId || current?.resourceId === resourceId) return
+ pendingDeniedResourceIdRef.current = null
+ if (!sessionScope) return
+ // Remove the denied query after its observer has left the current folder;
+ // removing an active infinite query can transiently expose an empty page.
+ queryClient.removeQueries({
+ exact: true,
+ queryKey: desktopQueryKeys.gfsChildren(sessionScope, resourceId, DRIVE),
+ })
+ }, [current?.resourceId, queryClient, sessionScope])
const revokeAccess = useCallback(() => {
setAccessState('revoked')
clearGfsState()
@@ -993,6 +1001,7 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
}
if (!isCurrent()) return false
+ if (!background) setOpenError(null)
setCrumbsState([...ancestors.reverse(), crumb])
return crumb
} catch (error) {