The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 14:45 UTC
fix(mobile): @path search no longer offers the previous worktree's files (#36778)
Julius Marminge committed
Nov 14, 2026 at 06:53 UTC
4ce60c162b400b374b12be0450777ab316bb0046
2 files changed
+31
-4
apps/mobile/src/state/queries.debounce.test.tsx
+25
-3
@@ -8,7 +8,8 @@ import { expect, it, vi } from "vite-plus/test";
8
9
const mocks = vi.hoisted(() => ({
10
sessionAtom: {},
11
- searchEntries: vi.fn(() => null),
11
+ searchEntriesAtom: {},
12
+ searchEntries: vi.fn((): unknown => mocks.searchEntriesAtom),
13
listRefs: vi.fn(),
14
refresh: vi.fn(),
15
}));
@@ -35,7 +36,9 @@ vi.mock("./query", () => ({
36
data:
37
atom === mocks.sessionAtom
38
? { authenticated: true, scopes: [AuthFilesystemReadScope] }
38
- : null,
39
+ : atom === mocks.searchEntriesAtom
40
+ ? { entries: [{ path: "src/only-in-original.ts", kind: "file" }] }
41
+ : null,
42
error: null,
43
isPending: false,
44
refresh: () => {},
@@ -53,12 +56,16 @@ function setup() {
56
vi.useFakeTimers();
57
mocks.searchEntries.mockClear();
58
const root = createRoot(document.createElement("div"));
59
+ let latest: ReturnType<typeof useComposerPathSearch> | null = null;
60
function Probe({ target }: { readonly target: ComposerPathSearchTarget }) {
57
- useComposerPathSearch(target);
61
+ latest = useComposerPathSearch(target);
62
return null;
63
}
64
65
return {
66
+ get result() {
67
+ return latest;
68
+ },
69
render(target: ComposerPathSearchTarget) {
70
act(() => root.render(<Probe target={{ ...target }} />));
71
},
@@ -128,6 +135,21 @@ it.each([
135
});
136
});
137
138
+it.each([
139
+ { field: "environment", changed: { ...target, environmentId: EnvironmentId.make("other") } },
140
+ { field: "project directory", changed: { ...target, cwd: "/other" } },
141
+])("reports settled results as pending when the $field changes", ({ changed }) => {
142
+ using harness = setup();
143
+ harness.render(target);
144
+ act(() => vi.advanceTimersByTime(200));
145
+ expect(harness.result?.isPending).toBe(false);
146
+ expect(harness.result?.entries).toHaveLength(1);
147
+
148
+ harness.render(changed);
149
+ expect(harness.result?.isPending).toBe(true);
150
+ expect(harness.result?.entries).toEqual([]);
151
+});
152
+
153
it("keeps compiled branch results stable and resets pagination for a new target or refresh", () => {
154
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
155
const registry = AtomRegistry.make();
apps/mobile/src/state/queries.ts
+6
-1
@@ -440,9 +440,13 @@ export function useComposerPathSearch(target: ComposerPathSearchTarget) {
440
canReadFiles && searchTarget !== null ? projectEnvironment.searchEntries(searchTarget) : null,
441
);
442
const hasTarget = searchTarget !== null;
443
+ const isSameCheckout =
444
+ normalizedTarget.environmentId === debouncedTarget.environmentId &&
445
+ normalizedTarget.cwd === debouncedTarget.cwd;
446
447
return {
445
- entries: result.data?.entries ?? [],
448
+ // Entries from another checkout must not be offered while the new one is debounced.
449
+ entries: isSameCheckout ? (result.data?.entries ?? []) : [],
450
error:
451
!hasTarget || fileAccess.isPending
452
? null
@@ -450,6 +454,7 @@ export function useComposerPathSearch(target: ComposerPathSearchTarget) {
454
? result.error
455
: (fileAccess.error ?? "This connection cannot search host files."),
456
isPending:
457
+ !isSameCheckout ||
458
normalizedTarget.query !== debouncedTarget.query ||
459
(hasTarget && (fileAccess.isPending || result.isPending)),
460
refresh: result.refresh,