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(workbench): dedupe initial project sync
joshistoast9e17be7db7c6
diff --git a/invokeai/frontend/webv2/scripts/mock-backend.mjs b/invokeai/frontend/webv2/scripts/mock-backend.mjsindex 3114bde4df..895848e1a8 100644--- a/invokeai/frontend/webv2/scripts/mock-backend.mjs+++ b/invokeai/frontend/webv2/scripts/mock-backend.mjs@@ -59,6 +59,9 @@ export const startMockBackend = async (port) => {}if (method === 'POST') {const requested = JSON.parse((await readBody(request)) || '{}');+ if (requested.project_id && state.projects.has(requested.project_id)) {+ return json(409, { detail: 'Project already exists' });+ }const now = timestamp();const project = {created_at: now,diff --git a/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.test.ts b/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.test.tsindex 9a99623380..0502af2818 100644--- a/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.test.ts+++ b/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.test.ts@@ -193,6 +193,21 @@ describe('loadWorkbench session hydration', () => {expect(second.hasPendingChanges()).toBe(false);});+ it('shares one backend import across StrictMode-style load replays', async () => {+ const state = createInitialWorkbenchState();+ storage.set(+ 'invokeai:v7:webv2:workbench',+ JSON.stringify({ savedAt: '2026-07-19T00:00:00.000Z', state, version: 1 })+ );++ const [first, replay] = await Promise.all([service.loadWorkbench(), service.loadWorkbench()]);++ expect(replay).toBe(first);+ expect(api.listProjects).toHaveBeenCalledTimes(1);+ expect(api.createProject).toHaveBeenCalledTimes(state.projects.length);+ expect(api.getProject).not.toHaveBeenCalled();+ });+it('hydrates only the open set and seeds the full library', async () => {const first = seedServerProject('First');const second = seedServerProject('Second');diff --git a/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.ts b/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.tsindex fe91d93816..3e93b2183f 100644--- a/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.ts+++ b/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.ts@@ -621,6 +621,7 @@ export const clearAllWorkbenchData = async (): Promise<void> => {/** Construct one synchronization lifetime per mounted Workbench. */export const createSyncedWorkbenchPersistence = (): SyncedWorkbenchPersistence => {const syncState = createSyncedPersistenceState();+ let loadPromise: Promise<HydratedWorkbenchSnapshot | null> | null = null;const adoptProjectRecord = (record: ProjectRecordDTO): Project | null => {const project = deserializeProjectDocument(record.data);@@ -670,42 +671,53 @@ export const createSyncedWorkbenchPersistence = (): SyncedWorkbenchPersistence =* unreachable. Returns null when there is nothing anywhere (first run with* no backend); the caller then keeps its default boot state.*/- async loadWorkbench(options?: WorkbenchLoadOptions): Promise<HydratedWorkbenchSnapshot | null> {- let local: HydratedWorkbenchSnapshot | null = null;-- try {- local = await localStorageWorkbenchPersistence.loadWorkbench();- } catch {- local = null;+ loadWorkbench(options?: WorkbenchLoadOptions): Promise<HydratedWorkbenchSnapshot | null> {+ // React StrictMode replays the Workbench mount effect. The synchronization+ // lifetime is stable across that replay, so both calls must observe the+ // same import instead of racing duplicate project POSTs.+ if (loadPromise) {+ return loadPromise;}- try {- return await loadFromBackend(syncState, local, options);- } catch {- // Backend unreachable: run from the cache; saves queue up locally and- // replay on reconnect.- syncState.hasPending = true;+ loadPromise = (async () => {+ let local: HydratedWorkbenchSnapshot | null = null;- const persistedRevisions = loadPersistedRevisions();-- for (const [projectId, revision] of Object.entries(persistedRevisions)) {- syncState.syncEntries.set(projectId, { pushedDoc: null, revision });+ try {+ local = await localStorageWorkbenchPersistence.loadWorkbench();+ } catch {+ local = null;}- reportProjectSync({- hasPendingChanges: true,- projects: Object.fromEntries(- (local?.state.projects ?? []).map((project) => [- project.id,- { isPendingPush: true, revision: persistedRevisions[project.id] ?? null },- ])- ),- });+ try {+ return await loadFromBackend(syncState, local, options);+ } catch {+ // Backend unreachable: run from the cache; saves queue up locally and+ // replay on reconnect.+ syncState.hasPending = true;- // A cache holding an empty session (last tab closed offline) cannot- // hydrate the editor; boot a fresh draft instead.- return local && local.state.projects.length > 0 ? local : null;- }+ const persistedRevisions = loadPersistedRevisions();++ for (const [projectId, revision] of Object.entries(persistedRevisions)) {+ syncState.syncEntries.set(projectId, { pushedDoc: null, revision });+ }++ reportProjectSync({+ hasPendingChanges: true,+ projects: Object.fromEntries(+ (local?.state.projects ?? []).map((project) => [+ project.id,+ { isPendingPush: true, revision: persistedRevisions[project.id] ?? null },+ ])+ ),+ });++ // A cache holding an empty session (last tab closed offline) cannot+ // hydrate the editor; boot a fresh draft instead.+ return local && local.state.projects.length > 0 ? local : null;+ }+ })();++ return loadPromise;},/**