Skip to content
This repository was archived by the owner on Aug 6, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof setTimeout> | 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -18,6 +19,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";
Expand Down Expand Up @@ -247,6 +249,18 @@ export function SessionView({
[onSendPrompt],
);

const { isOnline } = useConnectivity();
const handleBeforeSubmit = useCallback(
(text: string, clearEditor: () => void): boolean => {
if (!isOnline) {
showOfflineToast();
return false;
}
return onBeforeSubmit ? onBeforeSubmit(text, clearEditor) : true;
},
[isOnline, onBeforeSubmit],
);
Comment thread
charlesvien marked this conversation as resolved.
Resolved

const [isDraggingFile, setIsDraggingFile] = useState(false);
const editorRef = useRef<PromptInputHandle>(null);
const dragCounterRef = useRef(0);
Expand Down Expand Up @@ -645,7 +659,7 @@ export function SessionView({
/>
) : null
}
onBeforeSubmit={onBeforeSubmit}
onBeforeSubmit={handleBeforeSubmit}
onSubmit={handleSubmit}
onBashCommand={onBashCommand}
onCancel={onCancelPrompt}
Expand Down
Loading