fix(webui): keep queued prompts scoped across session switches

This commit is contained in:
chengyongru authored and chengyongru committed 2026-09-08 15:16:54 +08:00
1 parent f47b8f2315
commit 2b6c91472b
2 files changed
+43 -5

No files matched your search

+10 -5
View File
@@ -963,7 +963,7 @@ export function ThreadComposer({
const secondEnterPromptIdRef = useRef<string | null>(null);
const draggedQueuedPromptIdRef = useRef<string | null>(null);
const previousPendingQueueKeyRef = useRef(pendingQueueKey);
const wasStreamingRef = useRef(isStreaming);
const previousQueueRunRef = useRef({ key: pendingQueueKey, isStreaming });
const skipNextQueuedFlushRef = useRef(false);
const skipQueuedPromptPersistRef = useRef(false);
const voiceShortcutDownRef = useRef(false);
@@ -1895,16 +1895,21 @@ export function ThreadComposer({
}, [onSend, queuedPrompts]);
useEffect(() => {
const wasStreaming = wasStreamingRef.current;
wasStreamingRef.current = isStreaming;
const previous = previousQueueRunRef.current;
previousQueueRunRef.current = { key: pendingQueueKey, isStreaming };
if (!isStreaming) secondEnterPromptIdRef.current = null;
if (!wasStreaming || isStreaming || queuedPrompts.length === 0) return;
// Switching to an idle session is not completion of the previous session's run.
if (previous.key !== pendingQueueKey) {
skipNextQueuedFlushRef.current = false;
return;
}
if (!previous.isStreaming || isStreaming || queuedPrompts.length === 0) return;
if (skipNextQueuedFlushRef.current) {
skipNextQueuedFlushRef.current = false;
return;
}
sendNextQueuedPrompt();
}, [sendNextQueuedPrompt, isStreaming, queuedPrompts.length]);
}, [sendNextQueuedPrompt, isStreaming, pendingQueueKey, queuedPrompts.length]);
const handleStop = useCallback(() => {
secondEnterPromptIdRef.current = null;
+33
View File
@@ -3053,6 +3053,39 @@ describe("ThreadComposer", () => {
});
});
it("keeps queued guidance in its session when switching from running to idle", () => {
const sendA = vi.fn();
const sendB = vi.fn();
const view = render(
<ThreadComposer onSend={sendA} isStreaming pendingQueueKey="chat-a" />,
);
fireEvent.change(screen.getByLabelText("Message input"), {
target: { value: "follow-up for A" },
});
fireEvent.keyDown(screen.getByLabelText("Message input"), { key: "Enter" });
expect(screen.getByText("follow-up for A")).toBeInTheDocument();
expect(sendA).not.toHaveBeenCalled();
view.rerender(
<ThreadComposer onSend={sendB} isStreaming={false} pendingQueueKey="chat-b" />,
);
expect(sendB).not.toHaveBeenCalled();
expect(screen.queryByText("follow-up for A")).not.toBeInTheDocument();
view.rerender(
<ThreadComposer onSend={sendA} isStreaming pendingQueueKey="chat-a" />,
);
expect(screen.getByText("follow-up for A")).toBeInTheDocument();
expect(sendA).not.toHaveBeenCalled();
view.rerender(
<ThreadComposer onSend={sendA} isStreaming={false} pendingQueueKey="chat-a" />,
);
expect(sendA).toHaveBeenCalledTimes(1);
expect(sendA).toHaveBeenCalledWith("follow-up for A");
expect(sendB).not.toHaveBeenCalled();
expect(screen.queryByText("follow-up for A")).not.toBeInTheDocument();
});
it("persists queued guidance per chat across remounts", async () => {
const onSend = vi.fn();
const { rerender, unmount } = render(