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(desktop): keep sidebar visible while context menus are open (#89707)

Peter Kirkhamc881cc9e8186
diff --git a/products/desktop/packages/ui/src/features/canvas/components/ChannelItemRow.test.tsx b/products/desktop/packages/ui/src/features/canvas/components/ChannelItemRow.test.tsx
index 579c3eb2b8b3..56f605fe6dc6 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/ChannelItemRow.test.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/ChannelItemRow.test.tsx
@@ -3,13 +3,25 @@ import { formatRelativeTimeShort } from "@posthog/shared";
import type { Task } from "@posthog/shared/domain-types";
import { CANVAS_DRAG_TYPE } from "@posthog/ui/features/canvas/canvasDrag";
import type { TaskStatusInput } from "@posthog/ui/features/sidebar/components/items/taskStatusVocabulary";
+import {
+ beginSidebarPeek,
+ cancelSidebarPeek,
+ endSidebarPeek,
+ useSidebarPeekStore,
+} from "@posthog/ui/features/sidebar/sidebarPeekStore";
import {
TASK_DRAG_TYPE,
TASK_IDS_DRAG_TYPE,
} from "@posthog/ui/features/sidebar/taskDrag";
import { useTaskSelectionStore } from "@posthog/ui/features/sidebar/taskSelectionStore";
import { Theme } from "@radix-ui/themes";
-import { cleanup, fireEvent, render, screen } from "@testing-library/react";
+import {
+ act,
+ cleanup,
+ fireEvent,
+ render,
+ screen,
+} from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import type { ReactNode } from "react";
import { beforeEach, describe, expect, it, vi } from "vitest";
@@ -411,6 +423,29 @@ describe("ChannelItemRow", () => {
}
});
+ it("keeps the hover sidebar open while the context menu is open", () => {
+ vi.useFakeTimers();
+ try {
+ beginSidebarPeek();
+ renderWithMenu({});
+
+ fireEvent.contextMenu(screen.getByText("Investigate signup drop-off"));
+ endSidebarPeek(0);
+ act(() => vi.runAllTimers());
+
+ expect(useSidebarPeekStore.getState().peek).toBe(true);
+
+ fireEvent.keyDown(document, { key: "Escape" });
+ act(() => vi.runAllTimers());
+
+ expect(useSidebarPeekStore.getState().peek).toBe(false);
+ } finally {
+ cleanup();
+ cancelSidebarPeek();
+ vi.useRealTimers();
+ }
+ });
+
it("offers Run analysis for a task with a terminal run", () => {
const run = vi.fn();
mocks.analysis = { canAnalyze: true, isPending: false, run };
diff --git a/products/desktop/packages/ui/src/features/canvas/components/TaskRowMenu.tsx b/products/desktop/packages/ui/src/features/canvas/components/TaskRowMenu.tsx
index c1252724707f..2b9a7a7e0684 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/TaskRowMenu.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/TaskRowMenu.tsx
@@ -33,6 +33,8 @@ import type { Task } from "@posthog/shared/domain-types";
import { useChannels } from "@posthog/ui/features/canvas/hooks/useChannels";
import { useFileTaskToChannel } from "@posthog/ui/features/canvas/hooks/useFileTaskToChannel";
import { useFeatureFlag } from "@posthog/ui/features/feature-flags/useFeatureFlag";
+import { useSidebarPeekStore } from "@posthog/ui/features/sidebar/sidebarPeekStore";
+import { useHoldSidebarPeek } from "@posthog/ui/features/sidebar/useHoldSidebarPeek";
import type { SidebarBulkActions } from "@posthog/ui/features/sidebar/useSidebarBulkActions";
import { useTaskAnalysis } from "@posthog/ui/features/task-detail/components/TaskAnalysisButton";
import {
@@ -44,6 +46,7 @@ import {
type ComponentType,
type ReactElement,
type ReactNode,
+ useCallback,
useMemo,
useState,
} from "react";
@@ -412,8 +415,19 @@ export function TaskRowContextMenu({
onOpenChange?: (open: boolean) => void;
children: ReactNode;
}) {
+ const holdSidebarPeek = useHoldSidebarPeek();
+ const handleOpenChange = useCallback(
+ (open: boolean): void => {
+ if (!open || useSidebarPeekStore.getState().peek) {
+ holdSidebarPeek(open);
+ }
+ onOpenChange?.(open);
+ },
+ [holdSidebarPeek, onOpenChange],
+ );
+
return (
- <ContextMenu onOpenChange={onOpenChange}>
+ <ContextMenu onOpenChange={handleOpenChange}>
<ContextMenuTrigger render={<div className="min-w-0" />}>
{children}
</ContextMenuTrigger>
diff --git a/products/desktop/packages/ui/src/features/sidebar/components/SidebarMenu.tsx b/products/desktop/packages/ui/src/features/sidebar/components/SidebarMenu.tsx
index 9b0d4dcf884f..384e96029fa5 100644
--- a/products/desktop/packages/ui/src/features/sidebar/components/SidebarMenu.tsx
+++ b/products/desktop/packages/ui/src/features/sidebar/components/SidebarMenu.tsx
@@ -22,6 +22,7 @@ import { useExternalAppAction } from "@posthog/ui/features/external-apps/useExte
import { useFolders } from "@posthog/ui/features/folders/useFolders";
import { StopCloudRunDialog } from "@posthog/ui/features/sessions/components/StopCloudRunDialog";
import { useArchivingTasksStore } from "@posthog/ui/features/sidebar/archivingTasksStore";
+import { withSidebarPeekHeld } from "@posthog/ui/features/sidebar/sidebarPeekStore";
import { useSidebarStore } from "@posthog/ui/features/sidebar/sidebarStore";
import { useTaskSelectionStore } from "@posthog/ui/features/sidebar/taskSelectionStore";
import { useBulkArchiveConfirm } from "@posthog/ui/features/sidebar/useBulkArchiveConfirm";
@@ -240,8 +241,8 @@ function SidebarMenuComponent() {
e.stopPropagation();
const allPinned = bulkActions.pinDirection === "unpin";
try {
- const result =
- await hostClient.contextMenu.showBulkTaskContextMenu.mutate({
+ const result = await withSidebarPeekHeld(() =>
+ hostClient.contextMenu.showBulkTaskContextMenu.mutate({
taskCount: bulkActions.selectedCount,
allPinned,
runningCount: bulkActions.runningCount,
@@ -254,7 +255,8 @@ function SidebarMenuComponent() {
starred,
}),
),
- });
+ }),
+ );
if (!result.action) return;
const intent = resolveBulkTaskContextMenuIntent(result.action, {
@@ -290,11 +292,12 @@ function SidebarMenuComponent() {
const folder = findGroupFolder(folders, groupId);
if (!folder) return;
try {
- const result =
- await hostClient.contextMenu.showFolderContextMenu.mutate({
+ const result = await withSidebarPeekHeld(() =>
+ hostClient.contextMenu.showFolderContextMenu.mutate({
folderName: folder.name,
folderPath: folder.path,
- });
+ }),
+ );
if (result.action?.type === "remove") {
await removeFolder(folder.id);
} else if (result.action?.type === "external-app") {
@@ -354,32 +357,34 @@ function SidebarMenuComponent() {
currentUser.data?.id != null &&
taskMap.get(taskId)?.created_by?.id === currentUser.data.id;
- showContextMenu(task, e, {
- worktreePath: workspace?.worktreePath ?? undefined,
- folderPath: workspace?.folderPath ?? undefined,
- isPinned,
- isSuspended: taskData?.isSuspended,
- canStop:
- taskData?.taskRunEnvironment === "cloud" &&
- isTaskActivelyRunning(taskData),
- runId,
- isInCommandCenter,
- hasEmptyCommandCenterCell: true,
- canHandoff,
- onHandoff: () => setHandoffTaskId(task.id),
- onTogglePin: () => handleTaskTogglePin(taskId),
- onStop: (stopTaskId, taskTitle, stopRunId) =>
- setStopConfirm({
- taskId: stopTaskId,
- taskTitle,
- runId: stopRunId,
- }),
- onArchive: handleTaskArchive,
- onArchivePrior: handleArchivePrior,
- onAddToCommandCenter: () => {
- placeTaskInCommandCenter(taskId, task.title);
- },
- });
+ void withSidebarPeekHeld(() =>
+ showContextMenu(task, e, {
+ worktreePath: workspace?.worktreePath ?? undefined,
+ folderPath: workspace?.folderPath ?? undefined,
+ isPinned,
+ isSuspended: taskData?.isSuspended,
+ canStop:
+ taskData?.taskRunEnvironment === "cloud" &&
+ isTaskActivelyRunning(taskData),
+ runId,
+ isInCommandCenter,
+ hasEmptyCommandCenterCell: true,
+ canHandoff,
+ onHandoff: () => setHandoffTaskId(task.id),
+ onTogglePin: () => handleTaskTogglePin(taskId),
+ onStop: (stopTaskId, taskTitle, stopRunId) =>
+ setStopConfirm({
+ taskId: stopTaskId,
+ taskTitle,
+ runId: stopRunId,
+ }),
+ onArchive: handleTaskArchive,
+ onArchivePrior: handleArchivePrior,
+ onAddToCommandCenter: () => {
+ placeTaskInCommandCenter(taskId, task.title);
+ },
+ }),
+ );
}
};
diff --git a/products/desktop/packages/ui/src/features/sidebar/sidebarPeekStore.test.ts b/products/desktop/packages/ui/src/features/sidebar/sidebarPeekStore.test.ts
index 640a3f73f0a3..a6d0785aa8e1 100644
--- a/products/desktop/packages/ui/src/features/sidebar/sidebarPeekStore.test.ts
+++ b/products/desktop/packages/ui/src/features/sidebar/sidebarPeekStore.test.ts
@@ -6,6 +6,7 @@ import {
holdSidebarPeek,
releaseSidebarPeek,
useSidebarPeekStore,
+ withSidebarPeekHeld,
} from "./sidebarPeekStore";
const isPeeked = (): boolean => useSidebarPeekStore.getState().peek;
@@ -34,17 +35,19 @@ describe("sidebarPeekStore", () => {
expect(isPeeked()).toBe(false);
});
- it("keeps the peek open while held, then closes once released", () => {
+ it("keeps the peek open while held, then closes with the requested delay", () => {
beginSidebarPeek();
holdSidebarPeek();
- endSidebarPeek(0);
+ endSidebarPeek(200);
vi.runAllTimers();
expect(isPeeked()).toBe(true);
releaseSidebarPeek();
- endSidebarPeek(0);
- vi.runAllTimers();
+ vi.advanceTimersByTime(199);
+ expect(isPeeked()).toBe(true);
+
+ vi.advanceTimersByTime(1);
expect(isPeeked()).toBe(false);
});
@@ -52,14 +55,13 @@ describe("sidebarPeekStore", () => {
beginSidebarPeek();
holdSidebarPeek();
holdSidebarPeek();
+ endSidebarPeek(0);
releaseSidebarPeek();
- endSidebarPeek(0);
vi.runAllTimers();
expect(isPeeked()).toBe(true);
releaseSidebarPeek();
- endSidebarPeek(0);
vi.runAllTimers();
expect(isPeeked()).toBe(false);
});
@@ -81,6 +83,28 @@ describe("sidebarPeekStore", () => {
vi.advanceTimersByTime(200);
expect(isPeeked()).toBe(true);
+
+ releaseSidebarPeek();
+ vi.runAllTimers();
+ expect(isPeeked()).toBe(true);
+ });
+
+ it("keeps the peek open until an asynchronous menu closes", async () => {
+ beginSidebarPeek();
+ let closeMenu: (() => void) | undefined;
+ const menuClosed = new Promise<void>((resolve) => {
+ closeMenu = resolve;
+ });
+
+ const result = withSidebarPeekHeld(() => menuClosed);
+ endSidebarPeek(0);
+ vi.runAllTimers();
+ expect(isPeeked()).toBe(true);
+
+ closeMenu?.();
+ await result;
+ vi.runAllTimers();
+ expect(isPeeked()).toBe(false);
});
it("cancelSidebarPeek closes immediately and clears the hold", () => {
diff --git a/products/desktop/packages/ui/src/features/sidebar/sidebarPeekStore.ts b/products/desktop/packages/ui/src/features/sidebar/sidebarPeekStore.ts
index faec67500252..6477940d544a 100644
--- a/products/desktop/packages/ui/src/features/sidebar/sidebarPeekStore.ts
+++ b/products/desktop/packages/ui/src/features/sidebar/sidebarPeekStore.ts
@@ -20,11 +20,12 @@ export const useSidebarPeekStore = create<SidebarPeekStore>()((set) => ({
// panel itself) so re-entering any of them keeps the peek alive.
let hideTimer: ReturnType<typeof setTimeout> | null = null;
-// While a sidebar-spawned menu is open the peek is "held": endSidebarPeek is a
-// no-op so a pointer that leaves the panel (e.g. toward a submenu flyout) can't
-// collapse it and strand the open menu's portal anchor. Counted, not boolean,
-// so one menu's release can't drop a hold another menu still needs.
+// While a sidebar-spawned menu is open the peek is "held": endSidebarPeek is
+// deferred so a pointer that leaves the panel (e.g. toward a submenu flyout)
+// can't collapse it and strand the open menu's portal anchor. Counted, not
+// boolean, so one menu's release can't drop a hold another menu still needs.
let holdCount = 0;
+let pendingHideDelayMs: number | null = null;
const clearHideTimer = (): void => {
if (hideTimer) {
@@ -34,25 +35,43 @@ const clearHideTimer = (): void => {
};
export function beginSidebarPeek(): void {
+ pendingHideDelayMs = null;
clearHideTimer();
useSidebarPeekStore.getState().setPeek(true);
}
-// Pin the peek open while a menu spawned from the sidebar is open, and release
-// it when that menu closes. Paired open/close calls keep this balanced;
-// releasing hands control back to the hover logic, which collapses the peek on
-// the next pointer move outside the panel.
export function holdSidebarPeek(): void {
holdCount += 1;
clearHideTimer();
}
export function releaseSidebarPeek(): void {
- holdCount = Math.max(0, holdCount - 1);
+ if (holdCount === 0) return;
+
+ holdCount -= 1;
+ if (holdCount > 0 || pendingHideDelayMs === null) return;
+
+ const delayMs = pendingHideDelayMs;
+ pendingHideDelayMs = null;
+ endSidebarPeek(delayMs);
+}
+
+export async function withSidebarPeekHeld<T>(
+ operation: () => Promise<T>,
+): Promise<T> {
+ holdSidebarPeek();
+ try {
+ return await operation();
+ } finally {
+ releaseSidebarPeek();
+ }
}
export function endSidebarPeek(delayMs = 0): void {
- if (holdCount > 0) return;
+ if (holdCount > 0) {
+ pendingHideDelayMs = delayMs;
+ return;
+ }
clearHideTimer();
hideTimer = setTimeout(() => {
hideTimer = null;
@@ -62,6 +81,7 @@ export function endSidebarPeek(delayMs = 0): void {
export function cancelSidebarPeek(): void {
holdCount = 0;
+ pendingHideDelayMs = null;
clearHideTimer();
useSidebarPeekStore.getState().setPeek(false);
}