@devries-cameron20 / t3code-1 / commits / 325a7e2ae4
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(mobile): the split-view sidebar no longer crashes in an update loop (#21867)

Alex committed Oct 19, 2026 at 13:32 UTC 325a7e2ae4bf504cdaeb7b842e88b47f60b4bf59
2 files changed +80 -35
apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
+51 -19
@@ -17,6 +17,7 @@ import {
17 use,
18 useEffect,
19 useEffectEvent,
20 + useMemo,
21 useRef,
22 useState,
23 type ReactNode,
@@ -247,7 +248,14 @@ function AdaptiveWorkspaceLayoutContent(
248 const [primarySidebarSearchQuery, setPrimarySidebarSearchQuery] = useState("");
249 const [focusedAuxiliaryPaneRole, setFocusedAuxiliaryPaneRole] =
250 useState<WorkspaceAuxiliaryPaneRole | null>(null);
250 - const baseLayout = deriveLayout({ width: viewportWidth, height, nativeMetrics });
251 + // The compiler can't memoize these derivations: they stay live across later hook calls. Fresh
252 + // objects here change the workspace context on every render, so every workspace screen
253 + // re-renders on any layout state change, and the inspector registration then loops: each
254 + // re-register re-renders its screen, which hands over a new inspector renderer.
255 + const baseLayout = useMemo(
256 + () => deriveLayout({ width: viewportWidth, height, nativeMetrics }),
257 + [height, viewportWidth, nativeMetrics],
258 + );
259 const primarySidebarPinned = isPrimarySidebarPinned({
260 pathname,
261 nativeWorkspace,
@@ -260,17 +268,30 @@ function AdaptiveWorkspaceLayoutContent(
268 setHinge(next);
269 setWindowHinge(nextWindow);
270 };
263 - const layout = alignListPaneToHinge({ layout: baseLayout, hinge, viewportWidth });
271 + const layout = useMemo(
272 + () => alignListPaneToHinge({ layout: baseLayout, hinge, viewportWidth }),
273 + [baseLayout, hinge, viewportWidth],
274 + );
275 const shouldRenderPrimarySidebar = layout.usesSplitView;
265 - const fileInspector = deriveFileInspectorPaneLayout({
266 - layout,
267 - viewportWidth,
268 - preferredWidth: fileInspectorPreferredWidth ?? undefined,
269 - reservedLeadingWidth:
270 - shouldRenderPrimarySidebar && showPrimarySidebar
271 - ? (layout.listPaneWidth ?? 0) + (layout.listPaneGap ?? 0)
272 - : 0,
273 - });
276 + const fileInspector = useMemo(
277 + () =>
278 + deriveFileInspectorPaneLayout({
279 + layout,
280 + viewportWidth,
281 + preferredWidth: fileInspectorPreferredWidth ?? undefined,
282 + reservedLeadingWidth:
283 + shouldRenderPrimarySidebar && showPrimarySidebar
284 + ? (layout.listPaneWidth ?? 0) + (layout.listPaneGap ?? 0)
285 + : 0,
286 + }),
287 + [
288 + fileInspectorPreferredWidth,
289 + layout,
290 + showPrimarySidebar,
291 + shouldRenderPrimarySidebar,
292 + viewportWidth,
293 + ],
294 + );
295 const auxiliaryPaneRole: WorkspaceAuxiliaryPaneRole =
296 focusedAuxiliaryPaneRole ?? (/\/files(?:\/|$)/.test(pathname) ? "inspector" : "supplementary");
297 const auxiliaryPanePreferredVisible =
@@ -281,14 +302,25 @@ function AdaptiveWorkspaceLayoutContent(
302 auxiliaryPaneRole === "inspector"
303 ? fileInspectorPreferredWidth
304 : supplementaryPanePreferredWidth;
284 - const panes = deriveWorkspacePaneLayout({
285 - layout,
286 - viewportWidth,
287 - primarySidebarPreferredVisible: showPrimarySidebar,
288 - auxiliaryPanePreferredVisible,
289 - auxiliaryPaneRole,
290 - auxiliaryPanePreferredWidth: auxiliaryPanePreferredWidth ?? undefined,
291 - });
305 + const panes = useMemo(
306 + () =>
307 + deriveWorkspacePaneLayout({
308 + layout,
309 + viewportWidth,
310 + primarySidebarPreferredVisible: showPrimarySidebar,
311 + auxiliaryPanePreferredVisible,
312 + auxiliaryPaneRole,
313 + auxiliaryPanePreferredWidth: auxiliaryPanePreferredWidth ?? undefined,
314 + }),
315 + [
316 + auxiliaryPanePreferredVisible,
317 + auxiliaryPaneRole,
318 + auxiliaryPanePreferredWidth,
319 + layout,
320 + showPrimarySidebar,
321 + viewportWidth,
322 + ],
323 + );
324 const activeThread = parseActiveThreadPath(pathname);
325 const environmentId = activeThread?.environmentId ?? null;
326 const threadId = activeThread?.threadId ?? null;
apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx
+29 -16
@@ -13,7 +13,7 @@ import {
13 import { LegendList } from "@legendapp/list/react-native";
14 import type { MenuAction } from "@react-native-menu/menu";
15 import { useAtomValue } from "@effect/atom-react";
16 -import { useEffect, useRef, useState } from "react";
16 +import { useEffect, useMemo, useRef, useState } from "react";
17 import type { LayoutChangeEvent, TextInputInstance } from "react-native";
18 import { Platform, StyleSheet, TextInput, View } from "react-native";
19 import { GestureDetector, useNativeGesture } from "react-native-gesture-handler";
@@ -180,7 +180,9 @@ function ThreadNavigationSidebarPane(
180 ? [options.selectedEnvironmentId]
181 : [];
182 const threadSearch = useThreadSearch(searchEnvironmentIds, props.searchQuery);
183 - const threadSearchMatchByKey = (() => {
183 + // These maps reach LegendList's extraData, which re-renders every row whenever it changes
184 + // identity. The compiler leaves them unmemoized because they stay live across later hook calls.
185 + const threadSearchMatchByKey = useMemo(() => {
186 const matches = new Map<string, EnvironmentThreadSearchMatch>();
187 for (const match of threadSearch.matches) {
188 if (match.source === "user" || match.source === "assistant") {
@@ -188,7 +190,7 @@ function ThreadNavigationSidebarPane(
190 }
191 }
192 return matches;
191 - })();
193 + }, [threadSearch.matches]);
194 const matchedThreadKeys = new Set(threadSearch.matches.map(threadSearchMatchKey));
195 const projectScopeKey = options.selectedProjectKey;
196 const resolvedProjectKey = resolveScratchProjectScopeKey(projectScopeKey, projects, {
@@ -200,22 +202,33 @@ function ThreadNavigationSidebarPane(
202 setSelectedProjectKey(resolvedProjectKey);
203 }
204 }, [projectScopeKey, resolvedProjectKey, setSelectedProjectKey]);
203 - const projectScopes = buildHomeProjectScopes({
204 - projects,
205 - environmentId: options.selectedEnvironmentId,
206 - projectGroupingMode: options.projectGroupingMode,
207 - });
205 + const projectScopes = useMemo(
206 + () =>
207 + buildHomeProjectScopes({
208 + projects,
209 + environmentId: options.selectedEnvironmentId,
210 + projectGroupingMode: options.projectGroupingMode,
211 + }),
212 + [projects, options.selectedEnvironmentId, options.projectGroupingMode],
213 + );
214 const projectFilterOptions = projectScopes.map((scope) => ({
215 key: scope.key,
216 label: scope.title,
217 }));
212 - const projectTitleByProjectKey = new Map(
213 - projectScopes.flatMap((scope) =>
214 - scope.projectRefs.map(
215 - (projectRef) =>
216 - [scopedProjectKey(projectRef.environmentId, projectRef.projectId), scope.title] as const,
218 + const projectTitleByProjectKey = useMemo(
219 + () =>
220 + new Map(
221 + projectScopes.flatMap((scope) =>
222 + scope.projectRefs.map(
223 + (projectRef) =>
224 + [
225 + scopedProjectKey(projectRef.environmentId, projectRef.projectId),
226 + scope.title,
227 + ] as const,
228 + ),
229 + ),
230 ),
218 - ),
231 + [projectScopes],
232 );
233 const selectedProjectScope =
234 projectScopes.find((scope) => scope.key === resolvedProjectKey) ?? null;
@@ -228,13 +241,13 @@ function ThreadNavigationSidebarPane(
241 scopedProjectKey(projectRef.environmentId, projectRef.projectId),
242 ),
243 );
231 - const projectByKey = (() => {
244 + const projectByKey = useMemo(() => {
245 const map = new Map<string, EnvironmentProject>();
246 for (const project of projects) {
247 map.set(scopedProjectKey(project.environmentId, project.id), project);
248 }
249 return map;
237 - })();
250 + }, [projects]);
251
252 const [settledVisibleCount, setSettledVisibleCount] = useState(
253 THREAD_LIST_V2_SETTLED_INITIAL_COUNT,