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): stop a transferred document resolving to its source
Josh Corbett5cc3e85b1f0e
diff --git a/invokeai/frontend/webv2/src/workbench/projects/projectAssets.test.ts b/invokeai/frontend/webv2/src/workbench/projects/projectAssets.test.tsindex c12450adae..a0b51afe33 100644--- a/invokeai/frontend/webv2/src/workbench/projects/projectAssets.test.ts+++ b/invokeai/frontend/webv2/src/workbench/projects/projectAssets.test.ts@@ -275,6 +275,56 @@ describe('stripInstallationState', () => {expect(JSON.stringify(stripped)).toContain('galleryView');});+ /**+ * A URL is built around a media name and a server. The name is remapped by a transfer; the URL is+ * not — so a cached one keeps resolving, to the *source* project's picture, on a document that no+ * longer references that media at all.+ */+ it('blanks the cached media URLs rather than dropping them', () => {+ const stripped = stripInstallationState({+ widgetInstances: {+ 'gallery-1': {+ state: {+ values: {+ recentImages: [+ {+ height: 1,+ imageName: 'recent.png',+ imageUrl: 'http://source-install/api/v1/images/i/recent.png/full',+ queuedAt: '2026-08-07T00:00:00.000Z',+ sourceQueueItemId: 'q1',+ thumbnailUrl: 'http://source-install/api/v1/images/i/recent.png/thumbnail',+ width: 1,+ },+ ],+ },+ },+ typeId: 'gallery',+ },+ },+ });++ const [recent] = (+ (stripped.widgetInstances as Record<string, { state: { values: { recentImages: Record<string, unknown>[] } } }>)[+ 'gallery-1'+ ] as { state: { values: { recentImages: Record<string, unknown>[] } } }+ ).state.values.recentImages;++ // Blanked, not removed: `getBoundedRecentImages` requires both to be strings and silently drops+ // any entry missing one, so deleting the keys would discard the whole recents overlay.+ expect(recent).toMatchObject({ imageName: 'recent.png', imageUrl: '', thumbnailUrl: '' });+ expect(Object.keys(recent!)).toContain('thumbnailUrl');+ expect(JSON.stringify(stripped)).not.toContain('source-install');+ });++ it('leaves an already-blank URL identical', () => {+ const document = {+ widgetStates: { gallery: { values: { recentImages: [{ imageName: 'a.png', imageUrl: '' }] } } },+ };++ expect(stripInstallationState(document)).toBe(document);+ });+/*** Only the gallery widget's own two keys are installation state. A board named* by a workflow node is an authored input and has to survive the round trip.diff --git a/invokeai/frontend/webv2/src/workbench/projects/projectAssets.ts b/invokeai/frontend/webv2/src/workbench/projects/projectAssets.tsindex 968e6f301e..0da365a7da 100644--- a/invokeai/frontend/webv2/src/workbench/projects/projectAssets.ts+++ b/invokeai/frontend/webv2/src/workbench/projects/projectAssets.ts@@ -110,6 +110,21 @@ export const GALLERY_INSTALLATION_KEYS: ReadonlySet<string> = new Set(['projectBconst INSTALLATION_STATE_KEYS: ReadonlySet<string> = new Set([...GALLERY_SELECTION_KEYS, ...GALLERY_INSTALLATION_KEYS]);+/**+ * URLs the document caches beside a media name, which name *this* install's server and this+ * install's copy of the media.+ *+ * They are installation state like the keys above, but they cannot be removed the way those are.+ * The persisted-recents validator (`getBoundedRecentImages`) requires both to be strings and drops+ * any entry missing one, so deleting them would silently discard the whole gallery-recents overlay+ * on import. Blanked instead: every consumer already falls back to deriving the URL from the media+ * name (`item.thumbnailUrl || item.fullUrl`, `slot.candidate.thumbnailUrl || galleryImageUrls…`),+ * which is the only correct answer once a transfer has renamed the media anyway. The name is+ * remapped; a URL built around the *old* name is not, and would keep resolving — to the source+ * project's picture.+ */+const DERIVED_URL_KEYS: ReadonlySet<string> = new Set(['imageUrl', 'thumbnailUrl', 'videoUrl']);+export interface ProjectAssetRefs {images: Set<string>;videos: Set<string>;@@ -198,6 +213,12 @@ const stripNode = (node: unknown): unknown => {continue;}+ if (DERIVED_URL_KEYS.has(key) && typeof value === 'string') {+ next[key] = '';+ hasChanged ||= value !== '';+ continue;+ }+const stripped = stripNode(value);next[key] = stripped;@@ -209,14 +230,17 @@ const stripNode = (node: unknown): unknown => {/*** Drop everything that describes *this install* rather than the project — the- * gallery's selection and its board ids — at every depth, so an exported project- * opens with nothing selected, on the board the receiving server assigns it.+ * gallery's selection, its board ids, and the URLs cached beside media names — at+ * every depth, so an exported project opens with nothing selected, on the board+ * the receiving server assigns it, resolving its pictures through the names it+ * actually owns.*- * Every reader of these values already tolerates their absence — selection is- * parsed with `typeof`/`Array.isArray` guards and falls back to nothing, and the- * board ids are re-supplied from the project record — so removing the key is the- * same as clearing it, without inventing a shape. Subtrees with nothing to drop- * keep their identity.+ * Every reader of the selection and board values already tolerates their absence —+ * selection is parsed with `typeof`/`Array.isArray` guards and falls back to+ * nothing, and the board ids are re-supplied from the project record — so removing+ * the key is the same as clearing it, without inventing a shape. The cached URLs+ * are blanked rather than removed, for the reason {@link DERIVED_URL_KEYS} gives.+ * Subtrees with nothing to change keep their identity.** Stripping by key at any depth rather than by walking into `widgetInstances` is* what makes this cover the legacy `widgetStates.gallery` shape for free, and it