π OpenHands: AI-Driven Development
fix(frontend): show progress while onboarding starts a chat (#17212)
Graham Neubigbd166e6df173
diff --git a/__tests__/components/onboarding/say-hello-step.test.tsx b/__tests__/components/onboarding/say-hello-step.test.tsxnew file mode 100644index 0000000000..f818f29e16--- /dev/null+++ b/__tests__/components/onboarding/say-hello-step.test.tsx@@ -0,0 +1,83 @@+import { screen } from "@testing-library/react";+import userEvent from "@testing-library/user-event";+import { beforeEach, describe, expect, it, vi } from "vitest";+import { SayHelloStep } from "#/components/features/onboarding/steps/say-hello-step";+import { renderWithProviders } from "../../../test-utils";++const createConversation = vi.hoisted(() => vi.fn());++vi.mock("#/contexts/active-backend-context", () => ({+ useActiveBackend: () => ({ backend: { kind: "cloud" } }),+}));++vi.mock("#/hooks/mutation/use-create-conversation", () => ({+ useCreateConversation: () => ({+ mutate: createConversation,+ isPending: false,+ isSuccess: false,+ }),+}));++vi.mock("#/hooks/use-is-creating-conversation", () => ({+ useIsCreatingConversation: () => false,+}));++describe("SayHelloStep", () => {+ beforeEach(() => {+ vi.clearAllMocks();+ });++ it("reports pending immediately, blocks duplicate sends, and navigates only on success", async () => {+ const navigate = vi.fn();+ const onLaunched = vi.fn();+ renderWithProviders(+ <SayHelloStep+ onBack={vi.fn()}+ onClose={vi.fn()}+ onLaunched={onLaunched}+ />,+ { navigation: { navigate } },+ );++ const send = screen.getByTestId("submit-button");+ await userEvent.click(send);++ expect(screen.getByRole("status")).toHaveTextContent(+ "ONBOARDING$HELLO_LAUNCHING",+ );+ expect(send).toBeDisabled();+ expect(+ screen.getByTestId("submit-button-pending-icon"),+ ).toBeInTheDocument();+ await userEvent.click(send);+ expect(createConversation).toHaveBeenCalledTimes(1);+ expect(navigate).not.toHaveBeenCalled();+ expect(onLaunched).not.toHaveBeenCalled();++ const callbacks = createConversation.mock.calls[0][1];+ callbacks.onSuccess({ conversation_id: "conversation-123" });++ expect(navigate).toHaveBeenCalledWith("/conversations/conversation-123");+ expect(onLaunched).toHaveBeenCalledTimes(1);+ });++ it("shows an actionable error and allows retry after create fails", async () => {+ renderWithProviders(+ <SayHelloStep onBack={vi.fn()} onClose={vi.fn()} onLaunched={vi.fn()} />,+ );++ await userEvent.click(screen.getByTestId("submit-button"));+ createConversation.mock.calls[0][1].onError(new Error("backend down"));++ const alert = await screen.findByRole("alert");+ expect(alert).toHaveTextContent("ERROR$GENERIC");+ expect(alert).toHaveTextContent("LAUNCH$TRY_AGAIN");+ expect(screen.getByTestId("submit-button")).toBeEnabled();++ await userEvent.click(+ screen.getByRole("button", { name: "LAUNCH$TRY_AGAIN" }),+ );+ expect(createConversation).toHaveBeenCalledTimes(2);+ expect(screen.queryByRole("alert")).not.toBeInTheDocument();+ });+});diff --git a/src/components/features/chat/chat-send-button.tsx b/src/components/features/chat/chat-send-button.tsxindex e76070db15..5aed2a662c 100644--- a/src/components/features/chat/chat-send-button.tsx+++ b/src/components/features/chat/chat-send-button.tsx@@ -1,16 +1,18 @@-import { ArrowUp } from "lucide-react";+import { ArrowUp, Loader2 } from "lucide-react";import { cn } from "#/utils/utils";export interface ChatSendButtonProps {buttonClassName: string;handleSubmit: () => void;disabled: boolean;+ isPending?: boolean;}export function ChatSendButton({buttonClassName,handleSubmit,disabled,+ isPending = false,}: ChatSendButtonProps) {return (<button@@ -26,11 +28,20 @@ export function ChatSendButton({data-testid="submit-button"onClick={handleSubmit}disabled={disabled}+ aria-busy={isPending}>- <ArrowUp- className="w-4 h-4"- color={disabled ? "var(--oh-muted)" : "white"}- />+ {isPending ? (+ <Loader2+ data-testid="submit-button-pending-icon"+ className="size-4 animate-spin text-[var(--oh-muted)]"+ aria-hidden+ />+ ) : (+ <ArrowUp+ className="w-4 h-4"+ color={disabled ? "var(--oh-muted)" : "white"}+ />+ )}</button>);}diff --git a/src/components/features/onboarding/steps/say-hello-step.tsx b/src/components/features/onboarding/steps/say-hello-step.tsxindex 765aa111ee..308adcadaa 100644--- a/src/components/features/onboarding/steps/say-hello-step.tsx+++ b/src/components/features/onboarding/steps/say-hello-step.tsx@@ -41,7 +41,12 @@ export function SayHelloStep({isSuccess,} = useCreateConversation();const isCreatingElsewhere = useIsCreatingConversation();- const isLaunching = isPending || isSuccess || isCreatingElsewhere;+ const [launchStatus, setLaunchStatus] = React.useState<+ "idle" | "pending" | "error"+ >("idle");+ const isPendingLaunch =+ launchStatus === "pending" || isPending || isCreatingElsewhere;+ const isLaunching = isPendingLaunch || isSuccess;const launchInFlightRef = React.useRef(false);const canSubmit =@@ -50,6 +55,7 @@ export function SayHelloStep({const launchConversation = () => {if (!canSubmit || launchInFlightRef.current) return;launchInFlightRef.current = true;+ setLaunchStatus("pending");// Explicitly omit `repository` and `workingDir` so the// conversation starts with no workspace, per the spec.@@ -62,6 +68,7 @@ export function SayHelloStep({},onError: () => {launchInFlightRef.current = false;+ setLaunchStatus("error");},},);@@ -118,10 +125,36 @@ export function SayHelloStep({buttonClassName=""handleSubmit={launchConversation}disabled={!canSubmit}+ isPending={isPendingLaunch}/></div></form>+ {isPendingLaunch ? (+ <p+ role="status"+ aria-live="polite"+ className="mt-3 text-sm text-[var(--oh-muted)]"+ >+ {t(I18nKey.ONBOARDING$HELLO_LAUNCHING)}+ </p>+ ) : null}+ {launchStatus === "error" ? (+ <div+ role="alert"+ className="mt-3 flex items-center gap-2 text-sm text-danger"+ >+ <span>{t(I18nKey.ERROR$GENERIC)}</span>+ <button+ type="button"+ className="underline underline-offset-2"+ onClick={launchConversation}+ >+ {t(I18nKey.LAUNCH$TRY_AGAIN)}+ </button>+ </div>+ ) : null}+{showRecommendedAutomations ? (<><div