Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(frontend/onboarding): silence AbortError in onboarding provider (#14388)

seer-by-sentry[bot]70abf9fe36ac
diff --git a/autogpt_platform/frontend/src/providers/onboarding/__tests__/onboarding-provider-routing.test.tsx b/autogpt_platform/frontend/src/providers/onboarding/__tests__/onboarding-provider-routing.test.tsx
index 6d8dbe73ae..6c5bdceca1 100644
--- a/autogpt_platform/frontend/src/providers/onboarding/__tests__/onboarding-provider-routing.test.tsx
+++ b/autogpt_platform/frontend/src/providers/onboarding/__tests__/onboarding-provider-routing.test.tsx
@@ -1,8 +1,14 @@
-import { beforeEach, describe, expect, test, vi } from "vitest";
-import { render, waitFor } from "@testing-library/react";
+import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
+import { act, render, waitFor } from "@testing-library/react";
import OnboardingProvider from "../onboarding-provider";
const routerReplace = vi.fn();
+const toast = vi.hoisted(() => vi.fn());
+let completionError: Error | null = null;
+
+vi.mock("@/components/molecules/Toast/use-toast", () => ({
+ useToast: () => ({ toast }),
+}));
let mockPathname = "/signup";
let mockSearchParams = new URLSearchParams();
@@ -41,6 +47,11 @@ const completedCallCount = { value: 0 };
vi.mock("@/app/api/__generated__/endpoints/onboarding/onboarding", () => ({
getV1CheckIfOnboardingIsCompleted: () => {
completedCallCount.value += 1;
+ if (completionError) {
+ const error = completionError;
+ completionError = null;
+ return Promise.reject(error);
+ }
return Promise.resolve({
status: 200,
data: { is_completed: mockIsCompleted },
@@ -53,8 +64,12 @@ vi.mock("@/app/api/__generated__/endpoints/onboarding/onboarding", () => ({
}));
describe("OnboardingProvider routing — logged-in user", () => {
+ afterEach(() => vi.restoreAllMocks());
+
beforeEach(() => {
routerReplace.mockClear();
+ toast.mockClear();
+ completionError = null;
mockSearchParams = new URLSearchParams();
mockPathname = "/signup";
mockIsLoggedIn = true;
@@ -62,6 +77,59 @@ describe("OnboardingProvider routing — logged-in user", () => {
completedCallCount.value = 0;
});
+ test("silences cancellation and retries initialization after navigation", async () => {
+ mockPathname = "/onboarding";
+ completionError = new DOMException("Navigation cancelled", "AbortError");
+ const consoleError = vi
+ .spyOn(console, "error")
+ .mockImplementation(() => {});
+ const { rerender } = render(
+ <OnboardingProvider>
+ <div />
+ </OnboardingProvider>,
+ );
+ await act(async () => {});
+
+ expect(completedCallCount.value).toBe(1);
+ expect(toast).not.toHaveBeenCalled();
+ expect(consoleError).not.toHaveBeenCalled();
+
+ mockPathname = "/marketplace";
+ rerender(
+ <OnboardingProvider>
+ <div />
+ </OnboardingProvider>,
+ );
+ await waitFor(() => expect(completedCallCount.value).toBe(2));
+ expect(routerReplace).toHaveBeenCalledWith("/onboarding");
+ consoleError.mockRestore();
+ });
+
+ test("still reports a genuine initialization failure", async () => {
+ mockPathname = "/onboarding";
+ const error = new Error("Connection failed");
+ completionError = error;
+ const consoleError = vi
+ .spyOn(console, "error")
+ .mockImplementation(() => {});
+ render(
+ <OnboardingProvider>
+ <div />
+ </OnboardingProvider>,
+ );
+ await waitFor(() =>
+ expect(toast).toHaveBeenCalledWith({
+ title: "Failed to initialize onboarding",
+ variant: "destructive",
+ }),
+ );
+ expect(consoleError).toHaveBeenCalledWith(
+ "Failed to initialize onboarding:",
+ error,
+ );
+ consoleError.mockRestore();
+ });
+
test("incomplete user on /signup is redirected to /onboarding", async () => {
mockPathname = "/signup";
mockIsCompleted = false;
diff --git a/autogpt_platform/frontend/src/providers/onboarding/onboarding-provider.tsx b/autogpt_platform/frontend/src/providers/onboarding/onboarding-provider.tsx
index bf84ddff24..faf1b9600e 100644
--- a/autogpt_platform/frontend/src/providers/onboarding/onboarding-provider.tsx
+++ b/autogpt_platform/frontend/src/providers/onboarding/onboarding-provider.tsx
@@ -211,6 +211,11 @@ export default function OnboardingProvider({
return;
}
+ if (error instanceof DOMException && error.name === "AbortError") {
+ hasInitialized.current = false;
+ return;
+ }
+
console.error("Failed to initialize onboarding:", error);
toast({