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): ignore corrupt workbench cache
joshistoastb967f0394cbb
diff --git a/invokeai/frontend/webv2/src/workbench/persistence.test.ts b/invokeai/frontend/webv2/src/workbench/persistence.test.tsindex 0212822604..0104dde7a0 100644--- a/invokeai/frontend/webv2/src/workbench/persistence.test.ts+++ b/invokeai/frontend/webv2/src/workbench/persistence.test.ts@@ -1,8 +1,26 @@-import { describe, expect, it } from 'vitest';+import { beforeEach, describe, expect, it, vi } from 'vitest';-import { migrateWorkbenchPersistenceSnapshot } from './persistence';+import { localStorageWorkbenchPersistence, migrateWorkbenchPersistenceSnapshot } from './persistence';import { createInitialWorkbenchState } from './workbenchState';+const storage = new Map<string, string>();++vi.stubGlobal('window', {+ localStorage: {+ getItem: (key: string): string | null => storage.get(key) ?? null,+ removeItem: (key: string): void => {+ storage.delete(key);+ },+ setItem: (key: string, value: string): void => {+ storage.set(key, value);+ },+ },+});++beforeEach(() => {+ storage.clear();+});+describe('workbench persistence migration', () => {it('accepts current versioned workbench snapshots', () => {const state = createInitialWorkbenchState();@@ -27,4 +45,11 @@ describe('workbench persistence migration', () => {expect(migrateWorkbenchPersistenceSnapshot({ state: createInitialWorkbenchState(), version: 999 })).toBeNull();expect(migrateWorkbenchPersistenceSnapshot({ state: { projects: [] }, version: 1 })).toBeNull();});++ it('drops corrupt localStorage snapshots instead of throwing', async () => {+ storage.set('invokeai:v7:webv2:workbench', '{not json');++ await expect(localStorageWorkbenchPersistence.loadWorkbench()).resolves.toBeNull();+ expect(storage.has('invokeai:v7:webv2:workbench')).toBe(false);+ });});diff --git a/invokeai/frontend/webv2/src/workbench/persistence.ts b/invokeai/frontend/webv2/src/workbench/persistence.tsindex f9ee1d02fd..0ab6059caa 100644--- a/invokeai/frontend/webv2/src/workbench/persistence.ts+++ b/invokeai/frontend/webv2/src/workbench/persistence.ts@@ -75,7 +75,13 @@ export const localStorageWorkbenchPersistence: WorkbenchPersistenceService = {return Promise.resolve(null);}- return Promise.resolve(migrateWorkbenchPersistenceSnapshot(JSON.parse(value)));+ try {+ return Promise.resolve(migrateWorkbenchPersistenceSnapshot(JSON.parse(value)));+ } catch {+ window.localStorage.removeItem(getStorageKey());++ return Promise.resolve(null);+ }},saveWorkbench(state) {const snapshot = createSnapshot(state);diff --git a/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.test.ts b/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.test.tsindex addf90040f..b40110a8a1 100644--- a/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.test.ts+++ b/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.test.ts@@ -212,6 +212,15 @@ describe('loadWorkbench session hydration', () => {expect(snapshot?.state.projects).toHaveLength(2);});+ it('ignores a corrupt local cache and still hydrates from the backend', async () => {+ seedServerProject('Backend Project');+ storage.set('invokeai:v7:webv2:workbench', '{not json');++ const snapshot = await persistence.syncedWorkbenchPersistence.loadWorkbench();++ expect(snapshot?.state.projects.map((project) => project.name)).toEqual(['Backend Project']);+ });+it('boots a fresh draft when the session is empty', async () => {const existing = seedServerProject('Closed project');const account = createInitialWorkbenchState().account;diff --git a/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.ts b/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.tsindex 4af418e1af..3b8564f675 100644--- a/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.ts+++ b/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.ts@@ -476,7 +476,13 @@ export const syncedWorkbenchPersistence = {* no backend); the caller then keeps its default boot state.*/async loadWorkbench(options?: WorkbenchLoadOptions): Promise<WorkbenchPersistenceSnapshot | null> {- const local = await localStorageWorkbenchPersistence.loadWorkbench();+ let local: WorkbenchPersistenceSnapshot | null = null;++ try {+ local = await localStorageWorkbenchPersistence.loadWorkbench();+ } catch {+ local = null;+ }try {return await loadFromBackend(local, options);