From b83d9bb611c563c80319fcbb74e4f473842d01e6 Mon Sep 17 00:00:00 2001 From: PostHog Code Date: Fri, 1 May 2026 10:08:51 +0000 Subject: [PATCH 1/4] fix(sessions): preserve prompt when sending while offline MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pressing Enter in the message editor while offline used to clear the input even though the prompt never reached the agent — the connectivity check in sendPrompt() throws asynchronously, but the editor's doClear() already ran synchronously after onSubmit fired. Wraps the editor's onBeforeSubmit at the SessionView level with an offline guard. Returning false short-circuits both onSubmit and the editor's auto-clear, so the typed message stays put. A stable-id toast gives immediate feedback that the send didn't go through. Generated-By: PostHog Code Task-Id: ba36fa8e-ca18-4fd5-9d57-9bca8825814a --- .../sessions/components/SessionView.tsx | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/apps/code/src/renderer/features/sessions/components/SessionView.tsx b/apps/code/src/renderer/features/sessions/components/SessionView.tsx index d195c5ce5..09dafa84a 100644 --- a/apps/code/src/renderer/features/sessions/components/SessionView.tsx +++ b/apps/code/src/renderer/features/sessions/components/SessionView.tsx @@ -17,6 +17,7 @@ import type { Plan } from "@features/sessions/types"; import { useSettingsStore } from "@features/settings/stores/settingsStore"; import { useIsWorkspaceCloudRun } from "@features/workspace/hooks/useWorkspace"; import { useAutoFocusOnTyping } from "@hooks/useAutoFocusOnTyping"; +import { useConnectivity } from "@hooks/useConnectivity"; import { Pause, Spinner, Warning } from "@phosphor-icons/react"; import { Box, Button, ContextMenu, Flex, Text } from "@radix-ui/themes"; import type { TaskRunStatus } from "@shared/types"; @@ -26,6 +27,7 @@ import { isJsonRpcResponse, } from "@shared/types/session-events"; import { getFilePath } from "@utils/getFilePath"; +import { toast } from "@utils/toast"; import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { getSessionService } from "../service/service"; import { flattenSelectOptions } from "../stores/sessionStore"; @@ -244,6 +246,25 @@ export function SessionView({ [onSendPrompt], ); + const { isOnline } = useConnectivity(); + // Gate submission on connectivity so the editor isn't cleared by an Enter + // press that won't actually reach the agent. Returning false from + // onBeforeSubmit short-circuits both onSubmit and the editor's auto-clear. + const handleBeforeSubmit = useCallback( + (text: string, clearEditor: () => void): boolean => { + if (!isOnline) { + toast.error("Can't send while offline", { + id: "send-prompt-offline", + description: + "Your message has been kept — try again once you're back online.", + }); + return false; + } + return onBeforeSubmit ? onBeforeSubmit(text, clearEditor) : true; + }, + [isOnline, onBeforeSubmit], + ); + const [isDraggingFile, setIsDraggingFile] = useState(false); const editorRef = useRef(null); const dragCounterRef = useRef(0); @@ -643,7 +664,7 @@ export function SessionView({ /> ) : null } - onBeforeSubmit={onBeforeSubmit} + onBeforeSubmit={handleBeforeSubmit} onSubmit={handleSubmit} onBashCommand={onBashCommand} onCancel={onCancelPrompt} From 932a5842788d500dd9970a29c3d34892f033fafd Mon Sep 17 00:00:00 2001 From: PostHog Code Date: Fri, 1 May 2026 10:14:22 +0000 Subject: [PATCH 2/4] fix(sessions): drop redundant offline toast and comments Generated-By: PostHog Code Task-Id: ba36fa8e-ca18-4fd5-9d57-9bca8825814a --- .../features/sessions/components/SessionView.tsx | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/apps/code/src/renderer/features/sessions/components/SessionView.tsx b/apps/code/src/renderer/features/sessions/components/SessionView.tsx index 09dafa84a..8fd2678e2 100644 --- a/apps/code/src/renderer/features/sessions/components/SessionView.tsx +++ b/apps/code/src/renderer/features/sessions/components/SessionView.tsx @@ -27,7 +27,6 @@ import { isJsonRpcResponse, } from "@shared/types/session-events"; import { getFilePath } from "@utils/getFilePath"; -import { toast } from "@utils/toast"; import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { getSessionService } from "../service/service"; import { flattenSelectOptions } from "../stores/sessionStore"; @@ -247,19 +246,9 @@ export function SessionView({ ); const { isOnline } = useConnectivity(); - // Gate submission on connectivity so the editor isn't cleared by an Enter - // press that won't actually reach the agent. Returning false from - // onBeforeSubmit short-circuits both onSubmit and the editor's auto-clear. const handleBeforeSubmit = useCallback( (text: string, clearEditor: () => void): boolean => { - if (!isOnline) { - toast.error("Can't send while offline", { - id: "send-prompt-offline", - description: - "Your message has been kept — try again once you're back online.", - }); - return false; - } + if (!isOnline) return false; return onBeforeSubmit ? onBeforeSubmit(text, clearEditor) : true; }, [isOnline, onBeforeSubmit], From fcbabb72213faba7af764a60b79a8a836ba6878c Mon Sep 17 00:00:00 2001 From: PostHog Code Date: Fri, 1 May 2026 10:32:14 +0000 Subject: [PATCH 3/4] fix(sessions): surface existing connectivity toast on offline submit Within the 5s offline-debounce window, blocking submit silently was indistinguishable from a no-op. Reuse the same global connectivity toast (same id, same message) instead of inventing a new one. Generated-By: PostHog Code Task-Id: ba36fa8e-ca18-4fd5-9d57-9bca8825814a --- .claude/settings.local.json | 1 + .../features/connectivity/connectivityToast.ts | 18 +++++++++--------- .../sessions/components/SessionView.tsx | 6 +++++- 3 files changed, 15 insertions(+), 10 deletions(-) create mode 100644 .claude/settings.local.json diff --git a/.claude/settings.local.json b/.claude/settings.local.json new file mode 100644 index 000000000..0967ef424 --- /dev/null +++ b/.claude/settings.local.json @@ -0,0 +1 @@ +{} diff --git a/apps/code/src/renderer/features/connectivity/connectivityToast.ts b/apps/code/src/renderer/features/connectivity/connectivityToast.ts index 7e3ac6394..e5d5ba781 100644 --- a/apps/code/src/renderer/features/connectivity/connectivityToast.ts +++ b/apps/code/src/renderer/features/connectivity/connectivityToast.ts @@ -5,21 +5,21 @@ import { toast as sonnerToast } from "sonner"; const TOAST_ID = "connectivity-offline"; const OFFLINE_DEBOUNCE_MS = 5_000; +export function showOfflineToast() { + toast.error("No internet connection", { + id: TOAST_ID, + duration: Number.POSITIVE_INFINITY, + description: + "PostHog Code features that need the network are paused until you reconnect.", + }); +} + // Debounces flaky transitions: only surfaces a toast when the app has been // continuously offline for OFFLINE_DEBOUNCE_MS. The stable id guarantees the // toast never stacks; coming back online dismisses it automatically. export function initializeConnectivityToast() { let pendingTimer: ReturnType | null = null; - const showOfflineToast = () => { - toast.error("No internet connection", { - id: TOAST_ID, - duration: Number.POSITIVE_INFINITY, - description: - "PostHog Code features that need the network are paused until you reconnect.", - }); - }; - const clearPending = () => { if (pendingTimer) { clearTimeout(pendingTimer); diff --git a/apps/code/src/renderer/features/sessions/components/SessionView.tsx b/apps/code/src/renderer/features/sessions/components/SessionView.tsx index 8fd2678e2..8c99ffb2a 100644 --- a/apps/code/src/renderer/features/sessions/components/SessionView.tsx +++ b/apps/code/src/renderer/features/sessions/components/SessionView.tsx @@ -1,5 +1,6 @@ import { isOtherOption } from "@components/action-selector/constants"; import { PermissionSelector } from "@components/permissions/PermissionSelector"; +import { showOfflineToast } from "@features/connectivity/connectivityToast"; import { PromptInput, type EditorHandle as PromptInputHandle, @@ -248,7 +249,10 @@ export function SessionView({ const { isOnline } = useConnectivity(); const handleBeforeSubmit = useCallback( (text: string, clearEditor: () => void): boolean => { - if (!isOnline) return false; + if (!isOnline) { + showOfflineToast(); + return false; + } return onBeforeSubmit ? onBeforeSubmit(text, clearEditor) : true; }, [isOnline, onBeforeSubmit], From 8a5548d982f82662bc0b6e15160d20bb14d1dbf8 Mon Sep 17 00:00:00 2001 From: PostHog Code Date: Fri, 1 May 2026 10:33:40 +0000 Subject: [PATCH 4/4] chore: untrack accidentally committed local settings file Generated-By: PostHog Code Task-Id: ba36fa8e-ca18-4fd5-9d57-9bca8825814a --- .claude/settings.local.json | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .claude/settings.local.json diff --git a/.claude/settings.local.json b/.claude/settings.local.json deleted file mode 100644 index 0967ef424..000000000 --- a/.claude/settings.local.json +++ /dev/null @@ -1 +0,0 @@ -{}