@devries-cameron20 / t3code Mirror · read-only / commits / 737eab244d
Fork 0

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 22, 14:30 UTC

fix(mobile): Add project path survives its host dropping out and returning (#25819)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 27, 2026 at 02:37 UTC 737eab244dc1e30067a1aa8acf9f671fc1c25eea
2 files changed +127 -22
apps/mobile/src/features/projects/AddProjectScreen.test.ts
+100
@@ -686,3 +686,103 @@ describe("local project navigation", () => {
686 },
687 );
688 });
689 +
690 +describe("local folder path", () => {
691 + function findPathInput(
692 + node: ReactNode,
693 + ): { value: string; onChangeText: (value: string) => void } | null {
694 + if (Array.isArray(node)) {
695 + for (const child of node) {
696 + const input = findPathInput(child);
697 + if (input) return input;
698 + }
699 + return null;
700 + }
701 + if (
702 + !isValidElement<{
703 + value?: string;
704 + onChangeText?: (value: string) => void;
705 + onSubmit?: () => void;
706 + children?: ReactNode;
707 + }>(node)
708 + ) {
709 + return null;
710 + }
711 + const { value, onChangeText, onSubmit } = node.props;
712 + if (typeof value === "string" && onChangeText && onSubmit) return { value, onChangeText };
713 + return findPathInput(node.props.children);
714 + }
715 +
716 + function mountLocalFolder() {
717 + state.scopes = new Set([AuthOrchestrationOperateScope]);
718 + state.baseDirectory = "/work";
719 + state.connectionStates = {};
720 + state.environments = [
721 + { environmentId: "environment", environmentLabel: "Environment" },
722 + { environmentId: "another-environment", environmentLabel: "Another environment" },
723 + ];
724 + (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
725 + const root = createRoot(document.createElement("div"));
726 + const renderedPaths: string[] = [];
727 + let input: ReturnType<typeof findPathInput> = null;
728 + function LocalFolderObserver(props: { environmentId?: string }) {
729 + input = findPathInput(AddProjectLocalFolderScreen(props));
730 + if (input) renderedPaths.push(input.value);
731 + return null;
732 + }
733 + return {
734 + renderedPaths,
735 + get path() {
736 + return input?.value;
737 + },
738 + type: (value: string) => act(() => input!.onChangeText(value)),
739 + render: (environmentId?: string) =>
740 + act(() => root.render(createElement(LocalFolderObserver, { environmentId }))),
741 + [Symbol.asyncDispose]: async () => {
742 + await act(() => root.unmount());
743 + state.connectionStates = {};
744 + state.environments = [{ environmentId: "environment", environmentLabel: "Environment" }];
745 + },
746 + };
747 + }
748 +
749 + it("shows the new host's default path on the first render after the host changes", async () => {
750 + await using screen = mountLocalFolder();
751 + await screen.render("environment");
752 + await screen.type("/work/edited");
753 + screen.renderedPaths.length = 0;
754 +
755 + await screen.render("another-environment");
756 +
757 + expect(screen.renderedPaths).not.toContain("/work/edited");
758 + expect(screen.path).toBe("~/");
759 + });
760 +
761 + it("keeps each host's typed path when switching between hosts", async () => {
762 + await using screen = mountLocalFolder();
763 + await screen.render("environment");
764 + await screen.type("/work/a");
765 + await screen.render("another-environment");
766 + await screen.type("~/b");
767 +
768 + await screen.render("environment");
769 + expect(screen.path).toBe("/work/a");
770 + await screen.render("another-environment");
771 + expect(screen.path).toBe("~/b");
772 + });
773 +
774 + it("keeps a typed path when the default host drops out and comes back", async () => {
775 + await using screen = mountLocalFolder();
776 + await screen.render();
777 + expect(screen.path).toBe("~/");
778 + await screen.type("~/code/app");
779 +
780 + state.connectionStates = { "another-environment": "offline" };
781 + await screen.render();
782 + expect(screen.path).toBe("/work/");
783 +
784 + state.connectionStates = {};
785 + await screen.render();
786 + expect(screen.path).toBe("~/code/app");
787 + });
788 +});
apps/mobile/src/features/projects/AddProjectScreen.tsx
+27 -22
@@ -292,23 +292,40 @@ function useBrowsePathInput(environment: EnvironmentOption | null, pinnedDirecto
292 const environmentId = environment?.environmentId ?? null;
293 const environmentBaseDirectory = environment?.baseDirectory ?? null;
294 const clonePathCaseSensitive = !isWindowsPlatform(environment?.platform ?? "");
295 - const [pathInput, commitPathInput] = useState(() =>
296 - getCloneDestinationPath(
297 - getAddProjectInitialQuery(environmentBaseDirectory),
298 - pinnedDirectoryName,
299 - ),
295 + const seedPath = getCloneDestinationPath(
296 + getAddProjectInitialQuery(environmentBaseDirectory),
297 + pinnedDirectoryName,
298 );
301 - const previousEnvironmentIdRef = useRef(environmentId);
299 + // Each host keeps the path last typed or browsed for it, and shows its own default until then,
300 + // so switching hosts and back loses nothing. With no host selected (one dropping out briefly),
301 + // the field keeps the last path typed anywhere.
302 + const [paths, setPaths] = useState<{
303 + readonly byHost: ReadonlyMap<EnvironmentId, string>;
304 + readonly last: string;
305 + }>(() => ({ byHost: new Map(), last: seedPath }));
306 + const pathInput =
307 + environmentId === null ? paths.last : (paths.byHost.get(environmentId) ?? seedPath);
308 + const commitPathInput = (path: string) =>
309 + setPaths((current) => {
310 + const byHost = new Map(current.byHost);
311 + if (environmentId !== null) {
312 + byHost.set(environmentId, path);
313 + }
314 + return { byHost, last: path };
315 + });
316 const environmentRuntime = useRemoteEnvironmentRuntime(environmentId);
317 const loadBrowsePath = useAtomQueryRunner(filesystemEnvironment.browse, {
318 reportFailure: false,
319 reportDefect: false,
320 });
321 const [browseNavigation] = useState(createBrowseNavigationCoordinator);
308 - const [isBrowseNavigating, setIsBrowseNavigating] = useState(false);
322 + const [navigatingEnvironmentId, setNavigatingEnvironmentId] = useState<
323 + EnvironmentId | null | undefined
324 + >(undefined);
325 + const isBrowseNavigating = navigatingEnvironmentId === environmentId;
326 const setPathInput = (path: string) => {
327 browseNavigation.invalidate();
311 - setIsBrowseNavigating(false);
328 + setNavigatingEnvironmentId(undefined);
329 commitPathInput(path);
330 };
331 const navigateToBrowsePath = async (input: {
@@ -327,7 +344,7 @@ function useBrowsePathInput(environment: EnvironmentOption | null, pinnedDirecto
344 caseSensitive: clonePathCaseSensitive,
345 })
346 : getCloneDestinationPath(selectedDirectoryPath, pinnedDirectoryName);
330 - setIsBrowseNavigating(true);
347 + setNavigatingEnvironmentId(environmentId);
348 const committed = await browseNavigation.run(
349 async () => {
350 if (
@@ -344,23 +361,11 @@ function useBrowsePathInput(environment: EnvironmentOption | null, pinnedDirecto
361 () => commitPathInput(nextPathInput),
362 );
363 if (committed) {
347 - setIsBrowseNavigating(false);
364 + setNavigatingEnvironmentId(undefined);
365 }
366 return committed;
367 };
368
352 - useEffect(() => {
353 - if (environmentId !== null && environmentId !== previousEnvironmentIdRef.current) {
354 - previousEnvironmentIdRef.current = environmentId;
355 - setPathInput(
356 - getCloneDestinationPath(
357 - getAddProjectInitialQuery(environmentBaseDirectory),
358 - pinnedDirectoryName,
359 - ),
360 - );
361 - }
362 - }, [environmentBaseDirectory, environmentId, pinnedDirectoryName, setPathInput]);
363 -
369 useEffect(
370 () => () => {
371 browseNavigation.invalidate();