From a74bb10a1114260988105cdd56176acf506c6ded Mon Sep 17 00:00:00 2001 From: Theo Browne Date: Sun, 26 Jul 2026 15:45:04 -0700 Subject: [PATCH] fix(mobile): keep snoozed rows live across the clock tick MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three memoization defects found in review, all invisible to the pure partition tests: - The iPad row comparator ignored `snoozed`, and a timer wake changes no shell field — so a woken thread that also classified as settled kept its blue countdown and Wake action until an unrelated update landed. - The sidebar's renderListItem closed over `snoozedShelfExpanded` without it in the dep array, so the header always drew the collapsed chevron and count regardless of state. Expansion now travels on the list item itself, which also lets the comparator see it change. - The countdown label was computed inside the memoized row from `new Date()`, so it froze at first render — "2h" stayed "2h" as the wake approached. Both surfaces now compute it against their existing minute tick and pass it down, matching web's snoozeWakeLabelText. Co-Authored-By: Claude Opus 5 (1M context) --- apps/mobile/src/features/home/HomeScreen.tsx | 7 ++++ .../threads/ThreadNavigationSidebar.tsx | 36 ++++++++++++++++--- .../features/threads/thread-list-v2-items.tsx | 10 ++++-- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/apps/mobile/src/features/home/HomeScreen.tsx b/apps/mobile/src/features/home/HomeScreen.tsx index fb389e09d7..7d253ea7a0 100644 --- a/apps/mobile/src/features/home/HomeScreen.tsx +++ b/apps/mobile/src/features/home/HomeScreen.tsx @@ -38,6 +38,7 @@ import { import { ThreadListV2Row, ThreadListV2SnoozedShelfHeader } from "../threads/thread-list-v2-items"; import { buildThreadListV2Items, + snoozeWakeLabel, THREAD_LIST_V2_SETTLED_INITIAL_COUNT, THREAD_LIST_V2_SETTLED_PAGE_COUNT, type ThreadListV2Item, @@ -625,6 +626,11 @@ export function HomeScreen(props: HomeScreenProps) { variant={item.variant} showSettledDivider={item.showSettledDivider} snoozed={item.snoozed} + snoozeWakeLabelText={ + item.snoozed && item.thread.snoozedUntil != null + ? snoozeWakeLabel(item.thread.snoozedUntil, new Date(`${nowMinute}:00.000Z`)) + : undefined + } project={ projectByKey.get(scopedProjectKey(item.thread.environmentId, item.thread.projectId)) ?? null @@ -683,6 +689,7 @@ export function HomeScreen(props: HomeScreenProps) { props.savedConnectionsById, serverConfigs, settlementEnvironmentIds, + nowMinute, snoozeEnvironmentIds, snoozedShelfExpanded, toggleSnoozedShelf, diff --git a/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx b/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx index a5e8f62a4a..f8cfcd3541 100644 --- a/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx +++ b/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx @@ -66,6 +66,7 @@ import { import { ThreadListV2Row, ThreadListV2SnoozedShelfHeader } from "./thread-list-v2-items"; import { buildThreadListV2Items, + snoozeWakeLabel, THREAD_LIST_V2_SETTLED_INITIAL_COUNT, THREAD_LIST_V2_SETTLED_PAGE_COUNT, type ThreadListV2Item, @@ -82,11 +83,19 @@ type SidebarListItem = readonly pendingTask: PendingNewTask; readonly isLast: boolean; } - | { readonly type: "v2-thread"; readonly key: string; readonly item: ThreadListV2Item } + | { + readonly type: "v2-thread"; + readonly key: string; + readonly item: ThreadListV2Item; + /** Precomputed against the minute tick so the row comparator can see + the countdown change; undefined for non-snoozed rows. */ + readonly snoozeWakeLabelText: string | undefined; + } | { readonly type: "v2-snoozed-shelf-header"; readonly key: string; readonly count: number; + readonly expanded: boolean; } | { readonly type: "v2-show-more"; readonly key: string; readonly hiddenCount: number }; @@ -526,10 +535,15 @@ function ThreadNavigationSidebarPane( pendingTask, isLast: index === v2PendingTasks.length - 1, })); + const snoozeLabelNow = new Date(`${nowMinute}:00.000Z`); const threadRows: SidebarListItem[] = threadListV2Layout.items.map((item) => ({ type: "v2-thread" as const, key: scopedThreadKey(item.thread.environmentId, item.thread.id), item, + snoozeWakeLabelText: + item.snoozed && item.thread.snoozedUntil != null + ? snoozeWakeLabel(item.thread.snoozedUntil, snoozeLabelNow) + : undefined, })); // The shelf header is a row of its own: collapsed, it IS the shelf, so // it has no thread row to hang off. splice() handles the all-snoozed @@ -539,6 +553,7 @@ function ThreadNavigationSidebarPane( type: "v2-snoozed-shelf-header", key: "v2-snoozed-shelf-header", count: threadListV2Layout.snoozedCount, + expanded: snoozedShelfExpanded, }); } items.push(...threadRows); @@ -552,10 +567,12 @@ function ThreadNavigationSidebarPane( return items; }, [ listLayout.items, + nowMinute, options.selectedEnvironmentId, pendingTasks, props.searchQuery, selectedProjectRefs, + snoozedShelfExpanded, threadListV2Enabled, threadListV2Layout, ]); @@ -744,14 +761,22 @@ function ThreadNavigationSidebarPane( previous.key === item.key && previous.item.thread === item.item.thread && previous.item.variant === item.item.variant && - previous.item.showSettledDivider === item.item.showSettledDivider + previous.item.showSettledDivider === item.item.showSettledDivider && + // A timer wake is derived from the clock, not from new data: the + // shell reference and variant can both be unchanged while the row + // stops being snoozed. Without this the woken row keeps its blue + // countdown and Wake action. + previous.item.snoozed === item.item.snoozed && + // Same reason for the countdown text: it changes on the minute + // tick while every other field holds still. + previous.snoozeWakeLabelText === item.snoozeWakeLabelText ); } if (previous.type === "v2-show-more" && item.type === "v2-show-more") { return previous.hiddenCount === item.hiddenCount; } if (previous.type === "v2-snoozed-shelf-header" && item.type === "v2-snoozed-shelf-header") { - return previous.count === item.count; + return previous.count === item.count && previous.expanded === item.expanded; } if (previous.type === "v2-pending-task" && item.type === "v2-pending-task") { return previous.pendingTask === item.pendingTask && previous.isLast === item.isLast; @@ -815,6 +840,7 @@ function ThreadNavigationSidebarPane( variant={item.item.variant} showSettledDivider={item.item.showSettledDivider} snoozed={item.item.snoozed} + snoozeWakeLabelText={item.snoozeWakeLabelText} project={projectByKey.get(scopeKey) ?? null} projectTitle={projectTitleByProjectKey.get(scopeKey)} providerDriver={ @@ -857,7 +883,7 @@ function ThreadNavigationSidebarPane( return ( @@ -970,7 +996,9 @@ function ThreadNavigationSidebarPane( sidebarScrollGesture, snoozeEnvironmentIds, snoozeThread, + toggleSnoozedShelf, unsettleThread, + unsnoozeThread, updateGroupDisplay, ], ); diff --git a/apps/mobile/src/features/threads/thread-list-v2-items.tsx b/apps/mobile/src/features/threads/thread-list-v2-items.tsx index b3d3528621..459c09a689 100644 --- a/apps/mobile/src/features/threads/thread-list-v2-items.tsx +++ b/apps/mobile/src/features/threads/thread-list-v2-items.tsx @@ -22,7 +22,6 @@ import { resolveThreadListV2SnoozeGateExpiryMs, resolveThreadListV2Status, resolveThreadListV2SwipeActions, - snoozeWakeLabel, type ThreadListV2Status, } from "./threadListV2"; @@ -151,6 +150,11 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: { readonly showSettledDivider: boolean; /** Snoozed-shelf row: shows its wake time and offers Wake, not Settle. */ readonly snoozed?: boolean; + /** Pre-formatted "wakes in" text for snoozed rows. Computed by the parent + against its minute tick rather than here: this row is memoized, so a + clock read inside it would freeze at first render and the countdown + would never move. Mirrors web's snoozeWakeLabelText prop. */ + readonly snoozeWakeLabelText?: string; readonly project: EnvironmentProject | null; readonly projectTitle?: string; readonly providerDriver: string | null; @@ -540,8 +544,8 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: { )} style={{ fontFamily: MONO_FONT }} > - {snoozedRow && thread.snoozedUntil != null - ? snoozeWakeLabel(thread.snoozedUntil, new Date()) + {snoozedRow && props.snoozeWakeLabelText !== undefined + ? props.snoozeWakeLabelText : relativeTime(thread.latestUserMessageAt ?? thread.updatedAt ?? thread.createdAt)}