fix(desktop): cancel superseded channel reselect

Return huddle navigation promises so deferred navigation can clear its skeleton
when route commits fail, and cover reselecting the current channel while a new
channel is pending.

Co-authored-by: Carl <c7ebe626f000404285d3686e1dc74cc07cc60a9754a150041ba132e14bd3e2ec@buzz.block.builderlab.xyz>
Signed-off-by: Wes <wesbillman@users.noreply.github.com>
This commit is contained in:
Wes
2026-08-16 12:19:12 -06:00
co-authored by Carl
parent c6ea385186
commit e17c4df27e
3 changed files with 35 additions and 4 deletions
@@ -78,7 +78,12 @@ export function useDeferredSidebarNavigation({
const selectDeferred = React.useCallback(
(channelId: string) => {
if (channelId === selectedChannelId) {
selectChannel(channelId);
if (pendingChannelId !== null) {
dispatchNavigationIntent();
cancel();
}
const navigationResult = selectChannel(channelId);
if (navigationResult) void navigationResult.catch(() => undefined);
return;
}
dispatchNavigationIntent();
@@ -122,7 +127,7 @@ export function useDeferredSidebarNavigation({
});
});
},
[cancel, selectChannel, selectedChannelId],
[cancel, pendingChannelId, selectChannel, selectedChannelId],
);
return { pendingChannelId, selectDeferred };
+2 -2
View File
@@ -298,7 +298,7 @@ export function useHuddlePresentation() {
void queryClient.invalidateQueries({
queryKey: channelWindowKey(ephemeralChannelId),
});
void goChannel(ephemeralChannelId);
return goChannel(ephemeralChannelId);
},
[goChannel, queryClient, revealHuddleChannel],
);
@@ -306,7 +306,7 @@ export function useHuddlePresentation() {
(ephemeralChannelId: string) => {
activeHuddleChannelIdRef.current = ephemeralChannelId;
trackHuddleBackingChannel(ephemeralChannelId);
viewHuddleChannel(ephemeralChannelId);
return viewHuddleChannel(ephemeralChannelId);
},
[trackHuddleBackingChannel, viewHuddleChannel],
);
+26
View File
@@ -2887,6 +2887,32 @@ test("sidebar selection paints before cached channel work starts", async ({
await expect(page.getByTestId("chat-title")).toHaveText("random");
});
test("reselecting the current channel cancels pending sidebar navigation", async ({
page,
}) => {
await page.goto("/");
await page.getByTestId("channel-general").click();
await expect(page.getByTestId("chat-title")).toHaveText("general");
const generalUrl = page.url();
const historyLength = await page.evaluate(() => window.history.length);
await page.evaluate(() => {
document
.querySelector<HTMLElement>('[data-testid="channel-random"]')
?.click();
document
.querySelector<HTMLElement>('[data-testid="channel-general"]')
?.click();
});
await expect(page.getByTestId("pending-channel-skeleton")).toHaveCount(0);
await expect(page.getByTestId("chat-title")).toHaveText("general");
await page.waitForTimeout(100);
await expect(page).toHaveURL(generalUrl);
await expect(page.getByTestId("chat-title")).toHaveText("general");
expect(await page.evaluate(() => window.history.length)).toBe(historyLength);
});
test("superseded sidebar feedback cannot override newer navigation", async ({
page,
}) => {