Skip to content

Commit d835e43

Browse files
t3dotggclaudejuliusmarminge
authored
fix(web): question answers submit while normal sends are blocked (pingdotgg#22874)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Julius Marminge <[email protected]>
1 parent 52d621a commit d835e43

4 files changed

Lines changed: 84 additions & 36 deletions

File tree

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ import { cn, isMacPlatform, randomUUID } from "~/lib/utils";
223223
import {
224224
getComposerPromptLengthValidationMessage,
225225
getComposerSubmissionValidationMessage,
226+
isComposerSubmissionBlocked,
226227
submitComposerDraft,
227228
} from "./composerSubmission";
228229
import { ComposerPromptLengthValidation } from "./ComposerPromptLengthValidation";
@@ -1823,8 +1824,21 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
18231824
},
18241825
});
18251826
const { blocksSubmission: voiceInputActive, submitAfterDictation } = speechInput;
1826-
const voiceSendDisabledReason =
1827-
sendDisabledReason ?? (speechInput.preparing ? "Preparing voice input" : null);
1827+
const submissionTarget = activePendingProgress ? "pending-user-input" : "provider-turn";
1828+
const submissionBlocked = isComposerSubmissionBlocked({
1829+
submissionTarget,
1830+
noProviderAvailable,
1831+
sendDisabledReason,
1832+
attachmentBlockReason,
1833+
environmentUnavailable: environmentUnavailable !== null,
1834+
});
1835+
// The pending Submit button follows the answer's own blockers, matching submitComposer.
1836+
const primaryActionSendDisabledReason =
1837+
(activePendingProgress ? attachmentBlockReason : sendDisabledReason) ??
1838+
(speechInput.preparing ? "Preparing voice input" : null);
1839+
const primaryActionEnvironmentUnavailable =
1840+
environmentUnavailable !== null ||
1841+
(!activePendingProgress && (noProviderAvailable || projectSelectionRequired));
18281842
const dictationShortcutLabel = useDictationShortcut({
18291843
keybindings,
18301844
speech: speechInput,
@@ -2070,13 +2084,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
20702084

20712085
const shouldBlurMobileComposerOnSubmit = () => {
20722086
if (!isSoftwareKeyboardOpen) return false;
2073-
if (
2074-
isSendBusy ||
2075-
isSendDisabled ||
2076-
noProviderAvailable ||
2077-
environmentUnavailable !== null ||
2078-
phase === "running"
2079-
) {
2087+
if (isSendBusy || submissionBlocked || environmentUnavailable !== null || phase === "running") {
20802088
return false;
20812089
}
20822090
if (activePendingProgress) {
@@ -2098,11 +2106,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
20982106
submitAfterDictation(() => submitComposerRef.current(dispatchMode, submissionIntent));
20992107
return false;
21002108
}
2101-
if (
2102-
noProviderAvailable ||
2103-
isSendDisabled ||
2104-
!readEnvironmentScope(environmentId, AuthOrchestrationOperateScope)
2105-
) {
2109+
if (submissionBlocked || !readEnvironmentScope(environmentId, AuthOrchestrationOperateScope)) {
21062110
event?.preventDefault();
21072111
return false;
21082112
}
@@ -2129,7 +2133,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
21292133
}
21302134
const submission = submitComposerDraft({
21312135
prompt: promptRef.current,
2132-
submissionTarget: activePendingProgress ? "pending-user-input" : "provider-turn",
2136+
submissionTarget,
21332137
event,
21342138
onSend: (sendEvent) => {
21352139
providerInputRejectedRef.current = false;
@@ -3518,12 +3522,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
35183522
isRunning={false}
35193523
canInterrupt={false}
35203524
isSendBusy={isSendBusy}
3521-
sendDisabledReason={voiceSendDisabledReason}
3522-
isEnvironmentUnavailable={
3523-
environmentUnavailable !== null ||
3524-
noProviderAvailable ||
3525-
projectSelectionRequired
3526-
}
3525+
sendDisabledReason={primaryActionSendDisabledReason}
3526+
isEnvironmentUnavailable={primaryActionEnvironmentUnavailable}
35273527
isPreparingWorktree={false}
35283528
hasSendableContent={false}
35293529
preserveComposerFocusOnPointerDown
@@ -3602,12 +3602,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
36023602
)}
36033603
voiceInputActive={voiceInputActive}
36043604
isSendBusy={isSendBusy}
3605-
sendDisabledReason={voiceSendDisabledReason}
3606-
isEnvironmentUnavailable={
3607-
environmentUnavailable !== null ||
3608-
noProviderAvailable ||
3609-
projectSelectionRequired
3610-
}
3605+
sendDisabledReason={primaryActionSendDisabledReason}
3606+
isEnvironmentUnavailable={primaryActionEnvironmentUnavailable}
36113607
isPreparingWorktree={isPreparingWorktree}
36123608
hasSendableContent={composerSendState.hasSendableContent || voiceInputActive}
36133609
canResume={showResumeAction}

‎apps/web/src/components/chat/composerSubmission.test.ts‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from "@t3tools/shared/assistantCitations";
1212
import { describe, expect, it, vi } from "vite-plus/test";
1313

14-
import { submitComposerDraft } from "./composerSubmission";
14+
import { isComposerSubmissionBlocked, submitComposerDraft } from "./composerSubmission";
1515

1616
const assistantCitation = {
1717
version: 1 as const,
@@ -208,3 +208,30 @@ describe("submitComposerDraft", () => {
208208
expect(onSend).toHaveBeenCalledOnce();
209209
});
210210
});
211+
212+
describe("isComposerSubmissionBlocked", () => {
213+
const sendBlocked = {
214+
noProviderAvailable: true,
215+
sendDisabledReason: "Messages loading",
216+
attachmentBlockReason: null,
217+
environmentUnavailable: false,
218+
};
219+
220+
// regression: #9318
221+
it("lets a pending answer through while provider-turn sends are blocked", () => {
222+
expect(
223+
isComposerSubmissionBlocked({ ...sendBlocked, submissionTarget: "pending-user-input" }),
224+
).toBe(false);
225+
expect(isComposerSubmissionBlocked({ ...sendBlocked, submissionTarget: "provider-turn" })).toBe(
226+
true,
227+
);
228+
});
229+
230+
it("still blocks a pending answer on its attachments or a lost connection", () => {
231+
const answer = { ...sendBlocked, submissionTarget: "pending-user-input" as const };
232+
expect(
233+
isComposerSubmissionBlocked({ ...answer, attachmentBlockReason: "Attach the file again" }),
234+
).toBe(true);
235+
expect(isComposerSubmissionBlocked({ ...answer, environmentUnavailable: true })).toBe(true);
236+
});
237+
});

‎apps/web/src/components/chat/composerSubmission.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ export function getComposerSubmissionValidationMessage(
3030
: null;
3131
}
3232

33+
// Answering a question responds to the open request instead of starting a provider turn, so
34+
// provider and turn-send state must not block it. Its own attachments and connection still do.
35+
export function isComposerSubmissionBlocked(input: {
36+
submissionTarget: ComposerSubmissionInput["submissionTarget"];
37+
noProviderAvailable: boolean;
38+
sendDisabledReason: string | null;
39+
attachmentBlockReason: string | null;
40+
environmentUnavailable: boolean;
41+
}): boolean {
42+
return input.submissionTarget === "pending-user-input"
43+
? input.attachmentBlockReason !== null || input.environmentUnavailable
44+
: input.noProviderAvailable || input.sendDisabledReason !== null;
45+
}
46+
3347
export function submitComposerDraft(
3448
options: ComposerSubmissionInput & {
3549
event: ComposerSubmitEvent | undefined;

‎apps/web/src/components/chat/useComposerSend.ts‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,25 @@ export function useComposerSend(input: ComposerSendInput) {
390390
return;
391391
}
392392

393+
const sendCtx = composerRef.current?.getSendContext();
394+
// `/side` beats an open question and a plan follow-up, which would send the text to main.
395+
const sideChatCommand =
396+
sendCtx && !directAnnotation && !queuedRunEdit.isEditing
397+
? parseSideChatCommand(promptAtSend)
398+
: null;
399+
const answeringQuestion =
400+
Boolean(activePendingProgress) && sendCtx?.answeringPendingUserInput !== false;
401+
const startsSideChat =
402+
onSideChat !== undefined && sideChatCommand !== null && sideChatDisabledReason === null;
403+
// An answer responds to the open request rather than starting a turn, so the new-message
404+
// guards below (loading, busy, provider) must not swallow it.
405+
if (answeringQuestion && !startsSideChat && !directAnnotation) {
406+
if (readEnvironmentScope(environmentId, AuthOrchestrationOperateScope) && activeThread) {
407+
onAdvanceActivePendingUserInput();
408+
}
409+
return;
410+
}
411+
393412
const notifyDirectAnnotationAttached = () => {
394413
if (!directAnnotation) return;
395414
toastManager.add(
@@ -442,14 +461,6 @@ export function useComposerSend(input: ComposerSendInput) {
442461
});
443462
return;
444463
}
445-
const sendCtx = composerRef.current?.getSendContext();
446-
// `/side` beats an open question and a plan follow-up, which would send the text to main.
447-
const sideChatCommand =
448-
sendCtx && !directAnnotation && !queuedRunEdit.isEditing
449-
? parseSideChatCommand(promptAtSend)
450-
: null;
451-
const answeringQuestion =
452-
Boolean(activePendingProgress) && sendCtx?.answeringPendingUserInput !== false;
453464
// Where side chats are unavailable, `/side` text can still be a literal answer.
454465
if (sideChatDisabledReason !== null && sideChatCommand && !answeringQuestion) {
455466
toastManager.add(

0 commit comments

Comments
 (0)