Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
fix(webv2): show a new project's board in the gallery
Josh Corbettbaca9a06785d
diff --git a/invokeai/frontend/webv2/src/workbench/projects/api.test.ts b/invokeai/frontend/webv2/src/workbench/projects/api.test.tsindex d0a10df4ff..54b90a9248 100644--- a/invokeai/frontend/webv2/src/workbench/projects/api.test.ts+++ b/invokeai/frontend/webv2/src/workbench/projects/api.test.ts@@ -1,8 +1,10 @@import type * as transportModule from '@platform/transport/http';+import { galleryKeys } from '@features/gallery/queries';+import { queryClient } from '@platform/query/client';import { accountLifecycle, captureAccountScope } from '@platform/state/accountLifecycle';import { ApiError } from '@platform/transport/http';-import { beforeEach, describe, expect, it, vi } from 'vitest';+import { beforeEach, describe, expect, it, onTestFinished, vi } from 'vitest';const transport = vi.hoisted(() => ({apiFetch: vi.fn(),@@ -49,6 +51,19 @@ describe('createProjectSettled', () => {expect(transport.apiFetchJson).toHaveBeenCalledTimes(1);});+ it('marks board lists fetched before the create stale, since they predate its board', async () => {+ const owner = captureAccountScope();+ const boardsKey = [...galleryKeys.boardsForAccount(owner), {}];+ queryClient.setQueryData(boardsKey, []);+ transport.apiFetchJson.mockResolvedValueOnce({ board_id: 'board-for-project-1', project_id: 'project-1' });++ onTestFinished(() => queryClient.removeQueries({ queryKey: boardsKey }));++ await createProjectSettled(request, owner);++ await vi.waitFor(() => expect(queryClient.getQueryState(boardsKey)?.isInvalidated).toBe(true));+ });+/** Settle with a retry write: GET 404 can race the initial create transaction. */it('adopts the project when a retried create finds the first one committed', async () => {transport.apiFetchJsondiff --git a/invokeai/frontend/webv2/src/workbench/projects/api.ts b/invokeai/frontend/webv2/src/workbench/projects/api.tsindex b005c6dfa9..49480ea87e 100644--- a/invokeai/frontend/webv2/src/workbench/projects/api.ts+++ b/invokeai/frontend/webv2/src/workbench/projects/api.ts@@ -1,5 +1,6 @@import type { AccountScope } from '@platform/state/accountLifecycle';+import { queryClient } from '@platform/query/client';import { assertAccountScopeCurrent } from '@platform/state/accountLifecycle';import { ApiError, apiFetch, apiFetchJson, sleep } from '@platform/transport/http';import {@@ -308,10 +309,7 @@ export class ProjectCreateAbsentError extends Error {* commit. A 201 succeeds; after 409, GET distinguishes an existing project from a board conflict. Other* deterministic rejections prove absence. Transport failure remains unknown and must never authorize deletion.*/-export const createProjectSettled = async (- request: ProjectCreateRequest,- owner: AccountScope-): Promise<ProjectRecordDTO> => {+const settleProjectCreate = async (request: ProjectCreateRequest, owner: AccountScope): Promise<ProjectRecordDTO> => {const projectId = request.project_id;const body = serializeCreateProjectRequest(request);const writeBudget = createProjectWriteRetryBudget();@@ -370,6 +368,21 @@ export const createProjectSettled = async (}};+export const createProjectSettled = async (+ request: ProjectCreateRequest,+ owner: AccountScope+): Promise<ProjectRecordDTO> => {+ const record = await settleProjectCreate(request, owner);++ // The server mints the project's board with it, so board lists fetched before now are missing it. Loaded lazily+ // to keep the gallery data layer off the launchpad's startup graph.+ void import('@features/gallery/queries').then(({ galleryKeys }) =>+ queryClient.invalidateQueries({ queryKey: galleryKeys.boardsForAccount(owner) })+ );++ return record;+};+/** A response arrived and refused the create outright, so nothing was written. */const isRefusal = (error: unknown): boolean => error instanceof ApiError && error.status >= 400 && error.status < 500;