Skip to content

Commit 677ff55

Browse files
refactor(mobile): workspace layout reveals the review and files inspector itself
Opening Review or Files in split view revealed the inspector from an effect in each screen (ReviewSheet, ThreadFilesTreeScreen), which set layout state after the workspace had already committed without the inspector, so every open committed the whole workspace tree twice. The layout now derives the reveal in render from the focused workspace route name and thread, once per route and thread, so the first commit already shows the inspector and coming back from a screen pushed over the route keeps the user's choice. useRegisterWorkspaceInspector kept registration in sync with focus through a focus effect, a renderer-change effect, an unmount effect and two refs. One useFocusEffect does the same: it re-runs when the renderer changes while focused, and its cleanup deactivates on blur and unmount. Effects: AdaptiveWorkspaceLayout 5 -> 3, ReviewSheet 1 -> 0, ThreadFilesRouteScreen 1 -> 0. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 96fc7b9 commit 677ff55

3 files changed

Lines changed: 33 additions & 66 deletions

File tree

‎apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { resolveFilesystemReadAccess } from "@t3tools/client-runtime/state/files
44
import { environmentSession } from "../../state/session";
55
import { NativeStackScreenOptions } from "../../native/StackHeader";
66
import { StackActions, useNavigation, type StaticScreenProps } from "@react-navigation/native";
7-
import { useEffect, useId, useRef, useState } from "react";
7+
import { useId, useState } from "react";
88
import { Platform, View } from "react-native";
99
import { useSafeAreaInsets } from "react-native-safe-area-context";
1010
import Svg, { Defs, LinearGradient, Rect, Stop } from "react-native-svg";
@@ -431,14 +431,13 @@ function FilesToolbarBottomFade() {
431431
export function ThreadFilesTreeScreen(props: ThreadFilesRouteScreenProps) {
432432
useAdaptiveWorkspacePaneRole("inspector");
433433
const navigation = useNavigation();
434-
const { fileInspector, layout, showAuxiliaryPane } = useAdaptiveWorkspaceLayout();
434+
const { fileInspector, layout } = useAdaptiveWorkspaceLayout();
435435
const [searchQuery, setSearchQuery] = useState("");
436436
const { themeAppearance: highlightTheme } = useAppearancePreferences();
437437
const { cwd, environmentId, projectName, selectedThread, threadId } = useThreadFilesWorkspace(
438438
props.route.params,
439439
);
440440
const hasFileInspector = fileInspector.supported && threadId !== null;
441-
const revealedInspectorRef = useRef(false);
442441
const fileAccessSession = useEnvironmentQuery(
443442
environmentId !== null ? environmentSession.sessionStateAtom(environmentId) : null,
444443
);
@@ -511,13 +510,6 @@ export function ThreadFilesTreeScreen(props: ThreadFilesRouteScreenProps) {
511510
theme: highlightTheme,
512511
});
513512
};
514-
useEffect(() => {
515-
if (hasFileInspector && cwd !== null && !revealedInspectorRef.current) {
516-
revealedInspectorRef.current = true;
517-
showAuxiliaryPane("inspector");
518-
}
519-
}, [cwd, hasFileInspector, showAuxiliaryPane]);
520-
521513
if (environmentId === null || (threadId !== null && selectedThread === null)) {
522514
if (hasFileInspector) {
523515
return (

‎apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx‎

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,13 @@ import type {
99
import { EnvironmentId, ThreadId, type SidebarProjectGroupingMode } from "@t3tools/contracts";
1010
import { useAtomValue } from "@effect/atom-react";
1111
import { useFocusEffect } from "@react-navigation/native";
12-
import { NavigationContext, NavigationRouteContext, useNavigation } from "@react-navigation/native";
1312
import {
14-
use,
15-
useDeferredValue,
16-
useEffect,
17-
useEffectEvent,
18-
useMemo,
19-
useRef,
20-
useState,
21-
type ReactNode,
22-
} from "react";
13+
NavigationContext,
14+
NavigationRouteContext,
15+
useNavigation,
16+
useNavigationState,
17+
} from "@react-navigation/native";
18+
import { use, useDeferredValue, useEffect, useMemo, useRef, useState, type ReactNode } from "react";
2319
import { Keyboard, Platform, useWindowDimensions, View } from "react-native";
2420
import { KeyboardController, useKeyboardState } from "react-native-keyboard-controller";
2521
import Animated, {
@@ -124,39 +120,11 @@ export function useRegisterWorkspaceInspector(render: (() => ReactNode) | undefi
124120
);
125121
})();
126122

127-
const focusedRef = useRef(false);
128-
const deactivateRef = useRef<(() => void) | null>(null);
129-
130-
const syncRegistration = useEffectEvent(() => {
131-
if (!focusedRef.current || wrappedRender === undefined) {
132-
deactivateRef.current?.();
133-
return;
134-
}
135-
deactivateRef.current = registerWorkspaceInspector(wrappedRender);
136-
});
137-
138-
useFocusEffect(() => {
139-
focusedRef.current = true;
140-
syncRegistration();
141-
return () => {
142-
focusedRef.current = false;
143-
syncRegistration();
144-
};
145-
});
146-
147-
useEffect(() => {
148-
if (focusedRef.current) {
149-
syncRegistration();
150-
}
151-
// oxlint-disable-next-line react/exhaustive-effect-dependencies -- Changed pane content replaces its existing native workspace registration.
152-
}, [wrappedRender]);
153-
154-
useEffect(
155-
() => () => {
156-
deactivateRef.current?.();
157-
deactivateRef.current = null;
158-
},
159-
[],
123+
// useFocusEffect re-runs when the renderer changes while focused, so the
124+
// pane always shows this render's content, and its cleanup deactivates on
125+
// blur and unmount.
126+
useFocusEffect(() =>
127+
wrappedRender === undefined ? undefined : registerWorkspaceInspector(wrappedRender),
160128
);
161129
}
162130

@@ -354,6 +322,24 @@ function AdaptiveWorkspaceLayoutContent(
354322
return null;
355323
}
356324
})();
325+
const workspaceRouteName = useNavigationState(
326+
(state) => state?.routes.find((route) => route.key === props.workspaceRouteKey)?.name,
327+
);
328+
// Opening a review or the files route reveals its inspector once per route
329+
// and thread. Coming back to that route from a screen pushed over it keeps
330+
// the user's choice, so the last revealed key is not cleared on other routes.
331+
const inspectorRevealKey =
332+
(workspaceRouteName === "ThreadReview" ||
333+
(workspaceRouteName === "ThreadFiles" && fileInspector.supported)) &&
334+
selectedThreadKey !== null
335+
? `${props.workspaceRouteKey}:${selectedThreadKey}`
336+
: null;
337+
const [revealedInspectorKey, setRevealedInspectorKey] = useState<string | null>(null);
338+
if (inspectorRevealKey !== null && inspectorRevealKey !== revealedInspectorKey) {
339+
setRevealedInspectorKey(inspectorRevealKey);
340+
setFocusedAuxiliaryPaneRole("inspector");
341+
setFileInspectorPreferredVisible(true);
342+
}
357343
const [workspaceInspector, setWorkspaceInspector] = useState<{
358344
readonly render: () => ReactNode;
359345
readonly active: boolean;

‎apps/mobile/src/features/review/ReviewSheet.tsx‎

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,7 @@ import type { AppBarMenuItem } from "../../components/ui/AppBar.types";
1010
import type { ReviewSectionItem } from "./reviewModel";
1111
import { useReviewHeaderPresentation } from "./useReviewHeaderPresentation";
1212
import { Screen, ScreenStack, ScreenStackHeaderConfig } from "react-native-screens";
13-
import {
14-
type Ref,
15-
type ReactElement,
16-
useEffect,
17-
useImperativeHandle,
18-
useRef,
19-
useState,
20-
} from "react";
13+
import { type Ref, type ReactElement, useImperativeHandle, useRef, useState } from "react";
2114
import {
2215
FlatList,
2316
Platform,
@@ -432,7 +425,7 @@ type ReviewSheetProps = StaticScreenProps<{
432425
export function ReviewSheet(props: ReviewSheetProps) {
433426
const { nativeReviewDiffStyle } = useAppearanceCodeSurface();
434427
useAdaptiveWorkspacePaneRole("inspector");
435-
const { panes, showAuxiliaryPane } = useAdaptiveWorkspaceLayout();
428+
const { panes } = useAdaptiveWorkspaceLayout();
436429
const navigation = useNavigation();
437430
const selectDetail = useSelectWorkspaceDetail();
438431
const insets = useSafeAreaInsets();
@@ -451,10 +444,6 @@ export function ReviewSheet(props: ReviewSheetProps) {
451444
const bottomContentInset =
452445
Platform.OS === "ios" ? safeArea.bottom + 8 : Math.max(insets.bottom, 18) + 18;
453446

454-
useEffect(() => {
455-
showAuxiliaryPane("inspector");
456-
// oxlint-disable-next-line react/exhaustive-effect-dependencies -- Opening review for another thread reselects its inspector pane.
457-
}, [environmentId, showAuxiliaryPane, threadId]);
458447
const {
459448
error,
460449
reviewSections,

0 commit comments

Comments
 (0)