: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(desktop): give the composer send button instant feedback (#84077)
Adam Leith0ce00f3a7af7
diff --git a/products/desktop/packages/ui/src/features/message-editor/components/PromptInput.test.tsx b/products/desktop/packages/ui/src/features/message-editor/components/PromptInput.test.tsxindex 9f39fa5f493b..5438361cf6f2 100644--- a/products/desktop/packages/ui/src/features/message-editor/components/PromptInput.test.tsx+++ b/products/desktop/packages/ui/src/features/message-editor/components/PromptInput.test.tsx@@ -70,11 +70,22 @@ vi.mock("./SlotMachineSubmit", () => ({}));vi.mock("@posthog/quill", () => ({+ // Mirrors quill's Button: `loading` swaps the label for a spinner and blocks+ // activation.Button: ({children,+ loading,+ disabled,...props- }: React.ButtonHTMLAttributes<HTMLButtonElement>) => (- <button type="button" {...props}>+ }: React.ButtonHTMLAttributes<HTMLButtonElement> & {+ loading?: boolean;+ }) => (+ <button+ type="button"+ disabled={disabled || loading}+ aria-busy={loading || undefined}+ {...props}+ >{children}</button>),@@ -136,6 +147,30 @@ describe("PromptInput submit/stop affordance", () => {const send = screen.getByRole("button", { name: "Send message" });expect(send).toBeDisabled();});++ it("marks Send busy on click, before the surface reports anything", async () => {+ const user = userEvent.setup();+ // Surfaces flip their own busy flags only after a round trip, so a send+ // that never resolves must still register as pressed.+ const onSubmitClick = vi.fn();++ renderInput({ onSubmitClick });++ const send = screen.getByRole("button", { name: "Send message" });+ await user.click(send);++ expect(onSubmitClick).toHaveBeenCalledOnce();+ expect(send).toHaveAttribute("aria-busy", "true");+ expect(send).toBeDisabled();+ });++ it("keeps Send busy while the surface is both loading and untypeable", () => {+ // The new-task composer's whole task creation looks like this.+ renderInput({ disabled: true, isLoading: true });++ const send = screen.getByRole("button", { name: "Send message" });+ expect(send).toHaveAttribute("aria-busy", "true");+ });});describe("PromptInput escape handling", () => {diff --git a/products/desktop/packages/ui/src/features/message-editor/components/PromptInput.tsx b/products/desktop/packages/ui/src/features/message-editor/components/PromptInput.tsxindex 6b7d8e13fa85..56e100177909 100644--- a/products/desktop/packages/ui/src/features/message-editor/components/PromptInput.tsx+++ b/products/desktop/packages/ui/src/features/message-editor/components/PromptInput.tsx@@ -36,6 +36,11 @@ import { SlotMachineSubmit } from "./SlotMachineSubmit";export type { EditorHandle };+// How long the send button holds its own busy state when the surface never+// reports one — long enough to register as a press, short enough that a send+// the surface silently refuses doesn't strand the spinner.+const SUBMIT_PRESS_FEEDBACK_MS = 800;+export interface PromptInputProps {sessionId: string;placeholder?: string;@@ -381,7 +386,14 @@ export const PromptInput = forwardRef<EditorHandle, PromptInputProps>(e.stopPropagation();}, []);+ // Instant press feedback. Every surface that owns this composer flips its+ // own busy flags only after a round trip (a usage pre-flight, a worktree+ // probe, the send itself), so without this the button sits inert on click.+ const [pressedSubmit, setPressedSubmit] = useState(false);+ const surfaceBusy = disabled || isLoading || submitDisabledExternal;+const doSubmit = useCallback(() => {+ setPressedSubmit(true);if (onSubmitClick) {onSubmitClick();} else {@@ -389,6 +401,21 @@ export const PromptInput = forwardRef<EditorHandle, PromptInputProps>(}}, [onSubmitClick, submit]);+ // Hand over as soon as the surface reports busy itself, so the two states+ // never fight over the button.+ useEffect(() => {+ if (!pressedSubmit) return;+ if (surfaceBusy) {+ setPressedSubmit(false);+ return;+ }+ const timer = setTimeout(+ () => setPressedSubmit(false),+ SUBMIT_PRESS_FEEDBACK_MS,+ );+ return () => clearTimeout(timer);+ }, [pressedSubmit, surfaceBusy]);+const handleSubmitClick = (e: React.MouseEvent) => {e.stopPropagation();doSubmit();@@ -399,9 +426,15 @@ export const PromptInput = forwardRef<EditorHandle, PromptInputProps>(// that is not running, a compacting Pi session), and the editor cannot be// typed into, so a live send button only invites a click that misfires.const submitBlocked = disabled || submitDisabledExternal || isEmpty;- const submitTooltip =- submitTooltipOverride ??- (submitBlocked ? "Enter a message" : "Send message");+ // A surface that is loading *and* locked out of typing is working on the+ // send itself, so the button keeps spinning until it lands. A surface that+ // is loading but still typeable is mid-turn and accepting queued messages,+ // where send has to stay live.+ const submitBusy = pressedSubmit || (disabled && isLoading);+ const submitTooltip = submitBusy+ ? "Sending"+ : (submitTooltipOverride ??+ (submitBlocked ? "Enter a message" : "Send message"));// Stop takes priority over everything: you cancel a run, you don't gamble// on it. With slot machine mode on, the send affordance moves out to the@@ -428,7 +461,8 @@ export const PromptInput = forwardRef<EditorHandle, PromptInputProps>(variant="primary"size="icon"onClick={handleSubmitClick}- disabled={submitBlocked}+ disabled={submitBlocked || submitBusy}+ loading={submitBusy}aria-label="Send message"className="rounded-xs"{...(tourTarget && { "data-tour": `${tourTarget}-submit` })}@@ -564,7 +598,7 @@ export const PromptInput = forwardRef<EditorHandle, PromptInputProps>(</InputGroup>{slotMachineMode && !inStopMode && (<SlotMachineSubmit- disabled={submitBlocked}+ disabled={submitBlocked || submitBusy}onSubmit={doSubmit}tourTarget={tourTarget}/>diff --git a/products/desktop/packages/ui/src/features/task-detail/components/TaskInput.tsx b/products/desktop/packages/ui/src/features/task-detail/components/TaskInput.tsxindex 022d8a0f7e1b..527320bf661d 100644--- a/products/desktop/packages/ui/src/features/task-detail/components/TaskInput.tsx+++ b/products/desktop/packages/ui/src/features/task-detail/components/TaskInput.tsx@@ -25,6 +25,7 @@ import {useTaskRepositoryDraftStore,} from "@posthog/ui/features/canvas/stores/taskRepositoryDraftStore";import { openSettings } from "@posthog/ui/features/settings/hooks/useOpenSettings";+import { NEW_TASK_COMPOSER_FADE_MS } from "@posthog/ui/features/task-detail/newTaskComposerTransition";import type { TaskInputReportAssociation } from "@posthog/ui/features/task-detail/stores/taskInputPrefillStore";import { useTaskInputPrefillStore } from "@posthog/ui/features/task-detail/stores/taskInputPrefillStore";import { navigateToInbox } from "@posthog/ui/router/navigationBridge";@@ -975,6 +976,7 @@ export function TaskInput({const {isCreatingTask,+ isExitingComposer,canSubmit,handleSubmit,additionalDirectories,@@ -1265,8 +1267,16 @@ export function TaskInput({// suggestions fade out (and back in when the prompt is cleared).top: suggestions && suggestions.length > 0 ? "38%" : "50%",transform: "translate(-50%, -50%)",+ // Once the task is on its way, the whole composer fades out and+ // the pending chat fades in over it.+ opacity: isExitingComposer ? 0 : 1,+ transitionProperty: "opacity",+ transitionDuration: `${NEW_TASK_COMPOSER_FADE_MS}ms`,+ transitionTimingFunction: "ease-out",}}- className="absolute left-1/2 z-1 flex w-[calc(100%-2rem)] max-w-[600px] flex-col gap-2"+ className={`absolute left-1/2 z-1 flex w-[calc(100%-2rem)] max-w-[600px] flex-col gap-2 ${+ isExitingComposer ? "pointer-events-none" : ""+ }`}><Flexgap="2"diff --git a/products/desktop/packages/ui/src/features/task-detail/components/TaskPendingView.tsx b/products/desktop/packages/ui/src/features/task-detail/components/TaskPendingView.tsxindex b8ac6c5c74c5..70aa02e57d97 100644--- a/products/desktop/packages/ui/src/features/task-detail/components/TaskPendingView.tsx+++ b/products/desktop/packages/ui/src/features/task-detail/components/TaskPendingView.tsx@@ -1,4 +1,5 @@-import { Box } from "@radix-ui/themes";+import { NEW_TASK_COMPOSER_FADE_MS } from "@posthog/ui/features/task-detail/newTaskComposerTransition";+import { motion } from "framer-motion";import { usePendingTaskPrompt } from "../../../shell/pendingTaskPromptStore";import { PendingChatView } from "../../sessions/components/PendingChatView";@@ -10,11 +11,21 @@ export function TaskPendingView({ pendingTaskKey }: TaskPendingViewProps) {const pending = usePendingTaskPrompt(pendingTaskKey);return (- <Box className="relative h-full w-full bg-background">+ // Picks up where the new-task composer's fade-out left off, so submitting+ // reads as one phase handing over to the next.+ <motion.div+ initial={{ opacity: 0 }}+ animate={{ opacity: 1 }}+ transition={{+ duration: NEW_TASK_COMPOSER_FADE_MS / 1000,+ ease: "easeOut",+ }}+ className="relative h-full w-full bg-background"+ ><PendingChatViewpromptText={pending?.promptText ?? ""}attachments={pending?.attachments}/>- </Box>+ </motion.div>);}diff --git a/products/desktop/packages/ui/src/features/task-detail/hooks/useTaskCreation.ts b/products/desktop/packages/ui/src/features/task-detail/hooks/useTaskCreation.tsindex d52f8c4bb290..5c7e1e6d8cc3 100644--- a/products/desktop/packages/ui/src/features/task-detail/hooks/useTaskCreation.ts+++ b/products/desktop/packages/ui/src/features/task-detail/hooks/useTaskCreation.ts@@ -23,6 +23,7 @@ import type { ExecutionMode, Task } from "@posthog/shared/domain-types";import { useTaskChannels } from "@posthog/ui/features/canvas/hooks/useTaskChannels";import { useTaskRepositoryDraftStore } from "@posthog/ui/features/canvas/stores/taskRepositoryDraftStore";import { useFeatureFlag } from "@posthog/ui/features/feature-flags/useFeatureFlag";+import { waitForComposerExit } from "@posthog/ui/features/task-detail/newTaskComposerTransition";import { useTaskInputPrefillStore } from "@posthog/ui/features/task-detail/stores/taskInputPrefillStore";import { navigateToTaskPending } from "@posthog/ui/router/navigationBridge";import { openTask, openTaskInput } from "@posthog/ui/router/useOpenTask";@@ -115,6 +116,8 @@ interface UseTaskCreationOptions {interface UseTaskCreationReturn {isCreatingTask: boolean;+ /** The task is on its way; the composer fades out before the chat replaces it. */+ isExitingComposer: boolean;canSubmit: boolean;handleSubmit: (contentOverride?: EditorContent) => Promise<boolean>;additionalDirectories: string[];@@ -202,6 +205,7 @@ export function useTaskCreation({onTaskCreatedEffect,}: UseTaskCreationOptions): UseTaskCreationReturn {const [isCreatingTask, setIsCreatingTask] = useState(false);+ const [isExitingComposer, setIsExitingComposer] = useState(false);const hostClient = useHostTRPCClient();const trpc = useHostTRPC();const queryClient = useQueryClient();@@ -343,6 +347,10 @@ export function useTaskCreation({label: a.label,})),});+ // Fade the composer out before the chat fades in, so the phases+ // hand over instead of cutting.+ setIsExitingComposer(true);+ await waitForComposerExit();navigateToTaskPending(pendingTaskKey);if (!contentOverride) {editor.clear();@@ -554,6 +562,7 @@ export function useTaskCreation({}} finally {setIsCreatingTask(false);+ setIsExitingComposer(false);}},[@@ -603,6 +612,7 @@ export function useTaskCreation({return {isCreatingTask,+ isExitingComposer,canSubmit,handleSubmit,additionalDirectories,diff --git a/products/desktop/packages/ui/src/features/task-detail/newTaskComposerTransition.ts b/products/desktop/packages/ui/src/features/task-detail/newTaskComposerTransition.tsnew file mode 100644index 000000000000..eb0952b3c15a--- /dev/null+++ b/products/desktop/packages/ui/src/features/task-detail/newTaskComposerTransition.ts@@ -0,0 +1,12 @@+/**+ * How long the new-task composer takes to fade out once its task has been+ * submitted, and how long the pending chat takes to fade back in over it.+ */+export const NEW_TASK_COMPOSER_FADE_MS = 160;++/** Resolves once the composer's fade-out has had its full window. */+export function waitForComposerExit(): Promise<void> {+ return new Promise((resolve) =>+ setTimeout(resolve, NEW_TASK_COMPOSER_FADE_MS),+ );+}