Skip to content

Commit 7e518c8

Browse files
refactor(mobile): thread inspector mode is derived, not synced
ThreadRouteScreen stored the inspector selection together with the thread identity it was picked for, then copied the new identity in after every route change with an effect. Each thread switch therefore rendered once with no inspector mode (deregistering the workspace inspector and letting the auto-close effect see a transient empty state), then rendered again once the effect caught up. Store only the mode the user chose and derive the effective mode in render: "route" applies whenever the route supplies an inspector, a chosen git/files mode carries over, and files drops out when the thread has no working directory. Effects: ThreadRouteScreen.tsx 4 -> 3. Removed the selection sync effect. Kept the auto-close effect: it writes the shared workspace pane preference when this thread has nothing to show, and dropping it would leave the pane preferred-visible, which on non-native split view keeps the primary sidebar suppressed with no inspector beside it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent abf8f43 commit 7e518c8

1 file changed

Lines changed: 14 additions & 38 deletions

File tree

‎apps/mobile/src/features/threads/ThreadRouteScreen.tsx‎

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,6 @@ import {
111111
import type { ThreadInspectorTarget } from "./thread-inspector-navigation";
112112
import { useSelectWorkspaceDetail } from "../workspace/useSelectWorkspaceDetail";
113113

114-
interface ThreadInspectorSelection {
115-
readonly routeThreadIdentity: string | null;
116-
readonly mode: ThreadInspectorMode;
117-
}
118-
119114
function InspectorPaneRoleActivation() {
120115
useAdaptiveWorkspacePaneRole("inspector");
121116
return null;
@@ -435,19 +430,21 @@ function ThreadRouteContent(
435430
const threadId = firstRouteParam(params.threadId);
436431
const routeThreadIdentity =
437432
environmentIdRaw !== null && threadId !== null ? `${environmentIdRaw}:${threadId}` : null;
438-
const [inspectorSelection, setInspectorSelection] = useState<ThreadInspectorSelection | null>(
439-
() => (props.renderInspector ? { routeThreadIdentity, mode: "route" } : null),
440-
);
433+
// The chosen mode survives thread switches; "route" only applies while the route
434+
// supplies an inspector, which is also the default whenever it does.
435+
const [chosenInspectorMode, setChosenInspectorMode] = useState<ThreadInspectorMode | null>(null);
441436
const previewTarget = props.inspectorPresentation ? undefined : params.inspector;
442437
const inspectorMode = (() => {
443438
if (previewTarget) return "preview";
444-
if (inspectorSelection?.routeThreadIdentity === routeThreadIdentity) {
445-
if (inspectorSelection.mode === "files" && selectedThreadCwd === null) {
446-
return null;
447-
}
448-
return inspectorSelection.mode;
449-
}
450-
return null;
439+
const mode =
440+
props.renderInspector === undefined
441+
? chosenInspectorMode === "route"
442+
? null
443+
: chosenInspectorMode
444+
: chosenInspectorMode === null || chosenInspectorMode === "route"
445+
? "route"
446+
: chosenInspectorMode;
447+
return mode === "files" && selectedThreadCwd === null ? null : mode;
451448
})();
452449
useEffect(() => {
453450
if (
@@ -468,24 +465,6 @@ function ThreadRouteContent(
468465
toggleAuxiliaryPane,
469466
]);
470467

471-
useEffect(() => {
472-
// oxlint-disable-next-line react/set-state-in-effect -- Inspector selection follows route ownership but keeps an inspector the user opened.
473-
setInspectorSelection((current) => {
474-
if (props.renderInspector === undefined) {
475-
if (current === null || current.mode === "route") {
476-
return null;
477-
}
478-
return { ...current, routeThreadIdentity };
479-
}
480-
481-
if (current === null || current.mode === "route") {
482-
return { routeThreadIdentity, mode: "route" };
483-
}
484-
485-
return { ...current, routeThreadIdentity };
486-
});
487-
}, [props.renderInspector, routeThreadIdentity]);
488-
489468
const revealPreview = useEffectEvent(() => showAuxiliaryPane("inspector"));
490469
useEffect(() => {
491470
if (previewTarget) revealPreview();
@@ -552,7 +531,7 @@ function ThreadRouteContent(
552531
return;
553532
}
554533
navigation.setParams({ inspector: undefined });
555-
setInspectorSelection({ routeThreadIdentity, mode: "git" });
534+
setChosenInspectorMode("git");
556535
showAuxiliaryPane("inspector");
557536
};
558537
const handleOpenFilesInspector = () => {
@@ -567,10 +546,7 @@ function ThreadRouteContent(
567546
return;
568547
}
569548
navigation.setParams({ inspector: undefined });
570-
setInspectorSelection({
571-
routeThreadIdentity,
572-
mode: props.renderInspector === undefined ? "files" : "route",
573-
});
549+
setChosenInspectorMode(props.renderInspector === undefined ? "files" : "route");
574550
showAuxiliaryPane("inspector");
575551
};
576552
const handleToggleInspector = () => {

0 commit comments

Comments
 (0)