Skip to content

Commit cada302

Browse files
authored
fix(desktop): keep project sheets independent from threads (block#6901)
## Summary Project workspace sheets now slide in from the right as an independent layer over an open conversation thread instead of replacing the thread or rendering inside its panel. Closing the sheet restores the unchanged thread, Escape applies only to the topmost surface, and the covered thread's resize divider no longer leaks through the overlay. ### Related issue Related: block#6602. No matching issue found. ### Testing - `pnpm --dir desktop exec biome check src/features/channels/ui/RightAuxiliaryPane.tsx tests/e2e/project-commit-detail.spec.ts` - `pnpm exec playwright test tests/e2e/project-commit-detail.spec.ts --project=smoke --grep "project workspace sheet stays independent from an open thread"` - Pre-push desktop formatting, file-size, typecheck, and unit-test checks --------- Signed-off-by: Thomas Petersen <[email protected]>
1 parent cdab765 commit cada302

8 files changed

Lines changed: 352 additions & 36 deletions

‎desktop/src/features/channels/ui/ChannelPane.helpers.test.mjs‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,22 @@ test("focus idle drawers yield to every higher-priority auxiliary surface", () =
4242
}
4343
});
4444

45+
test("an explicit thread override keeps the idle panel in its own focus drawer", () => {
46+
assert.equal(
47+
shouldUseFocusIdleDrawer({
48+
channelManagementOpen: false,
49+
hasAgentSession: false,
50+
hasIdleAuxiliaryPanel: true,
51+
hasIdlePanelCloseHandler: true,
52+
hasProfilePanel: false,
53+
hasThreadSurface: true,
54+
overrideThread: true,
55+
useSplitAuxiliaryPane: false,
56+
}),
57+
true,
58+
);
59+
});
60+
4561
test("getChannelIntroKind names project homes ahead of regular streams", () => {
4662
assert.equal(getChannelIntroKind(channel(), true), "project channel");
4763
assert.equal(getChannelIntroKind(channel(), false), "regular channel");

‎desktop/src/features/channels/ui/ChannelPane.helpers.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export function shouldUseFocusIdleDrawer({
1010
hasIdlePanelCloseHandler,
1111
hasProfilePanel,
1212
hasThreadSurface,
13+
overrideThread = false,
1314
useSplitAuxiliaryPane,
1415
}: {
1516
channelManagementOpen: boolean;
@@ -18,14 +19,15 @@ export function shouldUseFocusIdleDrawer({
1819
hasIdlePanelCloseHandler: boolean;
1920
hasProfilePanel: boolean;
2021
hasThreadSurface: boolean;
22+
overrideThread?: boolean;
2123
useSplitAuxiliaryPane: boolean;
2224
}): boolean {
2325
return (
24-
useSplitAuxiliaryPane &&
26+
(useSplitAuxiliaryPane || overrideThread) &&
2527
!channelManagementOpen &&
2628
!hasAgentSession &&
2729
!hasProfilePanel &&
28-
!hasThreadSurface &&
30+
(!hasThreadSurface || overrideThread) &&
2931
hasIdleAuxiliaryPanel &&
3032
hasIdlePanelCloseHandler
3133
);

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

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ import { AgentSessionThreadPanel } from "@/features/channels/ui/AgentSessionThre
3030
import { ChannelManagementAuxiliaryPanel } from "@/features/channels/ui/ChannelManagementAuxiliaryPanel";
3131
import { IdleAuxiliaryPanel } from "@/features/channels/ui/IdleAuxiliaryPanel";
3232
import { RightAuxiliaryPane } from "@/features/channels/ui/RightAuxiliaryPane";
33+
import {
34+
ThreadPanelSurface,
35+
useThreadPanelSurface,
36+
} from "@/features/channels/ui/ThreadPanelSurface";
3337
import { ThreadViewModeToggle } from "@/features/channels/ui/ThreadViewModeToggle";
3438
import { FocusThreadDrawer } from "@/features/channels/ui/FocusThreadDrawer";
3539
import { THREAD_SURFACE_KEY } from "@/features/channels/lib/threadFocusLayout";
@@ -419,10 +423,10 @@ export const ChannelPane = React.memo(function ChannelPane({
419423
const isOverlay = useIsThreadPanelOverlay();
420424
const useSplitAuxiliaryPane = !isSinglePanelView && !isOverlay;
421425
const threadViewMode = useThreadViewMode();
426+
const hasThreadSurface =
427+
Boolean(threadHeadMessage) || shouldShowThreadSkeleton;
422428
const useFocusThreadDrawer =
423-
threadViewMode === "focus" &&
424-
useSplitAuxiliaryPane &&
425-
(Boolean(threadHeadMessage) || shouldShowThreadSkeleton);
429+
threadViewMode === "focus" && useSplitAuxiliaryPane && hasThreadSurface;
426430
const selectedAgent = React.useMemo(
427431
() =>
428432
agentSessionSelection.resolveSelectedAgentSession({
@@ -435,19 +439,26 @@ export const ChannelPane = React.memo(function ChannelPane({
435439
);
436440
const hasIdleAuxiliary =
437441
Boolean(idleAuxiliaryPanel) && Boolean(onCloseIdleAuxiliaryPanel);
442+
const priorityIdleAuxiliary = shouldPrioritizeIdleAuxiliary(
443+
idleAuxiliaryOverridesThread,
444+
hasIdleAuxiliary,
445+
);
446+
const overlayIdleAuxiliaryOverThread =
447+
priorityIdleAuxiliary && hasThreadSurface && !isOverlay;
448+
const replaceThreadWithIdleAuxiliary =
449+
priorityIdleAuxiliary && hasThreadSurface && isOverlay;
438450
const useFocusIdleDrawer = shouldUseFocusIdleDrawer({
439451
channelManagementOpen,
440452
hasAgentSession: Boolean(activeChannel && selectedAgent),
441453
hasIdleAuxiliaryPanel: Boolean(idleAuxiliaryPanel),
442454
hasIdlePanelCloseHandler: Boolean(onCloseIdleAuxiliaryPanel),
443455
hasProfilePanel: Boolean(profilePanelPubkey),
444-
hasThreadSurface: Boolean(threadHeadMessage) || shouldShowThreadSkeleton,
456+
hasThreadSurface,
457+
overrideThread: overlayIdleAuxiliaryOverThread,
445458
useSplitAuxiliaryPane,
446459
});
447-
const priorityIdleAuxiliary = shouldPrioritizeIdleAuxiliary(
448-
idleAuxiliaryOverridesThread,
449-
hasIdleAuxiliary,
450-
);
460+
const showIdleAuxiliaryOverThread =
461+
overlayIdleAuxiliaryOverThread && useFocusIdleDrawer;
451462
const { channelIsCovered, markExitComplete } = useFocusDrawerPresence(
452463
useFocusThreadDrawer || useFocusIdleDrawer,
453464
priorityIdleAuxiliary
@@ -456,6 +467,10 @@ export const ChannelPane = React.memo(function ChannelPane({
456467
? onCloseThread
457468
: (onCloseIdleAuxiliaryPanel ?? onCloseThread),
458469
);
470+
const threadSurface = useThreadPanelSurface(
471+
showIdleAuxiliaryOverThread,
472+
markExitComplete,
473+
);
459474
const { changeThreadViewMode, layoutScrollTargetId, resolveScrollTarget } =
460475
useThreadViewModeSwitch({
461476
activeThreadHeadId: threadHeadMessage?.id ?? null,
@@ -506,26 +521,27 @@ export const ChannelPane = React.memo(function ChannelPane({
506521
) : (
507522
<React.Fragment key={options.key ?? testId}>{panel}</React.Fragment>
508523
);
509-
const wrapThreadPanel = (panel: React.ReactNode) =>
510-
useFocusThreadDrawer ? (
511-
<FocusThreadDrawer
512-
channelName={activeChannel?.name ?? "channel"}
513-
hasActiveEdit={threadEditTarget !== null}
514-
key={THREAD_SURFACE_KEY}
515-
onClose={onCloseThread}
516-
>
517-
{panel}
518-
</FocusThreadDrawer>
519-
) : (
520-
wrapAux(panel, "message-thread-panel", { key: THREAD_SURFACE_KEY })
521-
);
524+
const wrapThreadPanel = (panel: React.ReactNode) => (
525+
<ThreadPanelSurface
526+
channelName={activeChannel?.name ?? "channel"}
527+
covered={threadSurface.covered}
528+
hasActiveEdit={threadEditTarget !== null}
529+
isFocusDrawer={useFocusThreadDrawer}
530+
key={THREAD_SURFACE_KEY}
531+
onClose={onCloseThread}
532+
ref={threadSurface.ref}
533+
>
534+
{useFocusThreadDrawer ? panel : wrapAux(panel, "message-thread-panel")}
535+
</ThreadPanelSurface>
536+
);
522537
const wrapIdlePanel = (panel: React.ReactNode) =>
523538
useFocusIdleDrawer && onCloseIdleAuxiliaryPanel ? (
524539
<FocusThreadDrawer
525540
channelName={activeChannel?.name ?? "channel"}
526541
key="idle-auxiliary-surface"
527542
label={idleAuxiliaryTitle || "Panel"}
528543
onClose={onCloseIdleAuxiliaryPanel}
544+
restoreFocusTarget={threadSurface.restoreFocusTarget}
529545
>
530546
{panel}
531547
</FocusThreadDrawer>
@@ -779,10 +795,8 @@ export const ChannelPane = React.memo(function ChannelPane({
779795
}
780796
showTopBorder={false}
781797
/>
782-
{/* The activity accessory is anchored in the dock's reserved
783-
bottom rail, so fading it cannot change the observed
784-
overlay height or move the conversation. Its natural
785-
content height remains responsive. */}
798+
{/* The reserved bottom rail keeps accessory fades from moving
799+
the conversation while content remains responsive. */}
786800
<ChannelComposerActivityAccessory
787801
agents={activityAgents}
788802
channel={activeChannel}
@@ -821,7 +835,7 @@ export const ChannelPane = React.memo(function ChannelPane({
821835
useSplitAuxiliaryPane={useSplitAuxiliaryPane}
822836
transparentChrome={hasSplitAuxiliaryPane}
823837
/>
824-
) : priorityIdleAuxiliary && idleAuxiliarySurface ? (
838+
) : replaceThreadWithIdleAuxiliary && idleAuxiliarySurface ? (
825839
idleAuxiliarySurface
826840
) : threadHeadMessage ? (
827841
(() => {
@@ -977,6 +991,9 @@ export const ChannelPane = React.memo(function ChannelPane({
977991
idleAuxiliarySurface
978992
)}
979993
</AnimatePresence>
994+
<AnimatePresence onExitComplete={threadSurface.markExitComplete}>
995+
{showIdleAuxiliaryOverThread ? idleAuxiliarySurface : null}
996+
</AnimatePresence>
980997
</div>
981998
);
982999
});

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

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ import { cn } from "@/shared/lib/cn";
1111
type FocusThreadDrawerProps = {
1212
channelName: string;
1313
children: React.ReactNode;
14+
/** Prevent a covered drawer from handling Escape before its overlay. */
15+
escapeEnabled?: boolean;
1416
/** Accessible name for the drawer. Channel threads leave the default. */
1517
label?: string;
1618
hasActiveEdit?: boolean;
1719
onClose: () => void;
20+
/** Resolve an explicit focus target after this drawer has been dismissed. */
21+
restoreFocusTarget?: () => HTMLElement | null;
1822
};
1923

2024
/**
@@ -120,6 +124,46 @@ const EXIT_TRANSITION = {
120124
*/
121125
const REDUCED_MOTION_TRANSITION = { duration: 0.12, ease: "linear" } as const;
122126

127+
function useViewportRightInsetPx(
128+
overlayRef: React.RefObject<HTMLDivElement | null>,
129+
) {
130+
const [rightInsetPx, setRightInsetPx] = React.useState(0);
131+
132+
React.useLayoutEffect(() => {
133+
const layoutRoot = overlayRef.current?.parentElement;
134+
if (!layoutRoot) return;
135+
136+
const updateRightInset = () => {
137+
const bounds = layoutRoot.getBoundingClientRect();
138+
const overflowPx = Math.max(0, bounds.right - window.innerWidth);
139+
const nextRightInsetPx = Math.min(bounds.width, Math.ceil(overflowPx));
140+
setRightInsetPx((current) =>
141+
current === nextRightInsetPx ? current : nextRightInsetPx,
142+
);
143+
};
144+
145+
updateRightInset();
146+
window.addEventListener("resize", updateRightInset);
147+
148+
const observer =
149+
typeof ResizeObserver === "undefined"
150+
? null
151+
: new ResizeObserver(updateRightInset);
152+
let ancestor: HTMLElement | null = layoutRoot;
153+
while (ancestor) {
154+
observer?.observe(ancestor);
155+
ancestor = ancestor.parentElement;
156+
}
157+
158+
return () => {
159+
observer?.disconnect();
160+
window.removeEventListener("resize", updateRightInset);
161+
};
162+
}, [overlayRef]);
163+
164+
return rightInsetPx;
165+
}
166+
123167
/**
124168
* Right-anchored thread drawer that overlays the channel content area.
125169
*
@@ -142,16 +186,22 @@ const REDUCED_MOTION_TRANSITION = { duration: 0.12, ease: "linear" } as const;
142186
export function FocusThreadDrawer({
143187
channelName,
144188
children,
189+
escapeEnabled = true,
145190
label = "Thread",
146191
hasActiveEdit = false,
147192
onClose,
193+
restoreFocusTarget,
148194
}: FocusThreadDrawerProps) {
149195
const prefersReducedMotion = useReducedMotion();
150196
const travelPx = prefersReducedMotion ? 0 : THREAD_FOCUS_DRAWER_TRAVEL_PX;
151197
const drawerRef = React.useRef<HTMLDivElement>(null);
198+
const overlayRef = React.useRef<HTMLDivElement>(null);
152199
const previousFocusRef = React.useRef<HTMLElement | null>(null);
200+
const viewportRightInsetPx = useViewportRightInsetPx(overlayRef);
153201

154202
React.useEffect(() => {
203+
if (!escapeEnabled) return;
204+
155205
function handleEscape(event: KeyboardEvent) {
156206
if (event.key !== "Escape") return;
157207
const target = event.target;
@@ -171,7 +221,7 @@ export function FocusThreadDrawer({
171221
return () => {
172222
window.removeEventListener("keydown", handleEscape, { capture: true });
173223
};
174-
}, [hasActiveEdit, onClose]);
224+
}, [escapeEnabled, hasActiveEdit, onClose]);
175225

176226
React.useLayoutEffect(() => {
177227
previousFocusRef.current =
@@ -183,19 +233,26 @@ export function FocusThreadDrawer({
183233
return () => {
184234
const previousFocus = previousFocusRef.current;
185235
requestAnimationFrame(() => {
236+
const explicitTarget = restoreFocusTarget?.();
237+
if (explicitTarget) {
238+
explicitTarget.focus({ preventScroll: true });
239+
return;
240+
}
186241
// A real dismissal keeps focus mode selected; a presentation switch
187242
// has already selected split mode and owns focus inside the new panel.
188243
if (getThreadViewMode() === "focus") {
189244
previousFocus?.focus({ preventScroll: true });
190245
}
191246
});
192247
};
193-
}, []);
248+
}, [restoreFocusTarget]);
194249

195250
return (
196251
<div
197252
className="absolute inset-0 z-41"
198253
data-testid="focus-thread-drawer-overlay"
254+
ref={overlayRef}
255+
style={{ right: viewportRightInsetPx }}
199256
>
200257
<motion.button
201258
animate={{ opacity: 1 }}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function RightAuxiliaryPane({
3131
return (
3232
<aside
3333
className={cn(
34-
"group/right-pane relative flex h-full shrink-0 flex-col overflow-hidden bg-background",
34+
"group/right-pane relative isolate flex h-full shrink-0 flex-col overflow-hidden bg-background",
3535
detached
3636
? "bg-transparent"
3737
: "before:pointer-events-none before:absolute before:bottom-0 before:left-0 before:top-0 before:z-50 before:w-px before:bg-border/80 before:content-['']",
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import * as React from "react";
2+
3+
import { FocusThreadDrawer } from "@/features/channels/ui/FocusThreadDrawer";
4+
import { usePresenceCoverage } from "@/features/channels/ui/useFocusDrawerPresence";
5+
6+
type ThreadPanelSurfaceProps = {
7+
channelName: string;
8+
children: React.ReactNode;
9+
covered: boolean;
10+
hasActiveEdit: boolean;
11+
isFocusDrawer: boolean;
12+
onClose: () => void;
13+
};
14+
15+
/** Keeps a thread mounted while controlling its focus-drawer presentation. */
16+
export const ThreadPanelSurface = React.forwardRef<
17+
HTMLDivElement,
18+
ThreadPanelSurfaceProps
19+
>(function ThreadPanelSurface(
20+
{ channelName, children, covered, hasActiveEdit, isFocusDrawer, onClose },
21+
ref,
22+
) {
23+
return (
24+
<div
25+
aria-hidden={covered ? true : undefined}
26+
className="contents"
27+
data-testid="thread-surface"
28+
inert={covered ? true : undefined}
29+
ref={ref}
30+
>
31+
{isFocusDrawer ? (
32+
<FocusThreadDrawer
33+
channelName={channelName}
34+
escapeEnabled={!covered}
35+
hasActiveEdit={hasActiveEdit}
36+
onClose={onClose}
37+
>
38+
{children}
39+
</FocusThreadDrawer>
40+
) : (
41+
children
42+
)}
43+
</div>
44+
);
45+
});
46+
47+
/** Supplies covered-thread lifecycle and focus ownership for an overlay drawer. */
48+
export function useThreadPanelSurface(
49+
open: boolean,
50+
onExitComplete: () => void,
51+
) {
52+
const ref = React.useRef<HTMLDivElement>(null);
53+
const coverage = usePresenceCoverage(open);
54+
const markExitComplete = React.useCallback(() => {
55+
coverage.markExitComplete();
56+
onExitComplete();
57+
}, [coverage.markExitComplete, onExitComplete]);
58+
const restoreFocusTarget = React.useCallback(
59+
() =>
60+
ref.current?.querySelector<HTMLElement>(
61+
'[data-testid="auxiliary-panel-close"]',
62+
) ?? null,
63+
[],
64+
);
65+
return { ...coverage, markExitComplete, ref, restoreFocusTarget };
66+
}

0 commit comments

Comments
 (0)