@devries-cameron20 / t3code-1 / commits / c5332bf14d
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(mobile): stabilize composer search debounce targets (#24272)

Julius Marminge committed Oct 25, 2026 at 11:03 UTC c5332bf14dfb335c9eb08966624d65328e82641a
3 files changed +112 -6
apps/mobile/src/state/queries.debounce.test.tsx new
+105
@@ -0,0 +1,105 @@
1 +import { AuthFilesystemReadScope, EnvironmentId } from "@t3tools/contracts";
2 +import { act } from "react";
3 +import { createRoot } from "react-dom/client";
4 +import { expect, it, vi } from "vite-plus/test";
5 +
6 +const mocks = vi.hoisted(() => ({
7 + sessionAtom: {},
8 + searchEntries: vi.fn(() => null),
9 +}));
10 +
11 +vi.mock("./session", () => ({
12 + environmentSession: { sessionStateAtom: () => mocks.sessionAtom },
13 +}));
14 +vi.mock("./presentation", () => ({
15 + useEnvironmentPresentation: () => ({
16 + isReady: true,
17 + presentation: { connection: { phase: "connected", error: null } },
18 + }),
19 +}));
20 +vi.mock("./pull-requests", () => ({ composerPullRequests: {} }));
21 +vi.mock("./projects", () => ({
22 + projectEnvironment: { searchEntries: mocks.searchEntries },
23 +}));
24 +vi.mock("./atom-registry", () => ({ appAtomRegistry: {} }));
25 +vi.mock("./orchestration", () => ({ orchestrationEnvironment: {} }));
26 +vi.mock("./vcs", () => ({ vcsEnvironment: {} }));
27 +vi.mock("./query", () => ({
28 + useEnvironmentQuery: (atom: unknown) => ({
29 + data:
30 + atom === mocks.sessionAtom
31 + ? { authenticated: true, scopes: [AuthFilesystemReadScope] }
32 + : null,
33 + error: null,
34 + isPending: false,
35 + refresh: () => {},
36 + }),
37 +}));
38 +
39 +import { useComposerPathSearch, type ComposerPathSearchTarget } from "./queries";
40 +
41 +function setup() {
42 + (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
43 + vi.useFakeTimers();
44 + mocks.searchEntries.mockClear();
45 + const root = createRoot(document.createElement("div"));
46 + function Probe({ target }: { readonly target: ComposerPathSearchTarget }) {
47 + useComposerPathSearch(target);
48 + return null;
49 + }
50 +
51 + return {
52 + render(target: ComposerPathSearchTarget) {
53 + act(() => root.render(<Probe target={{ ...target }} />));
54 + },
55 + [Symbol.dispose]() {
56 + act(() => root.unmount());
57 + vi.useRealTimers();
58 + },
59 + };
60 +}
61 +
62 +const target = {
63 + environmentId: EnvironmentId.make("test-environment"),
64 + cwd: "/repo",
65 + query: "src",
66 +};
67 +
68 +it("keeps the original search deadline when rerenders have equivalent targets", () => {
69 + using harness = setup();
70 + harness.render({ ...target, query: null });
71 + harness.render({ ...target, query: " src " });
72 + act(() => vi.advanceTimersByTime(100));
73 + harness.render(target);
74 + act(() => vi.advanceTimersByTime(99));
75 + expect(mocks.searchEntries).not.toHaveBeenCalled();
76 +
77 + act(() => vi.advanceTimersByTime(1));
78 + expect(mocks.searchEntries).toHaveBeenCalledExactlyOnceWith({
79 + environmentId: target.environmentId,
80 + input: { cwd: target.cwd, query: target.query, limit: 20 },
81 + });
82 +});
83 +
84 +it.each([
85 + { field: "environment", changed: { ...target, environmentId: EnvironmentId.make("other") } },
86 + { field: "project directory", changed: { ...target, cwd: "/other" } },
87 + { field: "query", changed: { ...target, query: "test" } },
88 +])("restarts the search deadline when the $field changes", ({ changed }) => {
89 + using harness = setup();
90 + harness.render({ ...target, query: null });
91 + harness.render(target);
92 + act(() => vi.advanceTimersByTime(100));
93 + harness.render(changed);
94 +
95 + act(() => vi.advanceTimersByTime(100));
96 + expect(mocks.searchEntries).not.toHaveBeenCalled();
97 + act(() => vi.advanceTimersByTime(99));
98 + expect(mocks.searchEntries).not.toHaveBeenCalled();
99 +
100 + act(() => vi.advanceTimersByTime(1));
101 + expect(mocks.searchEntries).toHaveBeenCalledExactlyOnceWith({
102 + environmentId: changed.environmentId,
103 + input: { cwd: changed.cwd, query: changed.query, limit: 20 },
104 + });
105 +});
apps/mobile/src/state/queries.ts
+6 -6
@@ -30,7 +30,7 @@ import * as Cause from "effect/Cause";
30 import { turnItemDetailRevision } from "@t3tools/client-runtime/work-log/item-detail";
31 import * as Option from "effect/Option";
32 import { AsyncResult, Atom } from "effect/reactivity";
33 -import { useEffect, useState } from "react";
33 +import { useEffect, useMemo, useState } from "react";
34
35 import { appAtomRegistry } from "./atom-registry";
36 import { orchestrationEnvironment } from "./orchestration";
@@ -370,11 +370,11 @@ export function usePaginatedBranches(target: VcsRefTarget) {
370 }
371
372 export function useComposerPathSearch(target: ComposerPathSearchTarget) {
373 - const normalizedTarget = {
374 - environmentId: target.environmentId,
375 - cwd: target.cwd,
376 - query: normalizeComposerPathSearchQuery(target.query),
377 - };
373 + const query = normalizeComposerPathSearchQuery(target.query);
374 + const normalizedTarget = useMemo(
375 + () => ({ environmentId: target.environmentId, cwd: target.cwd, query }),
376 + [target.environmentId, target.cwd, query],
377 + );
378 const debouncedTarget = useDebouncedValue(normalizedTarget, COMPOSER_PATH_SEARCH_DEBOUNCE_MS);
379 const fileAccessSession = useEnvironmentQuery(
380 debouncedTarget.environmentId === null
apps/mobile/vite.config.ts
+1
@@ -10,6 +10,7 @@ const reactTests = [
10 "src/native/NativeHeaderToolbar.test.tsx",
11 "src/native/useRestingTopOffset.test.tsx",
12 "src/native/useRetryingImageSource.test.tsx",
13 + "src/state/queries.debounce.test.tsx",
14 "src/state/use-selected-thread-git-actions.test.tsx",
15 ];
16