Skip to content

Commit 0c3d401

Browse files
committed
fix(mobile): split-view inspectors stop re-registering on every render
1 parent f8bcc3c commit 0c3d401

2 files changed

Lines changed: 29 additions & 17 deletions

File tree

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ function useThreadFilesWorkspace(params: {
349349
readonly threadId?: string | string[];
350350
readonly cwd?: string | string[];
351351
readonly projectName?: string | string[];
352+
readonly path?: string | string[];
352353
}) {
353354
const routeEnvironmentId = firstRouteParam(params.environmentId);
354355
const routeThreadId = firstRouteParam(params.threadId);
@@ -370,6 +371,7 @@ function useThreadFilesWorkspace(params: {
370371
cwd: routeCwd ?? selectedThreadCwd ?? project?.workspaceRoot ?? null,
371372
environmentId,
372373
projectName: routeProjectName ?? project?.title ?? "Files",
374+
relativePath: normalizeRoutePath(params.path),
373375
selectedThread,
374376
threadId,
375377
};
@@ -580,11 +582,9 @@ export function ThreadFileScreen(props: ThreadFileRouteScreenProps) {
580582
const { appearance, setCodeWordBreak } = useAppearancePreferences();
581583
const iconColor = useUniwindTheme()["--color-icon"];
582584
const params = props.route.params;
583-
const relativePath = normalizeRoutePath(params.path);
584585
const targetLine = normalizeRouteLine(firstRouteParam(params.line));
585-
const { cwd, environmentId, projectName, selectedThread, threadId } = useThreadFilesWorkspace(
586-
props.route.params,
587-
);
586+
const { cwd, environmentId, projectName, relativePath, selectedThread, threadId } =
587+
useThreadFilesWorkspace(props.route.params);
588588
const [modeOverride, setModeOverride] = useState<{
589589
readonly path: string;
590590
readonly mode: FileViewMode;

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

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,28 +173,40 @@ export function useRegisterWorkspaceInspector(render: (() => ReactNode) | undefi
173173
deactivateRef.current = registerWorkspaceInspector(wrappedRender);
174174
});
175175

176-
useFocusEffect(() => {
177-
focusedRef.current = true;
178-
syncRegistration();
179-
return () => {
176+
useEffect(() => {
177+
if (navigation === undefined) {
178+
return;
179+
}
180+
const focus = () => {
181+
if (focusedRef.current) {
182+
return;
183+
}
184+
focusedRef.current = true;
185+
syncRegistration();
186+
};
187+
const blur = () => {
180188
focusedRef.current = false;
181189
syncRegistration();
182190
};
183-
});
191+
if (navigation.isFocused()) {
192+
focus();
193+
}
194+
const unsubscribeFocus = navigation.addListener("focus", focus);
195+
const unsubscribeBlur = navigation.addListener("blur", blur);
196+
return () => {
197+
unsubscribeFocus();
198+
unsubscribeBlur();
199+
focusedRef.current = false;
200+
deactivateRef.current?.();
201+
deactivateRef.current = null;
202+
};
203+
}, [navigation]);
184204

185205
useEffect(() => {
186206
if (focusedRef.current) {
187207
syncRegistration();
188208
}
189209
}, [wrappedRender]);
190-
191-
useEffect(
192-
() => () => {
193-
deactivateRef.current?.();
194-
deactivateRef.current = null;
195-
},
196-
[],
197-
);
198210
}
199211

200212
export function AdaptiveWorkspaceLayout(props: {

0 commit comments

Comments
 (0)