diff --git a/apps/builder/app/builder/features/publish/publish-progress.render.test.tsx b/apps/builder/app/builder/features/publish/publish-progress.render.test.tsx index c3e4035b46..3519a96ca2 100644 --- a/apps/builder/app/builder/features/publish/publish-progress.render.test.tsx +++ b/apps/builder/app/builder/features/publish/publish-progress.render.test.tsx @@ -558,6 +558,40 @@ test("closing publish hides its countdown while polling continues to completion" expect(toast.success).toHaveBeenCalledOnce(); }); +test.each(["success", "failed"] as const)( + "a confirmed %s site publish clears controls despite a stale pending Build", + async (outcome) => { + publish = async () => { + project = makeProject("project", { + buildId: "accepted", + publishStatus: "PENDING", + }); + return accept(); + }; + job = async () => ({ status: outcome, code: "runner_failed" }); + await mount(); + await click("Publish"); + await waitFor(() => + expect(stores.$project.get()?.latestBuildVirtual?.buildId).toBe( + "accepted" + ) + ); + await waitFor(() => + expect(requests.some(({ route }) => route === "api.publish.getJob")).toBe( + true + ) + ); + await waitFor(() => expect(button("Publish")).toBeDefined()); + expect(button("Publish")?.dataset.state).not.toBe("pending"); + expect(button("Validate")?.disabled).toBe(false); + if (outcome === "success") { + await waitFor(() => expect(button("See logs")).toBeDefined()); + } else { + await waitFor(() => expect(button("See issues")).toBeDefined()); + } + } +); + test.each(["validation", "publish"] as const)( "%s diagnostics remain available after the popover reopens", async (action) => { diff --git a/apps/builder/app/builder/features/publish/publish-static.test.tsx b/apps/builder/app/builder/features/publish/publish-static.test.tsx index 1b3dd724fb..e3e8caaca9 100644 --- a/apps/builder/app/builder/features/publish/publish-static.test.tsx +++ b/apps/builder/app/builder/features/publish/publish-static.test.tsx @@ -21,6 +21,7 @@ const acceptedResponse = { let staticResponse: unknown = acceptedResponse; let projectStore: (typeof import("~/shared/sync/data-stores"))["$project"]; let getJobStatus: "pending" | "success" | "failed" = "pending"; +let buildStatus: "PENDING" | "PUBLISHED" = "PUBLISHED"; let publishRequests = 0; let jobRequests = 0; const downloads = vi.fn(); @@ -65,7 +66,7 @@ beforeAll(async () => { : { buildId: "static-1", updatedAt: new Date().toISOString(), - publishStatus: "PUBLISHED", + publishStatus: buildStatus, }, }, }), @@ -91,6 +92,7 @@ afterEach(async () => { projectStore.set(undefined); publishDialog.set("none"); getJobStatus = "pending"; + buildStatus = "PUBLISHED"; staticResponse = acceptedResponse; publishRequests = 0; jobRequests = 0; @@ -158,6 +160,7 @@ const render = async (open: boolean, projectId = "project-a") => { test("reopening an active static publish keeps one status owner and one download", async () => { vi.useFakeTimers(); + buildStatus = "PENDING"; projectStore.set(createProject()); await render(true); const button = staticButton(); @@ -183,6 +186,8 @@ test("reopening an active static publish keeps one status owner and one download }); expect(downloads).toHaveBeenCalledExactlyOnceWith("/cgi/static/ssg/site.zip"); expect(staticButton()?.dataset.state).not.toBe("pending"); + expect(staticButton()?.disabled).toBe(false); + expect(document.body.textContent).toContain("Downloaded"); expect(publishRequests).toBe(1); expect(jobRequests).toBe(2); }); @@ -213,17 +218,37 @@ test("project navigation suppresses an old static download and error toast", asy }); test("a failed static runner clears progress without starting a download", async () => { + vi.useFakeTimers(); const errorToast = vi.spyOn(toast, "error").mockImplementation(() => ""); - getJobStatus = "failed"; projectStore.set(createProject()); await render(true); const button = staticButton(); expect(button).toBeDefined(); await act(async () => button?.click()); await act(async () => vi.waitFor(() => expect(jobRequests).toBe(1))); + await act(async () => + vi.waitFor(() => + expect(projectStore.get()?.latestStaticBuild?.buildId).toBe("static-1") + ) + ); + act(() => + projectStore.set({ + ...projectStore.get()!, + latestStaticBuild: { + buildId: "static-1", + projectId: "project-a", + updatedAt: new Date().toISOString(), + publishStatus: "PENDING", + }, + }) + ); + getJobStatus = "failed"; + await act(async () => vi.advanceTimersByTimeAsync(15_100)); + expect(jobRequests).toBe(2); expect(downloads).not.toHaveBeenCalled(); expect(errorToast).toHaveBeenCalledOnce(); expect(staticButton()?.dataset.state).not.toBe("pending"); + expect(staticButton()?.disabled).toBe(false); await act(async () => document.body .querySelector( diff --git a/apps/builder/app/builder/features/publish/publish-ui.tsx b/apps/builder/app/builder/features/publish/publish-ui.tsx index 51fe0ce99c..4fd0553a64 100644 --- a/apps/builder/app/builder/features/publish/publish-ui.tsx +++ b/apps/builder/app/builder/features/publish/publish-ui.tsx @@ -434,8 +434,11 @@ const Publish = ({ const [hasCustomDomainsSelected, setHasCustomDomainsSelected] = useState(false); const previousDomainsKey = useRef(); + const latestSitePublish = publishes.find(({ target }) => target === "site"); const hasPendingState = project.latestBuildVirtual - ? getPublishStatusDisplay(project.latestBuildVirtual).status === "PENDING" + ? latestSitePublish?.buildId === project.latestBuildVirtual.buildId + ? latestSitePublish.status === "pending" + : getPublishStatusDisplay(project.latestBuildVirtual).status === "PENDING" : false; const isPublishInProgress = isPublishing || hasPendingState; @@ -504,7 +507,6 @@ const Publish = ({ const getForm = () => buttonRef.current?.closest("form"); const findings = flow.siteFindings; - const latestSitePublish = publishes.find(({ target }) => target === "site"); const hasSessionPublish = latestSitePublish !== undefined; return ( @@ -630,7 +632,12 @@ const PublishStatic = ({ ? "PUBLISHED" : status; - const isPublishInProgress = status === "PENDING" || isPublishing; + const isPublishInProgress = + isPublishing || + (latestPublish !== undefined && + latestPublish.buildId === project.latestStaticBuild?.buildId + ? latestPublish.status === "pending" + : status === "PENDING"); return ( diff --git a/apps/builder/app/builder/features/publish/publish.tsx b/apps/builder/app/builder/features/publish/publish.tsx index db857ca890..a6934f94b1 100644 --- a/apps/builder/app/builder/features/publish/publish.tsx +++ b/apps/builder/app/builder/features/publish/publish.tsx @@ -282,7 +282,8 @@ export const PublishButton = ({ projectId }: PublishProps) => { } } else { setPublishErrorState((current) => - current?.source === "status" || + (current?.source === "status" && + (status !== "PENDING" || current.buildId !== build.buildId)) || (isNewBuild && current?.source === "transport") ? undefined : current