Skip to content

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

TypeScript

fix(desktop): isolate remounted app find results (R1-M5)

Josué555d5e93f9f0
diff --git a/desktop-app/ui/src/pages/SandboxUiPage.tsx b/desktop-app/ui/src/pages/SandboxUiPage.tsx
index 92f7783bb..1cd5227f2 100644
--- a/desktop-app/ui/src/pages/SandboxUiPage.tsx
+++ b/desktop-app/ui/src/pages/SandboxUiPage.tsx
@@ -144,6 +144,7 @@ function useEmbedBounds(
const APP_PAGE_SIZE = 6
let pendingSandboxUiUnmountCleanup: number | null = null
+let nextSandboxFindClientRequestId = 0
export function SandboxUiPage({
boundsRefreshKey = 0,
@@ -174,7 +175,6 @@ export function SandboxUiPage({
const [localSearchResult, setLocalSearchResult] = useState({ current: 0, total: 0 })
const embedSlotRef = useRef<HTMLDivElement>(null)
const localSearchInputRef = useRef<HTMLInputElement>(null)
- const nextFindClientRequestIdRef = useRef(0)
const activeFindClientRequestIdRef = useRef<number | null>(null)
const lastLocalSearchRequestIdRef = useRef(0)
const localSearchPreviousFocusRef = useRef<HTMLElement | null>(null)
@@ -257,7 +257,7 @@ export function SandboxUiPage({
return
}
if (!options.findNext) setLocalSearchResult({ current: 0, total: 0 })
- const clientRequestId = ++nextFindClientRequestIdRef.current
+ const clientRequestId = ++nextSandboxFindClientRequestId
activeFindClientRequestIdRef.current = clientRequestId
await window.clerum.sandboxUi.findInPage(query, { ...options, clientRequestId })
},
diff --git a/desktop-app/ui/src/pages/__tests__/SandboxUiPage.test.tsx b/desktop-app/ui/src/pages/__tests__/SandboxUiPage.test.tsx
index 724578147..a4afe9b6d 100644
--- a/desktop-app/ui/src/pages/__tests__/SandboxUiPage.test.tsx
+++ b/desktop-app/ui/src/pages/__tests__/SandboxUiPage.test.tsx
@@ -279,6 +279,49 @@ describe('SandboxUiPage', () => {
await waitFor(() => expect(screen.getByRole('status').textContent).toBe('1/1'))
})
+ it('rejects a queued find result from a prior mounted page', async () => {
+ const listing = {
+ apps: [
+ {
+ appRef: 'sandbox-recipes/sales-crm',
+ title: "Andy's Sales CRM",
+ defaultPath: '/',
+ ready: true,
+ phase: 'active',
+ updatedAt: null,
+ },
+ ],
+ }
+ sandboxUi.listApps.mockResolvedValue(listing)
+ sandboxUi.open.mockResolvedValue(undefined)
+
+ const first = render(<SandboxUiPage localSearchRequestId={1} />)
+ fireEvent.click(await screen.findByRole('button', { name: "Open Andy's Sales CRM" }))
+ fireEvent.change(await screen.findByRole('textbox', { name: 'Find in current app' }), {
+ target: { value: 'old' },
+ })
+ const oldOptions = sandboxUi.findInPage.mock.calls.at(-1)?.[1]
+ const emitOldResult = emitFindResult
+ first.unmount()
+
+ render(<SandboxUiPage localSearchRequestId={1} />)
+ fireEvent.click(await screen.findByRole('button', { name: "Open Andy's Sales CRM" }))
+ fireEvent.change(await screen.findByRole('textbox', { name: 'Find in current app' }), {
+ target: { value: 'new' },
+ })
+ const newOptions = sandboxUi.findInPage.mock.calls.at(-1)?.[1]
+ expect(newOptions.clientRequestId).not.toBe(oldOptions.clientRequestId)
+
+ emitOldResult?.({
+ requestId: 17,
+ clientRequestId: oldOptions.clientRequestId,
+ activeMatchOrdinal: 7,
+ matches: 7,
+ finalUpdate: true,
+ })
+ expect(screen.getByRole('status').textContent).toBe('0/0')
+ })
+
it('opens a deep-linked app at its stable entry point before handing off the client route', async () => {
sandboxUi.listApps.mockResolvedValueOnce({ apps: [] })
sandboxUi.open.mockResolvedValueOnce(undefined)