Skip to content

Commit 4e3e322

Browse files
committed
fix(mobile): split-view inspectors stop re-registering on every render
1 parent e64766c commit 4e3e322

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
@@ -354,6 +354,7 @@ function useThreadFilesWorkspace(params: {
354354
readonly threadId?: string | string[];
355355
readonly cwd?: string | string[];
356356
readonly projectName?: string | string[];
357+
readonly path?: string | string[];
357358
}) {
358359
const routeEnvironmentId = firstRouteParam(params.environmentId);
359360
const routeThreadId = firstRouteParam(params.threadId);
@@ -375,6 +376,7 @@ function useThreadFilesWorkspace(params: {
375376
cwd: routeCwd ?? selectedThreadCwd ?? project?.workspaceRoot ?? null,
376377
environmentId,
377378
projectName: routeProjectName ?? project?.title ?? "Files",
379+
relativePath: normalizeRoutePath(params.path),
378380
selectedThread,
379381
threadId,
380382
};
@@ -585,11 +587,9 @@ export function ThreadFileScreen(props: ThreadFileRouteScreenProps) {
585587
const { appearance, setCodeWordBreak } = useAppearancePreferences();
586588
const iconColor = useUniwindTheme()["--color-icon"];
587589
const params = props.route.params;
588-
const relativePath = normalizeRoutePath(params.path);
589590
const targetLine = normalizeRouteLine(firstRouteParam(params.line));
590-
const { cwd, environmentId, projectName, selectedThread, threadId } = useThreadFilesWorkspace(
591-
props.route.params,
592-
);
591+
const { cwd, environmentId, projectName, relativePath, selectedThread, threadId } =
592+
useThreadFilesWorkspace(props.route.params);
593593
const fileAccessSession = useEnvironmentQuery(
594594
environmentId !== null ? environmentSession.sessionStateAtom(environmentId) : null,
595595
);

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

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

190-
useFocusEffect(() => {
191-
focusedRef.current = true;
192-
syncRegistration();
193-
return () => {
190+
useEffect(() => {
191+
if (navigation === undefined) {
192+
return;
193+
}
194+
const focus = () => {
195+
if (focusedRef.current) {
196+
return;
197+
}
198+
focusedRef.current = true;
199+
syncRegistration();
200+
};
201+
const blur = () => {
194202
focusedRef.current = false;
195203
syncRegistration();
196204
};
197-
});
205+
if (navigation.isFocused()) {
206+
focus();
207+
}
208+
const unsubscribeFocus = navigation.addListener("focus", focus);
209+
const unsubscribeBlur = navigation.addListener("blur", blur);
210+
return () => {
211+
unsubscribeFocus();
212+
unsubscribeBlur();
213+
focusedRef.current = false;
214+
deactivateRef.current?.();
215+
deactivateRef.current = null;
216+
};
217+
}, [navigation]);
198218

199219
useEffect(() => {
200220
if (focusedRef.current) {
201221
syncRegistration();
202222
}
203223
}, [wrappedRender]);
204-
205-
useEffect(
206-
() => () => {
207-
deactivateRef.current?.();
208-
deactivateRef.current = null;
209-
},
210-
[],
211-
);
212224
}
213225

214226
export function AdaptiveWorkspaceLayout(props: {

0 commit comments

Comments
 (0)