Skip to content

Commit cbc41a9

Browse files
committed
fix(desktop): bind retry regression to production wiring
Exercise the same query-to-loading coordinator used by ChannelScreen so removing the cold-error settlement guard fails the regression. Signed-off-by: Thomas Petersen <[email protected]>
1 parent 7ca3c8c commit cbc41a9

3 files changed

Lines changed: 52 additions & 34 deletions

File tree

‎desktop/src/features/channels/ui/ChannelScreen.tsx‎

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ import {
5050
isThreadReply,
5151
} from "@/features/messages/lib/threading";
5252
import { hasPersistedHydratedChannel } from "@/features/messages/lib/channelHeadCache";
53-
import {
54-
resolveTimelineLoadingLatch,
55-
selectTimelineLoadingState,
56-
} from "@/features/messages/lib/timelineLoadingState";
53+
import { resolveTimelineQueryLoadingState } from "@/features/messages/lib/timelineLoadingState";
5754
import { useFetchOlderMessages } from "@/features/messages/useFetchOlderMessages";
5855
import { useIndependentThreadPanel } from "@/features/messages/useIndependentThreadPanel";
5956
import { useThreadReplies } from "@/features/messages/useThreadReplies";
@@ -616,27 +613,21 @@ export function ChannelScreen({
616613
setThreadScrollTargetId,
617614
});
618615
const settledChannelIdRef = React.useRef<string | null>(null);
619-
const hasSettledThisChannel =
620-
activeChannelId !== null && settledChannelIdRef.current === activeChannelId;
621-
const timelineLoadingNow =
622-
activeChannel !== null &&
623-
activeChannel.channelType !== "forum" &&
624-
selectTimelineLoadingState(
616+
const { settledChannelId, isLoading: isTimelineLoading } =
617+
resolveTimelineQueryLoadingState(
618+
settledChannelIdRef.current,
619+
activeChannelId,
625620
{
621+
isEnabled:
622+
activeChannel !== null && activeChannel.channelType !== "forum",
626623
isPending: messagesQuery.isPending,
627624
isFetching: messagesQuery.isFetching,
628625
isPlaceholderData: messagesQuery.isPlaceholderData,
629626
dataLength: messagesQuery.data?.length ?? null,
627+
isError: messagesQuery.isError,
630628
},
631-
hasSettledThisChannel ||
632-
(activeChannelId !== null &&
633-
hasPersistedHydratedChannel(queryClient, activeChannelId)),
634-
);
635-
const { settledChannelId, isLoading: isTimelineLoading } =
636-
resolveTimelineLoadingLatch(
637-
settledChannelIdRef.current,
638-
activeChannelId,
639-
timelineLoadingNow, !messagesQuery.isError,
629+
activeChannelId !== null &&
630+
hasPersistedHydratedChannel(queryClient, activeChannelId),
640631
);
641632
settledChannelIdRef.current = settledChannelId;
642633
const { welcomeKickoffStage, welcomeKickoffSettingUp } =

‎desktop/src/features/messages/lib/timelineLoadingState.test.mjs‎

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { QueryClient, QueryObserver } from "@tanstack/react-query";
44

55
import {
66
resolveTimelineLoadingLatch,
7+
resolveTimelineQueryLoadingState,
78
selectTimelineLoadingState,
89
} from "./timelineLoadingState.ts";
910

@@ -25,21 +26,14 @@ function deferred() {
2526
}
2627

2728
function resolveQueryLoading(result, settledChannelId = null) {
28-
const loadingNow = selectTimelineLoadingState(
29-
{
30-
isPending: result.isPending,
31-
isFetching: result.isFetching,
32-
isPlaceholderData: result.isPlaceholderData,
33-
dataLength: result.data?.length ?? null,
34-
},
35-
settledChannelId === "chan-a",
36-
);
37-
return resolveTimelineLoadingLatch(
38-
settledChannelId,
39-
"chan-a",
40-
loadingNow,
41-
!result.isError,
42-
);
29+
return resolveTimelineQueryLoadingState(settledChannelId, "chan-a", {
30+
isEnabled: true,
31+
isPending: result.isPending,
32+
isFetching: result.isFetching,
33+
isPlaceholderData: result.isPlaceholderData,
34+
dataLength: result.data?.length ?? null,
35+
isError: result.isError,
36+
});
4337
}
4438

4539
test("pending first fetch with no cache is loading", () => {

‎desktop/src/features/messages/lib/timelineLoadingState.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ export type TimelineQueryStatus = {
1515
dataLength: number | null;
1616
};
1717

18+
export type TimelineQueryLoadingStatus = TimelineQueryStatus & {
19+
isEnabled: boolean;
20+
isError: boolean;
21+
};
22+
1823
export function selectTimelineLoadingState(
1924
status: TimelineQueryStatus,
2025
hasSettled = true,
@@ -65,3 +70,31 @@ export function resolveTimelineLoadingLatch(
6570
}
6671
return { settledChannelId, isLoading: loadingNow };
6772
}
73+
74+
/**
75+
* Production coordinator from the messages query state to the channel loading
76+
* latch. Keeping the error guard here prevents a cold terminal failure from
77+
* being recorded as an authoritative empty result before Retry starts.
78+
*/
79+
export function resolveTimelineQueryLoadingState(
80+
settledChannelId: string | null,
81+
activeChannelId: string | null,
82+
status: TimelineQueryLoadingStatus,
83+
hasPersistedHydratedChannel = false,
84+
): { settledChannelId: string | null; isLoading: boolean } {
85+
const hasSettledThisChannel =
86+
activeChannelId !== null && settledChannelId === activeChannelId;
87+
const loadingNow =
88+
status.isEnabled &&
89+
selectTimelineLoadingState(
90+
status,
91+
hasSettledThisChannel || hasPersistedHydratedChannel,
92+
);
93+
94+
return resolveTimelineLoadingLatch(
95+
settledChannelId,
96+
activeChannelId,
97+
loadingNow,
98+
!status.isError,
99+
);
100+
}

0 commit comments

Comments
 (0)