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): don't focus composer when clicking the thread pane (#77522)

Adam Leith50490943ef73
diff --git a/products/desktop/packages/ui/src/features/pi-sessions/PiSessionView.tsx b/products/desktop/packages/ui/src/features/pi-sessions/PiSessionView.tsx
index 84acab32922f..c801138bd01a 100644
--- a/products/desktop/packages/ui/src/features/pi-sessions/PiSessionView.tsx
+++ b/products/desktop/packages/ui/src/features/pi-sessions/PiSessionView.tsx
@@ -40,7 +40,6 @@ import {
import { ContextUsageIndicator } from "@posthog/ui/features/sessions/components/ContextUsageIndicator";
import { ChatThread } from "@posthog/ui/features/sessions/components/chat-thread/ChatThread";
import type { PromptRecallHandler } from "@posthog/ui/features/sessions/components/chat-thread/composerPromptRecall";
-import { focusComposerOnPaneClick } from "@posthog/ui/features/sessions/components/focusComposerOnPaneClick";
import { SessionInitializingView } from "@posthog/ui/features/sessions/components/SessionInitializingView";
import { CHAT_CONTENT_MAX_WIDTH } from "@posthog/ui/features/sessions/constants";
import { useMessagingModeStore } from "@posthog/ui/features/sessions/messagingModeStore";
@@ -391,18 +390,6 @@ function usePiRetry(
}, [controller, taskId]);
}
-function usePiThreadClick(
- draftActions: DraftActions,
- taskId: string,
-): (event: React.MouseEvent) => void {
- return useCallback(
- (event: React.MouseEvent) => {
- focusComposerOnPaneClick(event, () => draftActions.requestFocus(taskId));
- },
- [draftActions, taskId],
- );
-}
-
function usePiRestart(
controller: PiSessionController,
taskId: string,
@@ -550,7 +537,6 @@ export function PiSessionView({
const runBashCommand = usePiBash(piSessionController, taskId);
const cancelPrompt = usePiCancel(piSessionController, taskId, isBashRunning);
const retry = usePiRetry(piSessionController, taskId);
- const handleThreadClick = usePiThreadClick(draftActions, taskId);
const restart = usePiRestart(piSessionController, taskId);
const { change: changeProjectTrust, pending: projectTrustPending } =
usePiProjectTrustChange(piSessionController, taskId);
@@ -676,7 +662,7 @@ export function PiSessionView({
onRestart={restart}
/>
)}
- <Box className="min-h-0 flex-1" onClick={handleThreadClick}>
+ <Box className="min-h-0 flex-1">
<ChatThread
events={session.events}
isPromptPending={isStreaming}
diff --git a/products/desktop/packages/ui/src/features/sessions/components/SessionView.tsx b/products/desktop/packages/ui/src/features/sessions/components/SessionView.tsx
index e3fbc2e2a019..32538925c1a7 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/SessionView.tsx
+++ b/products/desktop/packages/ui/src/features/sessions/components/SessionView.tsx
@@ -34,7 +34,6 @@ import {
getGithubRefUrlFromEventTarget,
} from "@posthog/ui/features/sessions/components/copyContextTarget";
import { DropZoneOverlay } from "@posthog/ui/features/sessions/components/DropZoneOverlay";
-import { focusComposerOnPaneClick } from "@posthog/ui/features/sessions/components/focusComposerOnPaneClick";
import { PendingChatView } from "@posthog/ui/features/sessions/components/PendingChatView";
import { PlanStatusBar } from "@posthog/ui/features/sessions/components/PlanStatusBar";
import { QueuedMessagesDock } from "@posthog/ui/features/sessions/components/QueuedMessagesDock";
@@ -582,10 +581,6 @@ export function SessionView({
.catch(() => toast.error("Failed to attach files"));
}, []);
- const handlePaneClick = useCallback((event: React.MouseEvent) => {
- focusComposerOnPaneClick(event, () => editorRef.current?.focus());
- }, []);
-
useAutoFocusOnTyping(editorRef, !isActiveSession);
const handleContextMenu = useCallback((e: React.MouseEvent) => {
@@ -619,7 +614,6 @@ export function SessionView({
direction="column"
height="100%"
className="relative bg-background"
- onClick={handlePaneClick}
onContextMenu={handleContextMenu}
onDragEnter={handleDragEnter}
onDragLeave={handleDragLeave}
diff --git a/products/desktop/packages/ui/src/features/sessions/components/focusComposerOnPaneClick.test.ts b/products/desktop/packages/ui/src/features/sessions/components/focusComposerOnPaneClick.test.ts
deleted file mode 100644
index bde422324c7f..000000000000
--- a/products/desktop/packages/ui/src/features/sessions/components/focusComposerOnPaneClick.test.ts
+++ /dev/null
@@ -1,53 +0,0 @@
-import type { MouseEvent as ReactMouseEvent } from "react";
-import { afterEach, describe, expect, it, vi } from "vitest";
-import { focusComposerOnPaneClick } from "./focusComposerOnPaneClick";
-
-function clickTarget(target: EventTarget): Pick<ReactMouseEvent, "target"> {
- return { target };
-}
-
-afterEach(() => {
- window.getSelection()?.removeAllRanges();
- document.body.replaceChildren();
-});
-
-describe("focusComposerOnPaneClick", () => {
- it.each([
- {
- name: "chat content",
- markup: '<p id="target">Chat content</p>',
- expectsFocus: true,
- },
- {
- name: "an interactive element",
- markup: '<button id="target">Open</button>',
- expectsFocus: false,
- },
- {
- name: "content marked as interactive",
- markup: '<span id="target" data-interactive>Open</span>',
- expectsFocus: false,
- },
- ])("focuses for $name only when appropriate", ({ markup, expectsFocus }) => {
- document.body.innerHTML = markup;
- const focusComposer = vi.fn();
- const target = document.getElementById("target") as HTMLElement;
-
- focusComposerOnPaneClick(clickTarget(target), focusComposer);
-
- expect(focusComposer).toHaveBeenCalledTimes(expectsFocus ? 1 : 0);
- });
-
- it("does not focus while selecting chat content", () => {
- document.body.innerHTML = '<p id="target">Chat content</p>';
- const target = document.getElementById("target") as HTMLElement;
- const range = document.createRange();
- range.selectNodeContents(target);
- window.getSelection()?.addRange(range);
- const focusComposer = vi.fn();
-
- focusComposerOnPaneClick(clickTarget(target), focusComposer);
-
- expect(focusComposer).not.toHaveBeenCalled();
- });
-});
diff --git a/products/desktop/packages/ui/src/features/sessions/components/focusComposerOnPaneClick.ts b/products/desktop/packages/ui/src/features/sessions/components/focusComposerOnPaneClick.ts
deleted file mode 100644
index a23d29698c67..000000000000
--- a/products/desktop/packages/ui/src/features/sessions/components/focusComposerOnPaneClick.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import type { MouseEvent } from "react";
-
-const INTERACTIVE_SELECTOR =
- 'button, a, input, textarea, select, [role="button"], [role="link"], [contenteditable="true"], [data-interactive]';
-
-export function focusComposerOnPaneClick(
- event: Pick<MouseEvent, "target">,
- focusComposer: () => void,
-): void {
- const target = event.target;
- if (!(target instanceof Element) || target.closest(INTERACTIVE_SELECTOR)) {
- return;
- }
-
- const selection = window.getSelection();
- if (selection && selection.toString().length > 0) {
- return;
- }
-
- focusComposer();
-}