@devries-cameron20 / t3code-1 / commits / 8fe8f9a9c1
Fork 0

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

fix(mobile): defer filesystem navigation (#4799)

Co-authored-by: codex <codex@users.noreply.github.com>

Julius Marminge committed Jul 29, 2026 at 01:46 UTC 8fe8f9a9c1486528f689a7499c2eb78217d35caf
1 file changed +86 -25
apps/mobile/src/features/projects/AddProjectScreen.tsx
+86 -25
@@ -11,6 +11,8 @@ import {
11 type AddProjectRemoteSource,
12 } from "@t3tools/client-runtime/operations/projects";
13 import {
14 + canPreloadBrowsePath,
15 + createBrowseNavigationCoordinator,
16 filterFilesystemBrowseEntries,
17 getFilesystemBrowsePath,
18 } from "@t3tools/client-runtime/state/filesystem";
@@ -43,7 +45,10 @@ import { useThemeColor } from "../../lib/useThemeColor";
45 import { uuidv4 } from "../../lib/uuid";
46 import { useAtomCommand } from "../../state/use-atom-command";
47 import { useAtomQueryRunner } from "../../state/use-atom-query-runner";
46 -import { useSavedRemoteConnections } from "../../state/use-remote-environment-registry";
48 +import {
49 + useRemoteEnvironmentRuntime,
50 + useSavedRemoteConnections,
51 +} from "../../state/use-remote-environment-registry";
52
53 interface EnvironmentOption {
54 readonly environmentId: EnvironmentId;
@@ -221,6 +226,63 @@ function ProjectPathInput(props: {
226 );
227 }
228
229 +function useBrowsePathInput(environment: EnvironmentOption | null) {
230 + const [pathInput, commitPathInput] = useState(() =>
231 + getAddProjectInitialQuery(environment?.baseDirectory),
232 + );
233 + const environmentRuntime = useRemoteEnvironmentRuntime(environment?.environmentId ?? null);
234 + const loadBrowsePath = useAtomQueryRunner(filesystemEnvironment.browse, {
235 + reportFailure: false,
236 + reportDefect: false,
237 + });
238 + const [browseNavigation] = useState(createBrowseNavigationCoordinator);
239 + const [isBrowseNavigating, setIsBrowseNavigating] = useState(false);
240 + const setPathInput = useCallback(
241 + (path: string) => {
242 + browseNavigation.invalidate();
243 + setIsBrowseNavigating(false);
244 + commitPathInput(path);
245 + },
246 + [browseNavigation],
247 + );
248 + const navigateToBrowsePath = useCallback(
249 + async (path: string) => {
250 + setIsBrowseNavigating(true);
251 + const committed = await browseNavigation.run(
252 + async () => {
253 + if (environment && canPreloadBrowsePath(environmentRuntime?.connectionState)) {
254 + await loadBrowsePath({
255 + environmentId: environment.environmentId,
256 + input: { partialPath: path },
257 + });
258 + }
259 + },
260 + () => commitPathInput(path),
261 + );
262 + if (committed) {
263 + setIsBrowseNavigating(false);
264 + }
265 + return committed;
266 + },
267 + [browseNavigation, environment, environmentRuntime?.connectionState, loadBrowsePath],
268 + );
269 +
270 + useEffect(() => {
271 + if (environment) {
272 + setPathInput(getAddProjectInitialQuery(environment.baseDirectory));
273 + }
274 + }, [environment, setPathInput]);
275 +
276 + useEffect(
277 + () => () => {
278 + browseNavigation.invalidate();
279 + },
280 + [browseNavigation],
281 + );
282 +
283 + return { isBrowseNavigating, pathInput, setPathInput, navigateToBrowsePath };
284 +}
285 +
286 function useEnvironmentOptions(): ReadonlyArray<EnvironmentOption> {
287 const serverConfigByEnvironmentId = useServerConfigs();
288 const { savedConnectionsById } = useSavedRemoteConnections();
@@ -585,6 +647,7 @@ function FolderBrowser(props: {
647 readonly environment: EnvironmentOption;
648 readonly pathInput: string;
649 readonly setPathInput: (path: string) => void;
650 + readonly navigateToBrowsePath: (path: string) => Promise<boolean>;
651 }) {
652 const accentColor = useThemeColor("--color-icon-muted");
653 const browsePath = useMemo(
@@ -633,7 +696,7 @@ function FolderBrowser(props: {
696 right={null}
697 onPress={() => {
698 if (browsePath.parentPath) {
636 - props.setPathInput(browsePath.parentPath);
699 + void props.navigateToBrowsePath(browsePath.parentPath);
700 }
701 }}
702 />
@@ -650,7 +713,7 @@ function FolderBrowser(props: {
713 browsePath.directoryPath.length > 0
714 ? appendBrowsePathSegment(browsePath.directoryPath, entry.name)
715 : ensureBrowseDirectoryPath(entry.fullPath);
653 - props.setPathInput(nextPath);
716 + void props.navigateToBrowsePath(nextPath);
717 }}
718 />
719 ))}
@@ -662,19 +725,13 @@ function FolderBrowser(props: {
725 export function AddProjectLocalFolderScreen(props: { readonly environmentId?: string | string[] }) {
726 const environment = useEnvironmentFromParam(props.environmentId);
727 const createProject = useCreateProject(environment);
665 - const [pathInput, setPathInput] = useState(() =>
666 - getAddProjectInitialQuery(environment?.baseDirectory),
667 - );
728 + const { isBrowseNavigating, navigateToBrowsePath, pathInput, setPathInput } =
729 + useBrowsePathInput(environment);
730 const [isSubmitting, setIsSubmitting] = useState(false);
731 const [error, setError] = useState<string | null>(null);
732
671 - useEffect(() => {
672 - if (!environment) return;
673 - setPathInput(getAddProjectInitialQuery(environment.baseDirectory));
674 - }, [environment]);
675 -
733 const submitPath = useCallback(async () => {
677 - if (!environment || isSubmitting) return;
734 + if (!environment || isBrowseNavigating || isSubmitting) return;
735 setError(null);
736 const resolved = resolveAddProjectPath({
737 rawPath: pathInput,
@@ -692,7 +749,7 @@ export function AddProjectLocalFolderScreen(props: { readonly environmentId?: st
749 setError(errorMessage(Cause.squash(result.cause)));
750 }
751 setIsSubmitting(false);
695 - }, [createProject, environment, isSubmitting, pathInput]);
752 + }, [createProject, environment, isBrowseNavigating, isSubmitting, pathInput]);
753
754 return (
755 <AddProjectShell>
@@ -706,12 +763,13 @@ export function AddProjectLocalFolderScreen(props: { readonly environmentId?: st
763 />
764 <PrimaryActionButton
765 label="Add project"
709 - disabled={isSubmitting}
766 + disabled={isBrowseNavigating || isSubmitting}
767 onPress={() => void submitPath()}
768 loading={isSubmitting}
769 />
770 <FolderBrowser
771 environment={environment}
772 + navigateToBrowsePath={navigateToBrowsePath}
773 pathInput={pathInput}
774 setPathInput={setPathInput}
775 />
@@ -735,19 +793,13 @@ export function AddProjectDestinationScreen(props: {
793 const createProject = useCreateProject(environment);
794 const remoteUrl = stringParam(props.remoteUrl);
795 const repositoryTitle = stringParam(props.repositoryTitle);
738 - const [pathInput, setPathInput] = useState(() =>
739 - getAddProjectInitialQuery(environment?.baseDirectory),
740 - );
796 + const { isBrowseNavigating, navigateToBrowsePath, pathInput, setPathInput } =
797 + useBrowsePathInput(environment);
798 const [isSubmitting, setIsSubmitting] = useState(false);
799 const [error, setError] = useState<string | null>(null);
800
744 - useEffect(() => {
745 - if (!environment) return;
746 - setPathInput(getAddProjectInitialQuery(environment.baseDirectory));
747 - }, [environment]);
748 -
801 const submitPath = useCallback(async () => {
750 - if (!environment || !remoteUrl || isSubmitting) return;
802 + if (!environment || !remoteUrl || isBrowseNavigating || isSubmitting) return;
803 setError(null);
804 const resolved = resolveAddProjectPath({
805 rawPath: pathInput,
@@ -776,7 +828,15 @@ export function AddProjectDestinationScreen(props: {
828 }
829 }
830 setIsSubmitting(false);
779 - }, [cloneRepository, createProject, environment, isSubmitting, pathInput, remoteUrl]);
831 + }, [
832 + cloneRepository,
833 + createProject,
834 + environment,
835 + isBrowseNavigating,
836 + isSubmitting,
837 + pathInput,
838 + remoteUrl,
839 + ]);
840
841 return (
842 <AddProjectShell>
@@ -798,12 +858,13 @@ export function AddProjectDestinationScreen(props: {
858 />
859 <PrimaryActionButton
860 label="Clone project"
801 - disabled={isSubmitting || !remoteUrl}
861 + disabled={isBrowseNavigating || isSubmitting || !remoteUrl}
862 onPress={() => void submitPath()}
863 loading={isSubmitting}
864 />
865 <FolderBrowser
866 environment={environment}
867 + navigateToBrowsePath={navigateToBrowsePath}
868 pathInput={pathInput}
869 setPathInput={setPathInput}
870 />