Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-ui): r7-h2 prioritize foreground list loads
Josué887741bd93a1
diff --git a/control-ui/components/GfsBrowser.tsx b/control-ui/components/GfsBrowser.tsxindex f804faf94..617e052a5 100644--- a/control-ui/components/GfsBrowser.tsx+++ b/control-ui/components/GfsBrowser.tsx@@ -53,6 +53,7 @@ import {uploadGfsFileLegacy,} from '@lib/gfsFileUpload'import { gfsImagePreviewMimeType } from '@lib/gfsImagePreview'+import { isCurrentGfsLoad } from '@lib/gfsLoadArbitration'import { isGfsMarkdownPreviewFile } from '@lib/gfsMarkdownPreview'import { isGfsVideoFile } from '@lib/gfsVideoFile'import { gfsVideoPreviewMimeType } from '@lib/gfsVideoPreview'@@ -477,14 +478,21 @@ export function GfsBrowser(): React.JSX.Element {// Background revalidation has its own sequence: it can be superseded by// user navigation, but never invalidates that navigation's request.const navigationSeq = background ? loadSeqRef.current : ++loadSeqRef.current- const backgroundSeqAtStart = backgroundLoadSeqRef.currentconst backgroundSeq = background ? ++backgroundLoadSeqRef.current : undefined+ const loadToken = background+ ? {+ kind: 'background' as const,+ navigationSequence: navigationSeq,+ backgroundSequence: backgroundSeq!,+ }+ : {+ kind: 'foreground' as const,+ navigationSequence: navigationSeq,+ backgroundSequenceAtStart: backgroundLoadSeqRef.current,+ }const isCurrent = () =>!options?.signal?.aborted &&- (background- ? backgroundLoadSeqRef.current === backgroundSeq && loadSeqRef.current === navigationSeq- : loadSeqRef.current === navigationSeq &&- backgroundLoadSeqRef.current === backgroundSeqAtStart)+ isCurrentGfsLoad(loadToken, loadSeqRef.current, backgroundLoadSeqRef.current)if (!background && !cursor) loadedPageCountRef.current = 1if (appending) {setLoadingMore(true)diff --git a/control-ui/lib/__tests__/gfsLoadArbitration.test.ts b/control-ui/lib/__tests__/gfsLoadArbitration.test.tsnew file mode 100644index 000000000..4315a5754--- /dev/null+++ b/control-ui/lib/__tests__/gfsLoadArbitration.test.ts@@ -0,0 +1,23 @@+import { describe, expect, it } from 'vitest'+import { isCurrentGfsLoad } from '../gfsLoadArbitration'++describe('GFS list-load arbitration', () => {+ it('does not let a later background revalidation invalidate a foreground load', () => {+ const foreground = {+ kind: 'foreground' as const,+ navigationSequence: 8,+ backgroundSequenceAtStart: 3,+ }++ expect(isCurrentGfsLoad(foreground, 8, 4)).toBe(true)+ })++ it('lets foreground navigation supersede background work and newer background work supersede older', () => {+ expect(+ isCurrentGfsLoad({ kind: 'background', navigationSequence: 8, backgroundSequence: 4 }, 9, 4)+ ).toBe(false)+ expect(+ isCurrentGfsLoad({ kind: 'background', navigationSequence: 8, backgroundSequence: 3 }, 8, 4)+ ).toBe(false)+ })+})diff --git a/control-ui/lib/gfsLoadArbitration.ts b/control-ui/lib/gfsLoadArbitration.tsnew file mode 100644index 000000000..357caa01e--- /dev/null+++ b/control-ui/lib/gfsLoadArbitration.ts@@ -0,0 +1,15 @@+export type GfsLoadToken =+ | { kind: 'foreground'; navigationSequence: number; backgroundSequenceAtStart: number }+ | { kind: 'background'; navigationSequence: number; backgroundSequence: number }++/** Decide whether a list response still owns the visible folder state. */+export function isCurrentGfsLoad(+ token: GfsLoadToken,+ currentNavigationSequence: number,+ currentBackgroundSequence: number+): boolean {+ return token.kind === 'background'+ ? token.navigationSequence === currentNavigationSequence &&+ token.backgroundSequence === currentBackgroundSequence+ : token.navigationSequence === currentNavigationSequence+}diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex 87aeca9bc..bda43d88c 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.669",+ "version": "0.1.670","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.669",+ "version": "0.1.670","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/frontend-components": "file:../packages/frontend-components",diff --git a/control-ui/package.json b/control-ui/package.jsonindex e29b51a89..11f6fd1e3 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.669",+ "version": "0.1.670","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",