From 5efa2df4abc20f24a63ec73f6559dea632b57f30 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 27 Jun 2026 12:12:33 -0700 Subject: [PATCH] Address mobile review lifecycle issues --- .../t3-review-diff/ios/T3ReviewDiffView.swift | 6 ++++ apps/mobile/plugins/withIosSceneLifecycle.cjs | 22 ++++++++++-- apps/mobile/src/app/_layout.tsx | 6 ---- apps/mobile/src/app/new/_layout.tsx | 2 +- .../features/files/ThreadFilesRouteScreen.tsx | 34 ++++++++++++++----- .../features/threads/ThreadRouteScreen.tsx | 9 +++-- 6 files changed, 60 insertions(+), 19 deletions(-) diff --git a/apps/mobile/modules/t3-review-diff/ios/T3ReviewDiffView.swift b/apps/mobile/modules/t3-review-diff/ios/T3ReviewDiffView.swift index 9a7a5004da..bd023ff348 100644 --- a/apps/mobile/modules/t3-review-diff/ios/T3ReviewDiffView.swift +++ b/apps/mobile/modules/t3-review-diff/ios/T3ReviewDiffView.swift @@ -492,6 +492,8 @@ public final class T3ReviewDiffView: ExpoView, UIScrollViewDelegate { } func setTokensPatchJson(_ tokensPatchJson: String) { + let contentResetKey = self.contentResetKey + payloadDecodeQueue.async { [weak self] in guard let data = tokensPatchJson.data(using: .utf8) else { return @@ -503,6 +505,9 @@ public final class T3ReviewDiffView: ExpoView, UIScrollViewDelegate { guard let self else { return } + guard contentResetKey == self.contentResetKey else { + return + } // A highlighter request from the previous file can finish after the view has // already reset. Never let that stale patch roll the native token state back. if let resetKey = patch.resetKey, resetKey != self.tokensResetKey { @@ -550,6 +555,7 @@ public final class T3ReviewDiffView: ExpoView, UIScrollViewDelegate { } self.contentResetKey = contentResetKey + rowsDecodeGeneration += 1 tokensDecodeGeneration += 1 contentView.tokensByRowId = [:] hasAppliedInitialRowIndex = false diff --git a/apps/mobile/plugins/withIosSceneLifecycle.cjs b/apps/mobile/plugins/withIosSceneLifecycle.cjs index cfb2a159c4..d426475250 100644 --- a/apps/mobile/plugins/withIosSceneLifecycle.cjs +++ b/apps/mobile/plugins/withIosSceneLifecycle.cjs @@ -12,12 +12,23 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { ) { guard let windowScene = scene as? UIWindowScene, - let appDelegate = UIApplication.shared.delegate as? AppDelegate, - let appWindow = appDelegate.window + let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return } + let appWindow: UIWindow + if let existingWindow = appDelegate.window { + appWindow = existingWindow + } else { + appWindow = UIWindow(windowScene: windowScene) + appDelegate.window = appWindow + appDelegate.reactNativeFactory?.startReactNative( + withModuleName: "main", + in: appWindow, + launchOptions: nil) + } + window = appWindow appWindow.windowScene = windowScene appWindow.makeKeyAndVisible() @@ -25,6 +36,13 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { if let url = connectionOptions.urlContexts.first?.url { _ = appDelegate.application(UIApplication.shared, open: url, options: [:]) } + + if let userActivity = connectionOptions.userActivities.first { + _ = appDelegate.application( + UIApplication.shared, + continue: userActivity, + restorationHandler: { _ in }) + } } func scene(_ scene: UIScene, openURLContexts URLContexts: Set) { diff --git a/apps/mobile/src/app/_layout.tsx b/apps/mobile/src/app/_layout.tsx index c0e95c3d3b..7a73725bd9 100644 --- a/apps/mobile/src/app/_layout.tsx +++ b/apps/mobile/src/app/_layout.tsx @@ -16,7 +16,6 @@ import { useResolveClassNames } from "uniwind"; import { LoadingScreen } from "../components/LoadingScreen"; -import { useWorkspaceState } from "../state/workspace"; import { useThreadOutboxDrain } from "../state/use-thread-outbox-drain"; import { RegistryContext } from "@effect/atom-react"; import { appAtomRegistry } from "../state/atom-registry"; @@ -47,16 +46,11 @@ function AppNavigator() { } function AppNavigatorContent() { - const { state } = useWorkspaceState(); const colorScheme = useColorScheme(); const statusBarBg = useThemeColor("--color-status-bar"); useAgentNotificationNavigation(); useThreadOutboxDrain(); - if (state.isLoadingConnections) { - return ; - } - return ( <> router.back()} + onPress={() => router.dismiss()} > diff --git a/apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx b/apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx index c6760cad04..f74f61e8f4 100644 --- a/apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx +++ b/apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx @@ -538,14 +538,6 @@ export function ThreadFilesTreeScreen() { [projectName], ); - if (selectedThread === null || environmentId === null || threadId === null) { - return ; - } - - if (cwd === null) { - return ; - } - if (fileInspector.supported) { return ( ; + } + + if (cwd === null) { + return ; + } + return ( { + if (router.canGoBack()) { + router.back(); + return; + } + if (environmentId !== null && threadId !== null) { + router.replace(buildThreadRoutePath({ environmentId, threadId })); + } + }, [environmentId, router, threadId]); const needsFileContents = relativePath !== null && (resolvedActiveMode === "source" || isMarkdownPreviewFile(relativePath)); @@ -692,6 +701,15 @@ export function ThreadFileScreen() { [cwd, environmentId, fileInspector.supported, handleSelectFile, projectName, relativePath], ); + if (fileInspector.supported && environmentId !== null && threadId !== null) { + return ( + + ); + } + if (selectedThread === null || environmentId === null || threadId === null) { return ; } diff --git a/apps/mobile/src/features/threads/ThreadRouteScreen.tsx b/apps/mobile/src/features/threads/ThreadRouteScreen.tsx index e69294e9ea..5d5f36afc9 100644 --- a/apps/mobile/src/features/threads/ThreadRouteScreen.tsx +++ b/apps/mobile/src/features/threads/ThreadRouteScreen.tsx @@ -418,9 +418,14 @@ function ThreadRouteContent( if (selectedThread === null) { return; } - router.push(buildThreadFilesNavigation(selectedThread, path)); + const navigation = buildThreadFilesNavigation(selectedThread, path); + if (fileInspector.supported) { + router.replace(navigation); + return; + } + router.push(navigation); }, - [router, selectedThread], + [fileInspector.supported, router, selectedThread], ); const GitInspector = useCallback( () => ,