The best way to control Claude Code, Codex and more from any computer or phone
fix(mobile): Files search no longer carries into another workspace (#35902)
Julius Marminge committed
Nov 12, 2026 at 20:02 UTC
bedc8658c313f4b870d826598b766408f9216ee6
4 files changed
+104
-6
apps/mobile/src/components/ui/AppBar.tsx
+18
-4
@@ -1,8 +1,8 @@
1
import { Toolbar } from "./Toolbar";
2
import { AppActivityIndicator } from "./AppActivityIndicator";
3
-import type { HeaderBarButtonMailSearchToolbarItem } from "react-native-screens";
3
+import type { HeaderBarButtonMailSearchToolbarItem, SearchBarCommands } from "react-native-screens";
4
import { NavigationContext } from "@react-navigation/native";
5
-import { use, useId, useLayoutEffect } from "react";
5
+import { use, useId, useLayoutEffect, useRef } from "react";
6
import { View } from "react-native";
7
import { createNativeHeaderMenu } from "./nativeHeaderMenu.ios";
8
import { ScreenHeaderButton } from "./ScreenHeaderButton";
@@ -78,6 +78,19 @@ export function AppBar(props: AppBarProps) {
78
const usesNativeMailSearchToolbar = useNativeMailSearchToolbar();
79
const { search, menus } = props;
80
const menu = menus?.[0];
81
+ const searchBarRef = useRef<SearchBarCommands>(null);
82
+ const nativeSearchText = useRef(search?.value ?? "");
83
+ const searchValue = search?.value;
84
+ // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- the native search bar keeps its own text; a value the caller changes (a reset) has to be pushed into it
85
+ useLayoutEffect(() => {
86
+ if (searchValue === undefined || searchValue === nativeSearchText.current) return;
87
+ nativeSearchText.current = searchValue;
88
+ searchBarRef.current?.setText(searchValue);
89
+ }, [searchValue]);
90
+ const reportSearchText = (text: string) => {
91
+ nativeSearchText.current = text;
92
+ search?.onChangeText(text);
93
+ };
94
const compactSearch =
95
search !== undefined &&
96
(search.compactToolbar ?? !layout.usesSplitView) &&
@@ -142,8 +155,9 @@ export function AppBar(props: AppBarProps) {
155
? { obscureBackground: false }
156
: undefined),
157
placeholder: search.placeholder,
145
- onChangeText: (event) => search.onChangeText(event.nativeEvent.text),
146
- onCancelButtonPress: () => search.onChangeText(""),
158
+ ref: searchBarRef,
159
+ onChangeText: (event) => reportSearchText(event.nativeEvent.text),
160
+ onCancelButtonPress: () => reportSearchText(""),
161
},
162
}
163
: undefined),
apps/mobile/src/features/files/thread-file-navigator-pane.test.tsx
new
+79
@@ -0,0 +1,79 @@
1
+import { EnvironmentId } from "@t3tools/contracts";
2
+import { act, type ReactNode } from "react";
3
+import { createRoot } from "react-dom/client";
4
+import { expect, it, vi } from "vite-plus/test";
5
+
6
+const queries = vi.hoisted(() => [] as { cwd: string | null; searchQuery: string }[]);
7
+
8
+vi.mock("@t3tools/client-runtime/state/filesystem", () => ({
9
+ resolveFilesystemReadAccess: () => ({ canReadFiles: true, isPending: false }),
10
+}));
11
+vi.mock("../../state/session", () => ({ environmentSession: { sessionStateAtom: () => null } }));
12
+vi.mock("../../state/query", () => ({ useEnvironmentQuery: () => ({ data: null, error: null }) }));
13
+vi.mock("../../state/presentation", () => ({
14
+ useEnvironmentPresentation: () => ({ isReady: true, presentation: null }),
15
+}));
16
+vi.mock("../settings/appearance/AppearancePreferencesProvider", () => ({
17
+ useAppearancePreferences: () => ({ themeAppearance: "dark" }),
18
+}));
19
+vi.mock("./preload-workspace-file", () => ({ preloadWorkspaceFileContents: () => {} }));
20
+vi.mock("./FileTreeBrowser", () => ({ FileTreeBrowser: () => null }));
21
+vi.mock("./useFileTreeEntries", () => ({
22
+ useFileTreeEntries: (input: { cwd: string | null; searchQuery: string }) => {
23
+ queries.push({ cwd: input.cwd, searchQuery: input.searchQuery });
24
+ return { refresh: () => {}, selectPath: () => {} };
25
+ },
26
+}));
27
+vi.mock("../../components/ui/SheetPane", () => ({
28
+ SheetPane: ({ children }: { children: ReactNode }) => children,
29
+}));
30
+vi.mock("../../components/ui/ScreenContent", () => ({
31
+ ScreenContent: ({ children }: { children: ReactNode }) => children,
32
+}));
33
+vi.mock("../../components/ui/AppBar", () => ({
34
+ AppBar: (props: { search: { value: string; onChangeText: (value: string) => void } }) => (
35
+ <input
36
+ value={props.search.value}
37
+ onChange={(event) => props.search.onChangeText(event.target.value)}
38
+ />
39
+ ),
40
+}));
41
+
42
+import { ThreadFileNavigatorPane } from "./thread-file-navigator-pane";
43
+
44
+it("starts unfiltered when the mounted pane switches to another workspace", () => {
45
+ (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
46
+ const container = document.body.appendChild(document.createElement("div"));
47
+ const root = createRoot(container);
48
+ const render = (cwd: string) =>
49
+ act(() =>
50
+ root.render(
51
+ <ThreadFileNavigatorPane
52
+ cwd={cwd}
53
+ environmentId={EnvironmentId.make("env")}
54
+ projectName="Files"
55
+ selectedPath={null}
56
+ onSelectFile={() => {}}
57
+ />,
58
+ ),
59
+ );
60
+ try {
61
+ render("/first");
62
+ const input = container.querySelector("input")!;
63
+ act(() => {
64
+ Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")!.set!.call(
65
+ input,
66
+ "alpha",
67
+ );
68
+ input.dispatchEvent(new Event("input", { bubbles: true }));
69
+ });
70
+ expect(queries.at(-1)).toEqual({ cwd: "/first", searchQuery: "alpha" });
71
+
72
+ render("/second");
73
+ expect(queries.at(-1)).toEqual({ cwd: "/second", searchQuery: "" });
74
+ expect(container.querySelector("input")!.value).toBe("");
75
+ } finally {
76
+ act(() => root.unmount());
77
+ container.remove();
78
+ }
79
+});
apps/mobile/src/features/files/thread-file-navigator-pane.tsx
+6
-2
@@ -20,7 +20,11 @@ export function ThreadFileNavigatorPane(props: {
20
readonly selectedPath: string | null;
21
readonly onSelectFile: (path: string) => void;
22
}) {
23
- const [searchQuery, setSearchQuery] = useState("");
23
+ const workspaceKey = JSON.stringify([props.environmentId, props.cwd]);
24
+ // The pane stays mounted across thread switches; a query only filters the workspace it was typed in.
25
+ const [search, setSearch] = useState({ workspaceKey, query: "" });
26
+ const searchQuery = search.workspaceKey === workspaceKey ? search.query : "";
27
+ const setSearchQuery = (query: string) => setSearch({ workspaceKey, query });
28
const { themeAppearance: highlightTheme } = useAppearancePreferences();
29
const fileAccessSession = useEnvironmentQuery(
30
environmentSession.sessionStateAtom(props.environmentId),
@@ -48,7 +52,7 @@ export function ThreadFileNavigatorPane(props: {
52
};
53
const fileTree = (
54
<FileTreeBrowser
51
- key={JSON.stringify([props.environmentId, props.cwd])}
55
+ key={workspaceKey}
56
revealSelection={entriesQuery.revealSelection}
57
expandedPaths={entriesQuery.expandedPaths}
58
setExpandedPaths={entriesQuery.setExpandedPaths}
apps/mobile/vite.config.ts
+1
@@ -10,6 +10,7 @@ const reactTests = [
10
"src/state/use-thread-pr.demand.test.tsx",
11
"src/features/threads/git/GitBranchesSheet.occupancy.test.tsx",
12
"src/features/files/useFileTreeEntries.test.tsx",
13
+ "src/features/files/thread-file-navigator-pane.test.tsx",
14
"src/features/files/source-file-document.test.ts",
15
"src/features/projects/AddProjectScreen.test.ts",
16
"src/lib/useMediaVideoPlayback.test.tsx",