Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(canvas): keep the side panel open when switching to Chat (#80676)

Shy Alterb2610add3277
diff --git a/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSidePanel.test.tsx b/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSidePanel.test.tsx
index 410ffa051265..f0516627ca0e 100644
--- a/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSidePanel.test.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSidePanel.test.tsx
@@ -60,4 +60,26 @@ describe("CanvasSidePanel", () => {
"task-1:canvas-1",
);
});
+
+ it("shows the run that built the canvas on the chat tab while viewing", () => {
+ useCanvasChatPanelStore.setState({ tab: "comments", collapsed: false });
+ render(
+ <CanvasSidePanel
+ effectiveTaskId={null}
+ commentTaskId="task-1"
+ interactive={false}
+ onMinimize={vi.fn()}
+ dashboardId="canvas-1"
+ channelId="channel-1"
+ channelName="General"
+ name="Launch canvas"
+ displayedVersionId="version-2"
+ commentVersionLabel={(versionId) => versionId}
+ onCommentOpen={vi.fn()}
+ />,
+ );
+
+ fireEvent.click(screen.getByText("Chat"));
+ expect(screen.getByTestId("task-chat")).toBeInTheDocument();
+ });
});
diff --git a/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSidePanel.tsx b/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSidePanel.tsx
index 6194c5147c61..25f24b2fa82e 100644
--- a/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSidePanel.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSidePanel.tsx
@@ -28,6 +28,7 @@ import { type Ref, useEffect, useRef } from "react";
export function CanvasSidePanel({
effectiveTaskId,
commentTaskId,
+ interactive,
onMinimize,
dashboardId,
channelId,
@@ -43,6 +44,9 @@ export function CanvasSidePanel({
}: {
effectiveTaskId: string | null;
commentTaskId: string | null;
+ /** Whether the canvas is being edited. The composer is an edit affordance, so
+ * view mode falls back to the conversation that last built the canvas. */
+ interactive?: boolean;
onMinimize: () => void;
dashboardId: string;
channelId: string;
@@ -62,6 +66,9 @@ export function CanvasSidePanel({
const tab = useCanvasChatPanelStore((state) => state.tab);
const setTab = useCanvasChatPanelStore((state) => state.setTab);
const previousTaskId = useRef(effectiveTaskId);
+ // With no run in flight, edit mode gets the composer for the next change,
+ // while view mode gets the chat of the run that produced this canvas.
+ const chatTaskId = effectiveTaskId ?? (interactive ? null : commentTaskId);
useEffect(() => {
if (effectiveTaskId && effectiveTaskId !== previousTaskId.current) {
@@ -117,8 +124,8 @@ export function CanvasSidePanel({
commentVersionLabel={commentVersionLabel}
onCommentOpen={onCommentOpen}
/>
- ) : effectiveTaskId ? (
- <CanvasChatLoader taskId={effectiveTaskId} />
+ ) : chatTaskId ? (
+ <CanvasChatLoader taskId={chatTaskId} />
) : (
<div className="flex h-full min-h-0 flex-col gap-3 p-3">
<FreeformGenerateBar
diff --git a/products/desktop/packages/ui/src/features/canvas/freeform/FreeformCanvasView.tsx b/products/desktop/packages/ui/src/features/canvas/freeform/FreeformCanvasView.tsx
index f961b53c139b..06c7434245fa 100644
--- a/products/desktop/packages/ui/src/features/canvas/freeform/FreeformCanvasView.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/freeform/FreeformCanvasView.tsx
@@ -82,6 +82,7 @@ import { CanvasPermissionDialog } from "./CanvasPermissionDialog";
import { CanvasSelectionCommentAction } from "./CanvasSelectionCommentAction";
import { CanvasSidePanel } from "./CanvasSidePanel";
import { canvasCommentTaskId } from "./canvasCommentTask";
+import { canvasSidePanelVisibility } from "./canvasSidePanelVisibility";
import {
canvasVersionNavigation,
shouldClearCanvasBrowse,
@@ -131,7 +132,7 @@ export function FreeformCanvasView({
setClearTextSelectionKey((key) => key + 1);
}, []);
const collapsed = useCanvasChatPanelStore((s) => s.collapsed);
- const panelTab = useCanvasChatPanelStore((s) => s.tab);
+ const panelViewOpen = useCanvasChatPanelStore((s) => s.viewOpen);
const setCollapsed = useCanvasChatPanelStore((s) => s.setCollapsed);
const panelWidth = useCanvasChatPanelStore((s) => s.width);
const setPanelWidth = useCanvasChatPanelStore((s) => s.setWidth);
@@ -529,11 +530,18 @@ export function FreeformCanvasView({
!headCode &&
!generatingPanelDismissed;
// The side panel exists once there's a canvas or an active run (edit mode),
- // or while the generating default holds (any mode).
- const showPanel =
- (interactive && (hasContent || !!effectiveTaskId)) || generatingPanelOpen;
- const showCommentsPanel =
- panelTab === "comments" && !collapsed && !!commentTaskId;
+ // while the generating default holds (any mode), or once it was opened from
+ // view mode — a tested pure helper.
+ const panelVisibility = canvasSidePanelVisibility({
+ interactive,
+ hasContent,
+ hasActiveTask: !!effectiveTaskId,
+ generatingPanelOpen,
+ viewOpen: panelViewOpen,
+ collapsed,
+ hasCommentTask: !!commentTaskId,
+ });
+ const showPanel = panelVisibility.editing;
// Build failures/progress surface in view mode too — the toolbar renders
// there only while it has something to say.
const hasBuildSignal =
@@ -852,7 +860,7 @@ export function FreeformCanvasView({
</Box>
</Flex>
- {(showPanel || showCommentsPanel) && (
+ {(panelVisibility.editing || panelVisibility.viewing) && (
<ResizableSidebar
open={(!collapsed || generatingPanelOpen) && !waitingForHeroExit}
width={panelWidth}
@@ -867,6 +875,7 @@ export function FreeformCanvasView({
<CanvasSidePanel
effectiveTaskId={effectiveTaskId}
commentTaskId={commentTaskId}
+ interactive={interactive}
onMinimize={() => {
setCollapsed(true);
setGeneratingPanelDismissed(true);
diff --git a/products/desktop/packages/ui/src/features/canvas/freeform/canvasSidePanelVisibility.test.ts b/products/desktop/packages/ui/src/features/canvas/freeform/canvasSidePanelVisibility.test.ts
new file mode 100644
index 000000000000..29a127b1e7ad
--- /dev/null
+++ b/products/desktop/packages/ui/src/features/canvas/freeform/canvasSidePanelVisibility.test.ts
@@ -0,0 +1,54 @@
+import { describe, expect, it } from "vitest";
+import { canvasSidePanelVisibility } from "./canvasSidePanelVisibility";
+
+const base = {
+ interactive: false,
+ hasContent: true,
+ hasActiveTask: false,
+ generatingPanelOpen: false,
+ viewOpen: false,
+ collapsed: false,
+ hasCommentTask: true,
+};
+
+describe("canvasSidePanelVisibility", () => {
+ it.each([
+ ["editing a canvas with content", { interactive: true }, true, false],
+ [
+ "editing an empty canvas with a run in flight",
+ { interactive: true, hasContent: false, hasActiveTask: true },
+ true,
+ false,
+ ],
+ [
+ "generating in view mode",
+ { hasActiveTask: true, generatingPanelOpen: true },
+ true,
+ false,
+ ],
+ ["viewing, dock never opened", {}, false, false],
+ [
+ "viewing, dock opened from the breadcrumb",
+ { viewOpen: true },
+ false,
+ true,
+ ],
+ [
+ "viewing, dock opened but minimized",
+ { viewOpen: true, collapsed: true },
+ false,
+ false,
+ ],
+ [
+ "viewing a canvas no task backs",
+ { viewOpen: true, hasCommentTask: false },
+ false,
+ false,
+ ],
+ ])("%s", (_name, overrides, editing, viewing) => {
+ expect(canvasSidePanelVisibility({ ...base, ...overrides })).toEqual({
+ editing,
+ viewing,
+ });
+ });
+});
diff --git a/products/desktop/packages/ui/src/features/canvas/freeform/canvasSidePanelVisibility.ts b/products/desktop/packages/ui/src/features/canvas/freeform/canvasSidePanelVisibility.ts
new file mode 100644
index 000000000000..f38a1a922bdb
--- /dev/null
+++ b/products/desktop/packages/ui/src/features/canvas/freeform/canvasSidePanelVisibility.ts
@@ -0,0 +1,37 @@
+// Whether the canvas's right-hand dock is mounted, and why. Two independent
+// reasons, because the dock serves two modes: editing a canvas, and reading the
+// comments/agent chat of one you're only viewing.
+
+export interface CanvasSidePanelVisibility {
+ /** The edit-mode dock: there's a canvas to change, or a run to watch. */
+ editing: boolean;
+ /** The on-demand dock in view mode, opened from the breadcrumb's Comments
+ * button. Held open by its own state rather than by which tab is showing, so
+ * switching tabs inside it can't tear it down. */
+ viewing: boolean;
+}
+
+export function canvasSidePanelVisibility(args: {
+ /** Whether the canvas is being edited. */
+ interactive: boolean;
+ /** Whether the canvas has any published source or artifact. */
+ hasContent: boolean;
+ /** Whether a generation/edit run is in flight or just submitted. */
+ hasActiveTask: boolean;
+ /** The generating-canvas default: the run's chat is the only content there
+ * is, so the dock opens in view mode too. */
+ generatingPanelOpen: boolean;
+ /** Whether the dock was opened while viewing the canvas. */
+ viewOpen: boolean;
+ /** Whether the dock is minimized to the rail. */
+ collapsed: boolean;
+ /** Whether a task backs this canvas's comments and agent chat. */
+ hasCommentTask: boolean;
+}): CanvasSidePanelVisibility {
+ return {
+ editing:
+ (args.interactive && (args.hasContent || args.hasActiveTask)) ||
+ args.generatingPanelOpen,
+ viewing: args.viewOpen && !args.collapsed && args.hasCommentTask,
+ };
+}
diff --git a/products/desktop/packages/ui/src/features/canvas/stores/canvasChatPanelStore.ts b/products/desktop/packages/ui/src/features/canvas/stores/canvasChatPanelStore.ts
index 506056a9d698..d23a7fdf5ca2 100644
--- a/products/desktop/packages/ui/src/features/canvas/stores/canvasChatPanelStore.ts
+++ b/products/desktop/packages/ui/src/features/canvas/stores/canvasChatPanelStore.ts
@@ -13,6 +13,10 @@ interface CanvasChatPanelState {
collapsed: boolean;
width: number;
tab: CanvasPanelTab;
+ /** Whether the dock was opened while viewing (rather than editing) a canvas.
+ * View mode has no other reason to keep it mounted, so this — not the active
+ * tab — is what holds it open there, and a tab switch leaves it alone. */
+ viewOpen: boolean;
setCollapsed: (collapsed: boolean) => void;
setWidth: (width: number) => void;
setTab: (tab: CanvasPanelTab) => void;
@@ -25,10 +29,15 @@ export const useCanvasChatPanelStore = create<CanvasChatPanelState>()(
collapsed: false,
width: DEFAULT_PANEL_WIDTH,
tab: "chat",
- setCollapsed: (collapsed) => set({ collapsed }),
+ viewOpen: false,
+ // Minimizing in view mode dismisses the dock entirely: there's no rail
+ // button there, so the way back is the breadcrumb's Comments button.
+ setCollapsed: (collapsed) =>
+ set(collapsed ? { collapsed, viewOpen: false } : { collapsed }),
setWidth: (width) => set({ width }),
setTab: (tab) => set({ tab }),
- openComments: () => set({ collapsed: false, tab: "comments" }),
+ openComments: () =>
+ set({ collapsed: false, tab: "comments", viewOpen: true }),
}),
{
name: "canvas-chat-panel-storage",