Skip to content

Commit bc7c74b

Browse files
matt2eclaude
andcommitted
fix(channels): keep main-pane threads mounted under the image viewer
79f25bb guarded every thread host on showingMediaReview. hosts covers both panes, so a thread moved to the main pane now unmounted during a review and came back without its scroll place, reply target or expanded branches. Before that commit it stayed mounted and attached: the main PanelWorkspace was never gated on a review. useConversationTabs takes hostPanes, the panes whose thread content renders now, and ChannelsPage passes ["main"] during a review, so only side thread tabs leave. The review state moves above the hook call, which now reads it. keepMounted holds during a review only when there is a panel to keep, instead of rendering an empty hidden dock. The side-thread guard is not a no-op kept from main, as its comment and the earlier message said. On main the side thread stayed React-mounted in a detached portal subtree: TabSlot removed its node when the pane children unmounted while hosts kept portaling into it, which is the stale-draft state of the rejected keep-everything-mounted probe. The guard is what makes the viewer's edits reach the thread composer, which reads its draft only on mount; the comment now says so. Tests: a hook case opens a side and a main thread and shows hostPanes ["main"] withholds only the side host and hosts it again afterwards. The browser journey moves the side thread to the main pane, reviews the image and asserts the same composer element stays connected and the thread stays in the DOM while the viewer is up; it fails when a review withholds both panes. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: mtoohey <[email protected]>
1 parent 79f25bb commit bc7c74b

4 files changed

Lines changed: 128 additions & 25 deletions

File tree

‎src/bundled/channels/ChannelsPage.tsx‎

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,24 @@ function ChannelWorkspace({
12061206
target: targetKey(fallback),
12071207
};
12081208
};
1209+
const [mediaReview, setMediaReview] = useState<{
1210+
channelId: string;
1211+
channelName: string;
1212+
messageId: string;
1213+
attachment: Attachment;
1214+
initialAttachments?: readonly Attachment[] | undefined;
1215+
initialTime: number;
1216+
hasComments: boolean;
1217+
entryId?: string | undefined;
1218+
}>();
1219+
// The current destination may be an authorized public preview, which is
1220+
// intentionally absent from the joined-channel list.
1221+
const showingMediaReview = current?.archived
1222+
? undefined
1223+
: mediaReviewForDestination(mediaReview, current?.id, navigation?.entryId);
1224+
useEffect(() => {
1225+
if (mediaReview && !showingMediaReview) setMediaReview(undefined);
1226+
}, [mediaReview, showingMediaReview]);
12091227
const secondary = useConversationTabs({
12101228
state: tabState,
12111229
relay,
@@ -1238,6 +1256,13 @@ function ChannelWorkspace({
12381256
leadingIds: settings ? ["settings"] : [],
12391257
threadId: routedThread?.messageId,
12401258
mainPane: !solo,
1259+
// Side thread tabs leave during an image or video review; this is what
1260+
// hands the thread draft back from the viewer. The viewer's comment
1261+
// composer reads the thread's saved draft when it mounts, and a thread
1262+
// composer reads a draft only when it mounts, so a side thread kept
1263+
// mounted under the hidden dock would still show the text the viewer
1264+
// replaced. Main-pane threads keep their place and state, as before.
1265+
hostPanes: showingMediaReview ? ["main"] : undefined,
12411266
navigation: navigator,
12421267
routed: routedThread,
12431268
onVisitPanel: visitPanel,
@@ -1654,24 +1679,6 @@ function ChannelWorkspace({
16541679
[secondary.openLinkedThread],
16551680
);
16561681
const mediaReviewTrigger = useRef<HTMLElement | null>(null);
1657-
const [mediaReview, setMediaReview] = useState<{
1658-
channelId: string;
1659-
channelName: string;
1660-
messageId: string;
1661-
attachment: Attachment;
1662-
initialAttachments?: readonly Attachment[] | undefined;
1663-
initialTime: number;
1664-
hasComments: boolean;
1665-
entryId?: string | undefined;
1666-
}>();
1667-
// The current destination may be an authorized public preview, which is
1668-
// intentionally absent from the joined-channel list.
1669-
const showingMediaReview = current?.archived
1670-
? undefined
1671-
: mediaReviewForDestination(mediaReview, current?.id, navigation?.entryId);
1672-
useEffect(() => {
1673-
if (mediaReview && !showingMediaReview) setMediaReview(undefined);
1674-
}, [mediaReview, showingMediaReview]);
16751682
// Timeline rows are memoized; their callbacks read the shown destination at
16761683
// call time so a new navigation request does not rerender every row.
16771684
const destination = useRef({ current, navigation });
@@ -2486,10 +2493,7 @@ function ChannelWorkspace({
24862493
/>
24872494
)}
24882495
{secondary.drag.feedback}
2489-
{/* Thread tabs leave during a review: the viewer's comment composer reads
2490-
the thread draft when it mounts, and the thread reads the viewer's
2491-
edits back when it returns. */}
2492-
{!showingMediaReview && secondary.hosts}
2496+
{secondary.hosts}
24932497
<p role="status" className="sr-only">
24942498
{secondary.announcement}
24952499
</p>
@@ -2498,7 +2502,7 @@ function ChannelWorkspace({
24982502
keepMounted={
24992503
tabState.entries.length > 0 ||
25002504
(!!hasPanel && !tabState.paneOpen) ||
2501-
!!showingMediaReview
2505+
(!!hasPanel && !!showingMediaReview)
25022506
}
25032507
className={styles.panelStack}
25042508
resizeHandle={split.handle}

‎src/bundled/channels/useConversationTabs.test.tsx‎

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ import type {
2424
} from "../../features/panels/service";
2525
import { createAgentLibrary } from "../../features/agents/library";
2626
import { setThreadPlacementPreference } from "../../features/messages/thread-preferences";
27-
import { channelTabs, tabPane, useChannelTabState } from "./useChannelTabState";
27+
import {
28+
channelTabs,
29+
tabPane,
30+
useChannelTabState,
31+
type TabPane,
32+
} from "./useChannelTabState";
2833
import { useConversationTabs } from "./useConversationTabs";
2934
import {
3035
claimProfileTranscript,
@@ -1967,6 +1972,69 @@ it("mounts a hidden thread tab when first shown and keeps it for the visit", ()
19671972
expect(restored("thread:alpha:r1")).toBeUndefined();
19681973
});
19691974

1975+
it("a page withholds one pane's thread content and hosts it again afterwards", () => {
1976+
setThreadPlacementPreference("side");
1977+
const channels = [{ id: "alpha", name: "Alpha" }];
1978+
const session = {
1979+
viewer: "viewer",
1980+
channels: { list: () => ({ channels }), window: () => ({ rows: [] }) },
1981+
} as unknown as RelaySession;
1982+
const emptyPanels: RegisteredPanel[] = [];
1983+
const panels = {
1984+
snapshot: () => emptyPanels,
1985+
subscribe: () => () => {},
1986+
} as unknown as Panels;
1987+
const relay = {
1988+
snapshot: () => ({ status: "ready", session }),
1989+
} as unknown as RelayData;
1990+
const h = renderHook(
1991+
({ hostPanes }: { hostPanes?: readonly TabPane[] }) => {
1992+
const state = useChannelTabState(session, "alpha");
1993+
const workspace = useConversationTabs({
1994+
profiles: new Map(),
1995+
state,
1996+
relay,
1997+
session,
1998+
panels,
1999+
current: channels[0],
2000+
channels,
2001+
scope: "scope:viewer",
2002+
conversationIcon: () => null,
2003+
leadingIds: [],
2004+
continuingVisit: true,
2005+
mainPane: true,
2006+
hostPanes,
2007+
isLive: () => true,
2008+
openLink: () => false,
2009+
});
2010+
return { state, workspace };
2011+
},
2012+
{ initialProps: {} },
2013+
);
2014+
const hosted = () =>
2015+
h.result.current.workspace.hosts.map(
2016+
(host) => (host as { key?: string }).key,
2017+
);
2018+
act(() => h.result.current.state.openThreadTab("alpha", "r1", "r1"));
2019+
act(() =>
2020+
h.result.current.state.openThreadTab(
2021+
"alpha",
2022+
"r2",
2023+
"r2",
2024+
undefined,
2025+
"main",
2026+
),
2027+
);
2028+
expect(h.result.current.state.tabs.map(tabPane)).toEqual(["side", "main"]);
2029+
expect(hosted()).toEqual(["thread:alpha:r1", "thread:alpha:r2"]);
2030+
// Only the side thread leaves; the main-pane thread keeps rendering.
2031+
h.rerender({ hostPanes: ["main"] });
2032+
expect(hosted()).toEqual(["thread:alpha:r2"]);
2033+
// Back in the same visit, the side thread is hosted again without being shown.
2034+
h.rerender({});
2035+
expect(hosted()).toEqual(["thread:alpha:r1", "thread:alpha:r2"]);
2036+
});
2037+
19702038
it("a hidden retained thread tab's rows re-render for new panels, not channel-list changes", () => {
19712039
setThreadPlacementPreference("side");
19722040
const thread = (id: string) => ({

‎src/bundled/channels/useConversationTabs.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export function useConversationTabs({
8080
mainPane = false,
8181
anyMainThread = false,
8282
threadPane,
83+
hostPanes,
8384
visits = true,
8485
navigation,
8586
routed,
@@ -122,6 +123,9 @@ export function useConversationTabs({
122123
anyMainThread?: boolean | undefined;
123124
/** Where new thread tabs open; by default, per the thread placement setting. */
124125
threadPane?: TabPane | undefined;
126+
/** Panes whose thread content renders now; by default both. A page withholds
127+
* a pane's threads while something covers them; they mount afresh after. */
128+
hostPanes?: readonly TabPane[] | undefined;
125129
/** Showing a tab visits its conversation; a page may only reveal it. */
126130
visits?: boolean | undefined;
127131
/** Opens another conversation's tab where it lives, from the tab's menu. */
@@ -983,6 +987,7 @@ export function useConversationTabs({
983987
// Thread content renders here once and is attached to whichever pane holds it.
984988
hosts: tabState.tabs.flatMap((tab) => {
985989
if (tab.kind !== "thread") return [];
990+
if (hostPanes && !hostPanes.includes(tabPane(tab))) return [];
986991
const node = nodes.get(tab.id);
987992
const target = tabChannel(tab);
988993
if (!node || !target) return [];

‎tests/browser/channel-settings.spec.mjs‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ test("an image review keeps Channel settings open and hands the thread draft to
208208
await expect(settingsTab).toHaveAttribute("aria-selected", "true");
209209
await expect(tile).toBeFocused();
210210

211-
// Thread tabs still leave while the viewer is up: the viewer's comment
211+
// Side thread tabs leave while the viewer is up: the viewer's comment
212212
// composer reads the saved draft when it mounts, and the thread composer
213213
// reads the viewer's edits back when it returns. Reply closes settings today.
214214
await hoverMessage(row);
@@ -244,6 +244,32 @@ test("an image review keeps Channel settings open and hands the thread draft to
244244
await expect(viewer).toHaveCount(0);
245245
await expect(threadDraft).toHaveText("Handoff draft, edited in the viewer");
246246
await expect(tile).toBeFocused();
247+
248+
// A thread in the main pane is not under the dock and keeps its place
249+
// through a review: the same composer stays mounted, never leaving the DOM.
250+
const main = page.locator("[data-main-workspace]");
251+
const threadTabs = (host) =>
252+
host.locator('[role="tab"][data-tab-value^="thread:"]');
253+
await threadTabs(workspace).focus();
254+
await page.keyboard.press("Alt+Shift+ArrowLeft");
255+
await expect(threadTabs(main)).toHaveCount(1);
256+
const mainDraft = main.getByRole("textbox", {
257+
name: "Reply to thread",
258+
exact: true,
259+
});
260+
await expect(mainDraft).toHaveText("Handoff draft, edited in the viewer");
261+
const mainEditor = await mainDraft.elementHandle();
262+
await main.getByRole("tab", { name: "Alpha", exact: true }).click();
263+
await expect(tile).toBeVisible();
264+
await tile.click();
265+
await expect(viewer).toBeVisible();
266+
await expect(hiddenThread).toHaveCount(1);
267+
expect(await mainEditor.evaluate((node) => node.isConnected)).toBe(true);
268+
await page.keyboard.press("Escape");
269+
await expect(viewer).toHaveCount(0);
270+
expect(await mainEditor.evaluate((node) => node.isConnected)).toBe(true);
271+
await expect(threadTabs(main)).toHaveCount(1);
272+
await expect(tile).toBeFocused();
247273
});
248274

249275
test.describe("description links", () => {

0 commit comments

Comments
 (0)