From 7556d9f5c3956fd5b377bba107f234f918f468bf 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 | 22 ++++++++++++++++++- 1 file changed, 21 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 c542a1fccf..01eccf839f 100644 --- a/apps/code/src/renderer/features/sessions/components/SessionView.tsx +++ b/apps/code/src/renderer/features/sessions/components/SessionView.tsx @@ -18,6 +18,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 { toast } from "@renderer/utils/toast"; @@ -247,6 +248,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); @@ -645,7 +665,7 @@ export function SessionView({ /> ) : null } - onBeforeSubmit={onBeforeSubmit} + onBeforeSubmit={handleBeforeSubmit} onSubmit={handleSubmit} onBashCommand={onBashCommand} onCancel={onCancelPrompt} From 2ec429c54b54a56a201a0fcc7ed8d3a9cbdd2411 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 | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/apps/code/src/renderer/features/sessions/components/SessionView.tsx b/apps/code/src/renderer/features/sessions/components/SessionView.tsx index 01eccf839f..3f6462b7f8 100644 --- a/apps/code/src/renderer/features/sessions/components/SessionView.tsx +++ b/apps/code/src/renderer/features/sessions/components/SessionView.tsx @@ -249,19 +249,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 f528315d4b3bf199f1603e0f3ff70d20e4ea9835 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 0000000000..0967ef424b --- /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 7e3ac63946..e5d5ba781d 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 3f6462b7f8..cb760fe57f 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, @@ -251,7 +252,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 07a6147e08b4b2642e125ea5e8ae6610a4da4232 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 0967ef424b..0000000000 --- a/.claude/settings.local.json +++ /dev/null @@ -1 +0,0 @@ -{}