fix(sessions): preserve prompt when sending while offline#1971
fix(sessions): preserve prompt when sending while offline#1971posthog[bot] wants to merge 4 commits intomainfrom
Conversation
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
Generated-By: PostHog Code Task-Id: ba36fa8e-ca18-4fd5-9d57-9bca8825814a
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
apps/code/src/renderer/features/sessions/components/SessionView.tsx:249-255
**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],
);
```
Reviews (1): Last reviewed commit: "fix(sessions): drop redundant offline to..." | Re-trigger Greptile |
| const handleBeforeSubmit = useCallback( | ||
| (text: string, clearEditor: () => void): boolean => { | ||
| if (!isOnline) return false; | ||
| return onBeforeSubmit ? onBeforeSubmit(text, clearEditor) : true; | ||
| }, | ||
| [isOnline, onBeforeSubmit], | ||
| ); |
There was a problem hiding this 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.
| 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.There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
onBeforeSubmitpassed (no connectivity check),onSubmitfired, editor clearedsendPromptthrew asynchronously- 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.
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
Generated-By: PostHog Code Task-Id: ba36fa8e-ca18-4fd5-9d57-9bca8825814a
Summary
Pressing Enter in the message editor while offline used to clear the typed prompt even though the message never reached the agent. The connectivity check inside
service.sendPrompt()throws asynchronously, butuseTiptapEditor.submit()already runsdoClear()synchronously afteronSubmitfires — so the input was wiped before the offline error could be caught.This wraps the existing
onBeforeSubmithook (which is already designed to gate clearing — returningfalseshort-circuits bothonSubmitand the editor's auto-clear) at theSessionViewlevel with a connectivity check. The typed message stays in the editor, and a stable-id toast gives immediate feedback that the send didn't go through. BothTaskLogsPanelandCommandCenterSessionViewbenefit since they shareSessionView.The new-task input (
TaskInput) already disables submit when offline, so it isn't affected.Test plan
onBeforeSubmitstill delegates touseBranchMismatchDialog.handleBeforeSubmit).Created with PostHog Code