Skip to content

Commit 65443bc

Browse files
fix(mobile): carry row-derived list state on v2 items for recycled cells
A LegendList cell ignores the render closure while itemsAreEqual says the item is unchanged, so anything the row renders or menus that lives outside the item goes stale under recycling. Auditing the swap surfaced four: - the queued-outbox icon (an outbox write never touches the thread shell), - the card menu's move up/down availability (a reorder in flight, or its commit, changes availability without a shell update), - the shelf headers' preference-loading disabled state (a recycled header would keep the state it mounted with), and - the swipe-revealed snooze preset menu, which exists on slim settled rows too (the variant only swaps the primary action), so the menu minute clock was wrongly gated off them. Stamp all four onto the list items in buildThreadListV2ListItems (queued keys and move availability arrive as builder inputs the screens already compute) so they flow through the same equality that gates cell re-renders, and gate the snooze minute clock on actual snooze availability rather than row variant.
1 parent 9f45f72 commit 65443bc

4 files changed

Lines changed: 240 additions & 36 deletions

File tree

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

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,23 @@ export function HomeScreen(props: HomeScreenProps) {
699699
nowMinute,
700700
snoozeWakeTick,
701701
]);
702+
// Move up/down availability stamped onto the list items (see
703+
// buildThreadListV2ListItems): a recycled cell ignores the render closure,
704+
// so availability that changes without a shell update — a reorder in
705+
// flight, its commit — has to ride on the item through list equality.
706+
const resolveMoveAvailability = useCallback(
707+
(thread: EnvironmentThreadShell) => {
708+
if (pendingOrder !== null) return { canMoveUp: false, canMoveDown: false };
709+
const planner =
710+
thread.pinnedAt != null ? threadMovePlanners.pinned : threadMovePlanners.active;
711+
const movedId = `${thread.environmentId}:${thread.id}`;
712+
return {
713+
canMoveUp: planner(movedId, "up") !== null,
714+
canMoveDown: planner(movedId, "down") !== null,
715+
};
716+
},
717+
[pendingOrder, threadMovePlanners],
718+
);
702719
const threadListV2Layout = useMemo(() => {
703720
if (!threadListV2Enabled)
704721
return {
@@ -792,10 +809,16 @@ export function HomeScreen(props: HomeScreenProps) {
792809
settledShelfHeaderIndex: threadListV2Layout.settledShelfHeaderIndex,
793810
snoozeLabelNow: `${nowMinute}:00.000Z`,
794811
snoozeEnvironmentIds,
812+
queuedThreadKeys,
813+
resolveMoveAvailability,
814+
shelfPreferencesLoading: !shelfPreferencesLoaded,
795815
}),
796816
[
797817
nowMinute,
818+
queuedThreadKeys,
819+
resolveMoveAvailability,
798820
settledShelfExpanded,
821+
shelfPreferencesLoaded,
799822
snoozedShelfExpanded,
800823
snoozeEnvironmentIds,
801824
threadListV2Layout,
@@ -838,7 +861,7 @@ export function HomeScreen(props: HomeScreenProps) {
838861
return (
839862
<ThreadListV2SnoozedShelfHeader
840863
count={item.count}
841-
disabled={!shelfPreferencesLoaded}
864+
disabled={item.disabled}
842865
expanded={item.expanded}
843866
onToggle={toggleSnoozedShelf}
844867
/>
@@ -848,21 +871,19 @@ export function HomeScreen(props: HomeScreenProps) {
848871
return (
849872
<ThreadListV2SettledShelfHeader
850873
count={item.count}
851-
disabled={!shelfPreferencesLoaded}
874+
disabled={item.disabled}
852875
expanded={item.expanded}
853876
onToggle={toggleSettledShelf}
854877
/>
855878
);
856879
}
857880
const thread = item.item.thread;
858-
const movePlanner = item.item.pinned ? threadMovePlanners.pinned : threadMovePlanners.active;
859-
const movedId = `${thread.environmentId}:${thread.id}`;
860881
return (
861882
<ThreadListV2Row
862883
onNewThreadOnBranch={props.onNewThreadOnBranch}
863884
thread={thread}
864885
variant={item.item.variant}
865-
hasQueuedMessages={queuedThreadKeys.has(movedId)}
886+
hasQueuedMessages={item.hasQueuedMessages}
866887
snoozed={item.item.snoozed}
867888
pinned={item.item.pinned}
868889
snoozePresetMinute={item.snoozePresetMinute ?? ""}
@@ -904,8 +925,8 @@ export function HomeScreen(props: HomeScreenProps) {
904925
? pinReorderEnvironmentIds.has(thread.environmentId)
905926
: activeReorderEnvironmentIds.has(thread.environmentId)
906927
}
907-
canMoveUp={pendingOrder === null && movePlanner(movedId, "up") !== null}
908-
canMoveDown={pendingOrder === null && movePlanner(movedId, "down") !== null}
928+
canMoveUp={item.canMoveUp}
929+
canMoveDown={item.canMoveDown}
909930
onSnoozeThread={handleSnoozeThread}
910931
onUnsnoozeThread={handleUnsnoozeThread}
911932
onUnsettleThread={handleUnsettleThread}
@@ -920,9 +941,6 @@ export function HomeScreen(props: HomeScreenProps) {
920941
[
921942
handleDeleteThread,
922943
activeReorderEnvironmentIds,
923-
threadMovePlanners,
924-
pendingOrder,
925-
queuedThreadKeys,
926944
handleMoveThread,
927945
handlePinThread,
928946
handleRegenerateThreadTitle,
@@ -945,7 +963,6 @@ export function HomeScreen(props: HomeScreenProps) {
945963
props.onNewThreadOnBranch,
946964
props.savedConnectionsById,
947965
resolveProviderInstance,
948-
shelfPreferencesLoaded,
949966
settlementEnvironmentIds,
950967
snoozeEnvironmentIds,
951968
threadSearchMatchByKey,

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

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,23 @@ function ThreadNavigationSidebarPane(
524524
nowMinute,
525525
snoozeWakeTick,
526526
]);
527+
// Move up/down availability stamped onto the list items (see
528+
// buildThreadListV2ListItems): a recycled cell ignores the render closure,
529+
// so availability that changes without a shell update — a reorder in
530+
// flight, its commit — has to ride on the item through list equality.
531+
const resolveMoveAvailability = useCallback(
532+
(thread: EnvironmentThreadShell) => {
533+
if (pendingOrder !== null) return { canMoveUp: false, canMoveDown: false };
534+
const planner =
535+
thread.pinnedAt != null ? threadMovePlanners.pinned : threadMovePlanners.active;
536+
const movedId = `${thread.environmentId}:${thread.id}`;
537+
return {
538+
canMoveUp: planner(movedId, "up") !== null,
539+
canMoveDown: planner(movedId, "down") !== null,
540+
};
541+
},
542+
[pendingOrder, threadMovePlanners],
543+
);
527544
const threadListV2Layout = useMemo(() => {
528545
if (!threadListV2Enabled)
529546
return {
@@ -613,6 +630,9 @@ function ThreadNavigationSidebarPane(
613630
settledShelfHeaderIndex: threadListV2Layout.settledShelfHeaderIndex,
614631
snoozeLabelNow: `${nowMinute}:00.000Z`,
615632
snoozeEnvironmentIds,
633+
queuedThreadKeys,
634+
resolveMoveAvailability,
635+
shelfPreferencesLoading: !shelfPreferencesLoaded,
616636
});
617637
if (settledShelfExpanded && threadListV2Layout.hiddenSettledCount > 0) {
618638
items.push({
@@ -628,8 +648,11 @@ function ThreadNavigationSidebarPane(
628648
options.selectedEnvironmentId,
629649
pendingTasks,
630650
props.searchQuery,
651+
queuedThreadKeys,
652+
resolveMoveAvailability,
631653
selectedProjectRefs,
632654
settledShelfExpanded,
655+
shelfPreferencesLoaded,
633656
snoozedShelfExpanded,
634657
snoozeEnvironmentIds,
635658
threadListV2Enabled,
@@ -886,17 +909,13 @@ function ThreadNavigationSidebarPane(
886909
}
887910
case "v2-thread": {
888911
const thread = item.item.thread;
889-
const movePlanner = item.item.pinned
890-
? threadMovePlanners.pinned
891-
: threadMovePlanners.active;
892-
const movedId = `${thread.environmentId}:${thread.id}`;
893912
const scopeKey = scopedProjectKey(thread.environmentId, thread.projectId);
894913
return (
895914
<ThreadListV2Row
896915
onNewThreadOnBranch={props.onNewThreadOnBranch}
897916
thread={thread}
898917
variant={item.item.variant}
899-
hasQueuedMessages={queuedThreadKeys.has(`${thread.environmentId}:${thread.id}`)}
918+
hasQueuedMessages={item.hasQueuedMessages}
900919
snoozed={item.item.snoozed}
901920
pinned={item.item.pinned}
902921
snoozePresetMinute={item.snoozePresetMinute ?? ""}
@@ -938,8 +957,8 @@ function ThreadNavigationSidebarPane(
938957
? pinReorderEnvironmentIds.has(thread.environmentId)
939958
: activeReorderEnvironmentIds.has(thread.environmentId)
940959
}
941-
canMoveUp={pendingOrder === null && movePlanner(movedId, "up") !== null}
942-
canMoveDown={pendingOrder === null && movePlanner(movedId, "down") !== null}
960+
canMoveUp={item.canMoveUp}
961+
canMoveDown={item.canMoveDown}
943962
onSnoozeThread={snoozeThread}
944963
onUnsnoozeThread={unsnoozeThread}
945964
onUnsettleThread={unsettleThread}
@@ -956,7 +975,7 @@ function ThreadNavigationSidebarPane(
956975
return (
957976
<ThreadListV2SnoozedShelfHeader
958977
count={item.count}
959-
disabled={!shelfPreferencesLoaded}
978+
disabled={item.disabled}
960979
expanded={item.expanded}
961980
onToggle={toggleSnoozedShelf}
962981
pane="sidebar"
@@ -966,7 +985,7 @@ function ThreadNavigationSidebarPane(
966985
return (
967986
<ThreadListV2SettledShelfHeader
968987
count={item.count}
969-
disabled={!shelfPreferencesLoaded}
988+
disabled={item.disabled}
970989
expanded={item.expanded}
971990
onToggle={toggleSettledShelf}
972991
pane="sidebar"
@@ -1063,8 +1082,6 @@ function ThreadNavigationSidebarPane(
10631082
[
10641083
archiveThread,
10651084
activeReorderEnvironmentIds,
1066-
threadMovePlanners,
1067-
pendingOrder,
10681085
queuedThreadKeys,
10691086
confirmDeletePendingTask,
10701087
confirmDeleteThread,
@@ -1087,7 +1104,6 @@ function ThreadNavigationSidebarPane(
10871104
props.selectedThreadKey,
10881105
props.width,
10891106
savedConnectionsById,
1090-
shelfPreferencesLoaded,
10911107
threadSearchMatchByKey,
10921108
titleRegenerationEnvironmentIds,
10931109
settleThread,

0 commit comments

Comments
 (0)