Skip to content
Open
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 @@ -17,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 type { TaskRunStatus } from "@shared/types";
Expand Down Expand Up @@ -244,6 +246,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 on lines +250 to +259
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 No user feedback when submit is blocked offline

handleBeforeSubmit silently returns false when offline, so the editor content is preserved (correct) but the user gets no indication of why their submit was ignored. The PR description and test plan explicitly state "a 'Can't send while offline' toast appears," but no such toast is fired here.

The existing connectivity toast in connectivityToast.ts is debounced by 5 s, so if the user goes offline and tries to send within that window, the submit silently no-ops with zero feedback. A toast.error(…) call is needed inside the if (!isOnline) branch.

Suggested change
const handleBeforeSubmit = useCallback(
(text: string, clearEditor: () => void): boolean => {
if (!isOnline) return false;
return onBeforeSubmit ? onBeforeSubmit(text, clearEditor) : true;
},
[isOnline, onBeforeSubmit],
);
const handleBeforeSubmit = useCallback(
(text: string, clearEditor: () => void): boolean => {
if (!isOnline) {
toast.error("Can't send while offline", {
id: "send-offline",
description: "Reconnect to the network and try again.",
});
return false;
}
return onBeforeSubmit ? onBeforeSubmit(text, clearEditor) : true;
},
[isOnline, onBeforeSubmit],
);
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/renderer/features/sessions/components/SessionView.tsx
Line: 249-255

Comment:
**No user feedback when submit is blocked offline**

`handleBeforeSubmit` silently returns `false` when offline, so the editor content is preserved (correct) but the user gets no indication of *why* their submit was ignored. The PR description and test plan explicitly state "a 'Can't send while offline' toast appears," but no such toast is fired here.

The existing connectivity toast in `connectivityToast.ts` is debounced by 5 s, so if the user goes offline and tries to send within that window, the submit silently no-ops with zero feedback. A `toast.error(…)` call is needed inside the `if (!isOnline)` branch.

```suggestion
  const handleBeforeSubmit = useCallback(
    (text: string, clearEditor: () => void): boolean => {
      if (!isOnline) {
        toast.error("Can't send while offline", {
          id: "send-offline",
          description: "Reconnect to the network and try again.",
        });
        return false;
      }
      return onBeforeSubmit ? onBeforeSubmit(text, clearEditor) : true;
    },
    [isOnline, onBeforeSubmit],
  );
```

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

originally, is the general toast for connectivity shown after this prompt is submitted? so if this stays as is, we would not be showing anything?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's correct. The general connectivity toast from connectivityToast.ts fires on the isOnline state transition (after a 5-second debounce), not in response to a submit attempt. So it would show up regardless of whether the user tried to submit or not.

In the original (pre-PR) flow:

  1. onBeforeSubmit passed (no connectivity check), onSubmit fired, editor cleared
  2. sendPrompt threw asynchronously
  3. The general offline toast appeared only after the 5s debounce (unrelated to the submit)

With this PR, if the user goes offline and submits within that 5-second window, handleBeforeSubmit returns false silently — the debounced toast hasn't appeared yet and there's no submit-specific toast either, so they get zero feedback. After the 5s window the general toast is already visible, so the silent no-op is more tolerable, but it's still not great UX.

Adding a toast.error(...) in the !isOnline branch (as I originally suggested) would handle the window case and give immediate, action-specific feedback regardless of when the user goes offline.

Tip: You can customize Greptile's behavior for this repo with .greptile/rules.md and .greptile/config.json.


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