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/marketplace): unstick publish submit after adding image and cut success-screen lag (#13578)

Abhimanyu Yadavb6dbec6490d6
diff --git a/autogpt_platform/frontend/src/components/contextual/PublishAgentModal/components/AgentInfoStep/__tests__/useAgentInfoStep.test.ts b/autogpt_platform/frontend/src/components/contextual/PublishAgentModal/components/AgentInfoStep/__tests__/useAgentInfoStep.test.ts
new file mode 100644
index 0000000000..5b1effd8ce
--- /dev/null
+++ b/autogpt_platform/frontend/src/components/contextual/PublishAgentModal/components/AgentInfoStep/__tests__/useAgentInfoStep.test.ts
@@ -0,0 +1,67 @@
+import { describe, expect, it, vi } from "vitest";
+import { act, renderHook } from "@testing-library/react";
+
+vi.mock("@sentry/nextjs", () => ({
+ captureException: vi.fn(),
+}));
+
+import { useAgentInfoStep } from "../useAgentInfoStep";
+
+describe("useAgentInfoStep", () => {
+ const baseArgs = {
+ onBack: vi.fn(),
+ onSuccess: vi.fn(),
+ selectedAgentId: "graph-1",
+ selectedAgentVersion: 1,
+ };
+
+ // react-hook-form's formState is a subscription proxy: errors only update
+ // when read during render, so expose them from the render callback.
+ function renderInfoStepHook() {
+ return renderHook(() => {
+ const step = useAgentInfoStep(baseArgs);
+ return { step, rootError: step.form.formState.errors.root };
+ });
+ }
+
+ it("clears the image-required error once an image is added so submit re-enables", () => {
+ const { result } = renderInfoStepHook();
+
+ // Simulate submitting without a thumbnail: the form marks the root error.
+ act(() => {
+ result.current.step.form.setError("root", {
+ type: "manual",
+ message: "At least one image is required",
+ });
+ });
+ expect(result.current.rootError).toBeDefined();
+
+ // Adding an image must clear the stale error, otherwise the submit button
+ // stays disabled forever and the user is stuck.
+ act(() => {
+ result.current.step.handleImagesChange(["https://example.com/thumb.png"]);
+ });
+
+ expect(result.current.rootError).toBeUndefined();
+ expect(result.current.step.images).toEqual([
+ "https://example.com/thumb.png",
+ ]);
+ });
+
+ it("keeps the error while there are still no images", () => {
+ const { result } = renderInfoStepHook();
+
+ act(() => {
+ result.current.step.form.setError("root", {
+ type: "manual",
+ message: "At least one image is required",
+ });
+ });
+
+ act(() => {
+ result.current.step.handleImagesChange([]);
+ });
+
+ expect(result.current.rootError).toBeDefined();
+ });
+});
diff --git a/autogpt_platform/frontend/src/components/contextual/PublishAgentModal/components/AgentInfoStep/useAgentInfoStep.ts b/autogpt_platform/frontend/src/components/contextual/PublishAgentModal/components/AgentInfoStep/useAgentInfoStep.ts
index ed886b1f67..1ee6e45ea5 100644
--- a/autogpt_platform/frontend/src/components/contextual/PublishAgentModal/components/AgentInfoStep/useAgentInfoStep.ts
+++ b/autogpt_platform/frontend/src/components/contextual/PublishAgentModal/components/AgentInfoStep/useAgentInfoStep.ts
@@ -85,9 +85,15 @@ export function useAgentInfoStep({
}
}, [selectedAgentId, agentId]);
- const handleImagesChange = useCallback((newImages: string[]) => {
- setImages(newImages);
- }, []);
+ const handleImagesChange = useCallback(
+ (newImages: string[]) => {
+ setImages(newImages);
+ if (newImages.length > 0) {
+ form.clearErrors("root");
+ }
+ },
+ [form],
+ );
async function handleFormSubmit(data: PublishAgentFormData) {
// Validate that at least one image is present
diff --git a/autogpt_platform/frontend/src/components/contextual/PublishAgentModal/components/ReviewHero.tsx b/autogpt_platform/frontend/src/components/contextual/PublishAgentModal/components/ReviewHero.tsx
index 9a51189072..21fa5eb4f1 100644
--- a/autogpt_platform/frontend/src/components/contextual/PublishAgentModal/components/ReviewHero.tsx
+++ b/autogpt_platform/frontend/src/components/contextual/PublishAgentModal/components/ReviewHero.tsx
@@ -35,9 +35,10 @@ export function ReviewHero({
{showConfetti && !shouldReduceMotion ? (
<Confetti
options={{
- particleCount: 80,
+ particleCount: 50,
spread: 70,
startVelocity: 35,
+ ticks: 120,
origin: { y: 0.3 },
}}
/>
@@ -53,7 +54,7 @@ export function ReviewHero({
transition={{
duration: 1.6,
ease: "easeOut",
- repeat: Infinity,
+ repeat: 3,
repeatDelay: 0.4,
}}
className={cn(
@@ -68,7 +69,7 @@ export function ReviewHero({
transition={{
duration: 1.6,
ease: "easeOut",
- repeat: Infinity,
+ repeat: 3,
repeatDelay: 0.4,
delay: 0.5,
}}
diff --git a/autogpt_platform/frontend/src/components/molecules/Confetti/Confetti.tsx b/autogpt_platform/frontend/src/components/molecules/Confetti/Confetti.tsx
index 14dea25d02..4511f0507f 100644
--- a/autogpt_platform/frontend/src/components/molecules/Confetti/Confetti.tsx
+++ b/autogpt_platform/frontend/src/components/molecules/Confetti/Confetti.tsx
@@ -58,29 +58,6 @@ const ConfettiComponent = forwardRef<ConfettiRef, Props>(
const canvasElRef = useRef<HTMLCanvasElement | null>(null);
const instanceRef = useRef<ConfettiInstance | null>(null);
- const hasAutoStartedRef = useRef(false);
-
- // Create the confetti instance once after mount via useEffect,
- // so React never re-fires a callback ref on re-renders.
- useEffect(() => {
- const node = canvasElRef.current;
- if (!node || instanceRef.current) return;
-
- const dpr = window.devicePixelRatio || 1;
- node.width = node.offsetWidth * dpr;
- node.height = node.offsetHeight * dpr;
-
- instanceRef.current = confetti.create(node, {
- resize: true,
- useWorker: false,
- ...globalOptions,
- });
-
- return () => {
- instanceRef.current?.reset();
- instanceRef.current = null;
- };
- }, []); // eslint-disable-line react-hooks/exhaustive-deps
const fire = useMemo(
() =>
@@ -102,11 +79,49 @@ const ConfettiComponent = forwardRef<ConfettiRef, Props>(
useImperativeHandle(ref, () => api, [api]);
+ // Mirror the latest props into refs so the mount-only effect below can read
+ // current values without listing them as dependencies. `fire`'s identity
+ // changes whenever `options` changes (a new object literal every render at
+ // most call sites), so depending on it would tear down and re-fire the
+ // instance on every re-render.
+ const manualstartRef = useRef(manualstart);
+ manualstartRef.current = manualstart;
+ const globalOptionsRef = useRef(globalOptions);
+ globalOptionsRef.current = globalOptions;
+ const fireRef = useRef(fire);
+ fireRef.current = fire;
+
+ // Create the confetti instance once after mount via useEffect,
+ // so React never re-fires a callback ref on re-renders. Auto-fire is
+ // tied to instance creation so StrictMode's remount (which resets the
+ // instance) still produces a visible burst.
useEffect(() => {
- if (manualstart || hasAutoStartedRef.current) return;
- hasAutoStartedRef.current = true;
- void fire();
- }, [manualstart, fire]);
+ const node = canvasElRef.current;
+ if (!node || instanceRef.current) return;
+
+ // Cap DPR: full-resolution canvases on 2-3x displays multiply the
+ // pixels the main thread has to paint each frame for little visual gain.
+ // `resize: false` keeps this capped sizing — canvas-confetti's own resize
+ // handling ignores devicePixelRatio and would drop the cap on any resize.
+ const dpr = Math.min(window.devicePixelRatio || 1, 1.5);
+ node.width = node.offsetWidth * dpr;
+ node.height = node.offsetHeight * dpr;
+
+ instanceRef.current = confetti.create(node, {
+ resize: false,
+ useWorker: false,
+ ...globalOptionsRef.current,
+ });
+
+ if (!manualstartRef.current) {
+ void fireRef.current();
+ }
+
+ return () => {
+ instanceRef.current?.reset();
+ instanceRef.current = null;
+ };
+ }, []);
return (
<ConfettiContext.Provider value={api}>
diff --git a/autogpt_platform/frontend/src/components/molecules/Confetti/__tests__/Confetti.test.tsx b/autogpt_platform/frontend/src/components/molecules/Confetti/__tests__/Confetti.test.tsx
new file mode 100644
index 0000000000..9b4fac8fe8
--- /dev/null
+++ b/autogpt_platform/frontend/src/components/molecules/Confetti/__tests__/Confetti.test.tsx
@@ -0,0 +1,78 @@
+import { createRef } from "react";
+import { render } from "@testing-library/react";
+import { beforeEach, describe, expect, it, vi } from "vitest";
+
+import { Confetti, type ConfettiRef } from "../Confetti";
+
+const fireInstance = vi.fn().mockResolvedValue(undefined);
+const resetInstance = vi.fn();
+const createInstance = vi.fn();
+
+vi.mock("canvas-confetti", () => ({
+ default: {
+ create: (...args: unknown[]) => {
+ createInstance(...args);
+ return Object.assign(fireInstance, { reset: resetInstance });
+ },
+ },
+}));
+
+describe("Confetti", () => {
+ beforeEach(() => {
+ fireInstance.mockClear();
+ resetInstance.mockClear();
+ createInstance.mockClear();
+ });
+
+ it("creates an instance and auto-fires once on mount", () => {
+ render(<Confetti />);
+
+ expect(createInstance).toHaveBeenCalledTimes(1);
+ expect(fireInstance).toHaveBeenCalledTimes(1);
+ });
+
+ it("caps the device pixel ratio when sizing the canvas", () => {
+ const original = window.devicePixelRatio;
+ Object.defineProperty(window, "devicePixelRatio", {
+ value: 3,
+ configurable: true,
+ });
+
+ render(<Confetti data-testid="confetti-canvas" />);
+
+ // With offsetWidth/Height of 0 in happy-dom the size stays 0, but the
+ // create call still happens with the capped DPR path exercised.
+ expect(createInstance).toHaveBeenCalledTimes(1);
+
+ Object.defineProperty(window, "devicePixelRatio", {
+ value: original,
+ configurable: true,
+ });
+ });
+
+ it("does not auto-fire when manualstart is set", () => {
+ render(<Confetti manualstart />);
+
+ expect(createInstance).toHaveBeenCalledTimes(1);
+ expect(fireInstance).not.toHaveBeenCalled();
+ });
+
+ it("fires via the imperative ref handle", async () => {
+ const ref = createRef<ConfettiRef>();
+ render(<Confetti manualstart ref={ref} />);
+
+ expect(fireInstance).not.toHaveBeenCalled();
+
+ await ref.current?.fire();
+
+ expect(fireInstance).toHaveBeenCalledTimes(1);
+ });
+
+ it("resets the instance on unmount", () => {
+ const { unmount } = render(<Confetti manualstart />);
+
+ unmount();
+
+ expect(resetInstance).toHaveBeenCalledTimes(1);
+ });
+});