Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): r7-m4 prioritize foreground folder navigation
Josué547320984cd3
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsxindex 03d0c135a..9627d569a 100644--- a/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx+++ b/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx@@ -394,15 +394,11 @@ describe('useGfsBrowserController', () => {const deferredUserNavigation = new Promise<typeof folderB>(resolve => {finishUserNavigation = resolve})- let finishBackgroundRefresh!: (resource: typeof folderA) => void- const deferredBackgroundRefresh = new Promise<typeof folderA>(resolve => {- finishBackgroundRefresh = resolve- })const resolve = vi.fn().mockResolvedValueOnce(folderA).mockImplementationOnce(() => deferredUserNavigation)- .mockImplementationOnce(() => deferredBackgroundRefresh)+ .mockImplementationOnce(() => new Promise<typeof folderA>(() => {}))Object.defineProperty(window, 'clerum', {configurable: true,@@ -429,14 +425,14 @@ describe('useGfsBrowserController', () => {await act(async () => {screen.getByRole('button', { name: 'background refresh current location' }).click()})- await waitFor(() => expect(resolve).toHaveBeenCalledTimes(3))- await act(async () => finishUserNavigation(folderB))-- await waitFor(() => expect(screen.getByTestId('current').textContent).toBe('folder-b'))- await act(async () => finishBackgroundRefresh(folderA))await waitFor(() =>expect(screen.getByTestId('background-refresh-outcome').textContent).toBe('superseded'))+ expect(resolve).toHaveBeenCalledTimes(2)+ await act(async () => finishUserNavigation(folderB))++ await waitFor(() => expect(screen.getByTestId('current').textContent).toBe('folder-b'))+ expect(screen.getByTestId('current-name').textContent).toBe('Folder B')})it('exposes the presented verdict for a failed affordances read, not the IPC wrapper', async () => {diff --git a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.tsindex 3cc5423c2..415f4f3fa 100644--- a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts+++ b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts@@ -304,6 +304,7 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {const [openError, setOpenError] = useState<string | null>(null)const [resolving, setResolving] = useState(false)const openUriGenerationRef = useRef(0)+ const foregroundOpenUriPendingRef = useRef<number | null>(null)const backgroundOpenUriGenerationRef = useRef(0)// Any browser-location update supersedes an in-flight URI resolution. This// includes navigation through the tree/crumbs as well as metadata updates,@@ -311,6 +312,7 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {// location or clear its state.const setCrumbs = useCallback<Dispatch<SetStateAction<GfsCrumb[]>>>(next => {openUriGenerationRef.current += 1+ foregroundOpenUriPendingRef.current = nullsetResolving(false)setCrumbsState(next)}, [])@@ -931,6 +933,10 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {const openUri = useCallback(async (uri: string, options?: { clearIfUnavailable?: boolean; background?: boolean }) => {const background = options?.background === true+ // User navigation owns the location until its authoritative resolution+ // settles. A background refresh that starts before React commits that+ // navigation must not read/commit the old location in the meantime.+ if (background && foregroundOpenUriPendingRef.current !== null) return falseconst generation = background ? openUriGenerationRef.current : ++openUriGenerationRef.currentconst backgroundGeneration = background ? ++backgroundOpenUriGenerationRef.current : undefinedconst isCurrent = () =>@@ -939,6 +945,7 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {(backgroundOpenUriGenerationRef.current === backgroundGeneration &¤tCrumbRef.current?.gfsUri === uri))if (!background) {+ foregroundOpenUriPendingRef.current = generationsetOpenError(null)setResolving(true)}@@ -1007,7 +1014,10 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {}return false} finally {- if (!background && openUriGenerationRef.current === generation) setResolving(false)+ if (!background && foregroundOpenUriPendingRef.current === generation) {+ foregroundOpenUriPendingRef.current = null+ if (openUriGenerationRef.current === generation) setResolving(false)+ }}},[clearInaccessibleGfsLocation, handleAuthorityFailure]