Skip to content

Commit 4b2cebf

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 and the sidebar 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 the handlers read the destructured callbacks they call. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent f2ebeea commit 4b2cebf

3 files changed

Lines changed: 44 additions & 27 deletions

File tree

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -415,28 +415,40 @@ export function HomeScreen(props: HomeScreenProps) {
415415
),
416416
);
417417
const handleSettleThread = props.onSettleThread;
418+
// Destructured so each handler below caches on the one callback it calls; a
419+
// `props.onX(...)` closure would be rebuilt whenever any prop changes.
420+
const {
421+
onSnoozeThread,
422+
onUnsnoozeThread,
423+
onPinThread,
424+
onMoveThread,
425+
onUnpinThread,
426+
onSetThreadAutoSettle,
427+
onRegenerateThreadTitle,
428+
onRenameThread,
429+
} = props;
418430
const handleSnoozeThread = (thread: EnvironmentThreadShell, snoozedUntil: string) => {
419-
void props.onSnoozeThread(thread, snoozedUntil);
431+
void onSnoozeThread(thread, snoozedUntil);
420432
};
421433
const handleUnsnoozeThread = (thread: EnvironmentThreadShell) => {
422-
void props.onUnsnoozeThread(thread);
434+
void onUnsnoozeThread(thread);
423435
};
424436
const handlePinThread = (thread: EnvironmentThreadShell) => {
425-
void props.onPinThread(thread);
437+
void onPinThread(thread);
426438
};
427439
const handleMoveThread = (thread: EnvironmentThreadShell, direction: ThreadMoveDestination) => {
428-
void props.onMoveThread(thread, direction);
440+
void onMoveThread(thread, direction);
429441
};
430442
const handleUnpinThread = (thread: EnvironmentThreadShell) => {
431-
void props.onUnpinThread(thread);
443+
void onUnpinThread(thread);
432444
};
433445
const handleSetThreadAutoSettle = (thread: EnvironmentThreadShell, enabled: boolean) => {
434-
void props.onSetThreadAutoSettle(thread, enabled);
446+
void onSetThreadAutoSettle(thread, enabled);
435447
};
436448
const handleRegenerateThreadTitle = (thread: EnvironmentThreadShell) => {
437-
void props.onRegenerateThreadTitle(thread);
449+
void onRegenerateThreadTitle(thread);
438450
};
439-
const handleRenameThread = (thread: EnvironmentThreadShell) => props.onRenameThread(thread);
451+
const handleRenameThread = (thread: EnvironmentThreadShell) => onRenameThread(thread);
440452
const handleDeleteThread = props.onDeleteThread;
441453
const handleUnsettleThread = props.onUnsettleThread;
442454
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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,15 +484,17 @@ function ThreadNavigationSidebarPane(
484484
openSwipeableRef.current = null;
485485
}
486486
};
487+
// Destructured so the row handlers cache on these callbacks, not on `props`.
488+
const { onSelectThread, onOpenThreadPullRequests } = props;
487489
const handleSelectThread = (thread: EnvironmentThreadShell) => {
488-
props.onSelectThread(thread);
490+
onSelectThread(thread);
489491
openSwipeableRef.current?.close();
490492
};
491493
const handleOpenThreadPullRequests = (
492494
thread: EnvironmentThreadShell,
493495
pr: ThreadPrPresentation,
494496
) => {
495-
props.onOpenThreadPullRequests(thread, pr);
497+
onOpenThreadPullRequests(thread, pr);
496498
openSwipeableRef.current?.close();
497499
};
498500
const handleScrollBeginDrag = () => {

0 commit comments

Comments
 (0)