Skip to content

Commit 01223e6

Browse files
perf(mobile): thread rows no longer re-render when another thread streams
useConfirmDeleteThread called no hooks, so the compiler skipped it and the delete handler was a new closure every render. HomeScreen wrapped props callbacks as `props.onX(...)`, which the compiler caches on the whole props object. Together these gave every memoized ThreadListV2Row new handler props on each parent render. The delete confirmation is now a plain function, and HomeScreen passes the callbacks through. The sidebar's select and pull request handlers read destructured callbacks because they also close the open swipe row. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent f2ebeea commit 01223e6

3 files changed

Lines changed: 33 additions & 41 deletions

File tree

‎apps/mobile/src/features/home/HomeScreen.tsx‎

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -415,28 +415,14 @@ export function HomeScreen(props: HomeScreenProps) {
415415
),
416416
);
417417
const handleSettleThread = props.onSettleThread;
418-
const handleSnoozeThread = (thread: EnvironmentThreadShell, snoozedUntil: string) => {
419-
void props.onSnoozeThread(thread, snoozedUntil);
420-
};
421-
const handleUnsnoozeThread = (thread: EnvironmentThreadShell) => {
422-
void props.onUnsnoozeThread(thread);
423-
};
424-
const handlePinThread = (thread: EnvironmentThreadShell) => {
425-
void props.onPinThread(thread);
426-
};
427-
const handleMoveThread = (thread: EnvironmentThreadShell, direction: ThreadMoveDestination) => {
428-
void props.onMoveThread(thread, direction);
429-
};
430-
const handleUnpinThread = (thread: EnvironmentThreadShell) => {
431-
void props.onUnpinThread(thread);
432-
};
433-
const handleSetThreadAutoSettle = (thread: EnvironmentThreadShell, enabled: boolean) => {
434-
void props.onSetThreadAutoSettle(thread, enabled);
435-
};
436-
const handleRegenerateThreadTitle = (thread: EnvironmentThreadShell) => {
437-
void props.onRegenerateThreadTitle(thread);
438-
};
439-
const handleRenameThread = (thread: EnvironmentThreadShell) => props.onRenameThread(thread);
418+
const handleSnoozeThread = props.onSnoozeThread;
419+
const handleUnsnoozeThread = props.onUnsnoozeThread;
420+
const handlePinThread = props.onPinThread;
421+
const handleMoveThread = props.onMoveThread;
422+
const handleUnpinThread = props.onUnpinThread;
423+
const handleSetThreadAutoSettle = props.onSetThreadAutoSettle;
424+
const handleRegenerateThreadTitle = props.onRegenerateThreadTitle;
425+
const handleRenameThread = props.onRenameThread;
440426
const handleDeleteThread = props.onDeleteThread;
441427
const handleUnsettleThread = props.onUnsettleThread;
442428
const [settledVisibleCount, setSettledVisibleCount] = useState(

‎apps/mobile/src/features/home/useThreadListActions.ts‎

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -193,23 +193,24 @@ function useThreadActionExecutor(
193193
return executeAction;
194194
}
195195

196-
function useConfirmDeleteThread(
196+
// A plain function, not a hook: a `use*` function that calls no hooks is skipped by
197+
// the compiler, so the delete handler it returned was a new closure every render.
198+
function confirmThreadDeletion(
197199
executeAction: (action: ThreadListAction, thread: EnvironmentThreadShell) => Promise<boolean>,
200+
thread: EnvironmentThreadShell,
198201
) {
199-
return (thread: EnvironmentThreadShell) => {
200-
if (!checkThreadOperationPermission(thread, actionFailureTitle("delete"))) return;
201-
const title = "Delete thread?";
202-
const message = `“${thread.title}” will be permanently deleted, including its terminal history.`;
203-
Dialog.confirm({
204-
title,
205-
message,
206-
confirmText: "Delete",
207-
destructive: true,
208-
onConfirm: () => {
209-
void executeAction("delete", thread);
210-
},
211-
});
212-
};
202+
if (!checkThreadOperationPermission(thread, actionFailureTitle("delete"))) return;
203+
const title = "Delete thread?";
204+
const message = `“${thread.title}” will be permanently deleted, including its terminal history.`;
205+
Dialog.confirm({
206+
title,
207+
message,
208+
confirmText: "Delete",
209+
destructive: true,
210+
onConfirm: () => {
211+
void executeAction("delete", thread);
212+
},
213+
});
213214
}
214215

215216
export function useThreadListActions(): {
@@ -662,7 +663,8 @@ export function useThreadListActions(): {
662663
return moved;
663664
};
664665

665-
const confirmDeleteThread = useConfirmDeleteThread(executeAction);
666+
const confirmDeleteThread = (thread: EnvironmentThreadShell) =>
667+
confirmThreadDeletion(executeAction, thread);
666668

667669
return {
668670
archiveThread,
@@ -693,7 +695,8 @@ export function useArchivedThreadListActions(
693695
const unarchiveThread = (thread: EnvironmentThreadShell) => {
694696
void executeAction("unarchive", thread);
695697
};
696-
const confirmDeleteThread = useConfirmDeleteThread(executeAction);
698+
const confirmDeleteThread = (thread: EnvironmentThreadShell) =>
699+
confirmThreadDeletion(executeAction, thread);
697700

698701
return { unarchiveThread, confirmDeleteThread };
699702
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,15 +484,18 @@ function ThreadNavigationSidebarPane(
484484
openSwipeableRef.current = null;
485485
}
486486
};
487+
// These close the open row too, so they cannot be pass-throughs. The compiler would
488+
// recache a closure over `props` whenever any prop changed.
489+
const { onSelectThread, onOpenThreadPullRequests } = props;
487490
const handleSelectThread = (thread: EnvironmentThreadShell) => {
488-
props.onSelectThread(thread);
491+
onSelectThread(thread);
489492
openSwipeableRef.current?.close();
490493
};
491494
const handleOpenThreadPullRequests = (
492495
thread: EnvironmentThreadShell,
493496
pr: ThreadPrPresentation,
494497
) => {
495-
props.onOpenThreadPullRequests(thread, pr);
498+
onOpenThreadPullRequests(thread, pr);
496499
openSwipeableRef.current?.close();
497500
};
498501
const handleScrollBeginDrag = () => {

0 commit comments

Comments
 (0)