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): keep control-layer filter results out of the gallery
joshistoast71268f87817a
diff --git a/invokeai/frontend/webv2/src/features/gallery/data/backend.test.ts b/invokeai/frontend/webv2/src/features/gallery/data/backend.test.tsindex df511f939b..34f7c180f0 100644--- a/invokeai/frontend/webv2/src/features/gallery/data/backend.test.ts+++ b/invokeai/frontend/webv2/src/features/gallery/data/backend.test.ts@@ -14,6 +14,7 @@ vi.mock('@platform/transport/http', () => ({import {getGalleryImageByName,+ imageMakeCanvasAssetChanges,imageMakeDurableChanges,imageSaveToGalleryChanges,listGalleryImages,@@ -167,3 +168,21 @@ describe('imageMakeDurableChanges', () => {expect('image_category' in body).toBe(false);});});++describe('imageMakeCanvasAssetChanges', () => {+ it('makes the image durable AND moves it out of the gallery images view', () => {+ // A node's output is `general` — precisely what the Images view lists — so+ // durability alone published every ControlNet preprocess into the gallery.+ expect(imageMakeCanvasAssetChanges()).toEqual({ image_category: 'other', is_intermediate: false });+ });++ it('uses the same category the canvas uploads its own paint bitmaps under', () => {+ // Layer pixels are layer pixels however they were produced; a filtered+ // control map must not be classified differently from a painted one.+ expect(imageMakeCanvasAssetChanges().image_category).toBe('other');+ });++ it('still clears is_intermediate, so the layer source cannot be collected', () => {+ expect(imageMakeCanvasAssetChanges().is_intermediate).toBe(false);+ });+});diff --git a/invokeai/frontend/webv2/src/features/gallery/data/backend.ts b/invokeai/frontend/webv2/src/features/gallery/data/backend.tsindex 9c4a2c752e..31bd67f295 100644--- a/invokeai/frontend/webv2/src/features/gallery/data/backend.ts+++ b/invokeai/frontend/webv2/src/features/gallery/data/backend.ts@@ -344,14 +344,33 @@ export const imageSaveToGalleryChanges = (): { is_intermediate: false; image_cat/*** The `ImageRecordChanges` body that makes an intermediate image durable without* changing its category. Clearing `is_intermediate` stops garbage collection;- * where the image appears is determined by its existing category. Used when a- * utility result becomes a canvas source while discarded previews remain- * intermediate and can be collected.+ * where the image appears is determined by its existing category.+ *+ * NOT for adopting a graph result as canvas pixels — a node's output is+ * `general`, so this alone publishes it to the gallery's Images view. Use+ * {@link imageMakeCanvasAssetChanges} there.*/export const imageMakeDurableChanges = (): { is_intermediate: false } => ({is_intermediate: false,});+/**+ * The `ImageRecordChanges` body that adopts a utility result as CANVAS-OWNED+ * pixels: durable (so it is not garbage-collected out from under the layer that+ * now points at it) and `image_category: 'other'`, the category the canvas+ * already uploads its own paint bitmaps under.+ *+ * A node's output is `general` by default, which is exactly what the gallery's+ * Images view lists — so promoting a control-layer filter result with+ * {@link imageMakeDurableChanges} alone published every ControlNet preprocess+ * into the user's gallery. These are layer pixels, not gallery images: they+ * belong with the rest of the canvas's assets.+ */+export const imageMakeCanvasAssetChanges = (): { is_intermediate: false; image_category: 'other' } => ({+ image_category: 'other',+ is_intermediate: false,+});+/*** Makes a single intermediate image durable (survives GC) without changing its* category, via `PATCH /api/v1/images/i/{image_name}`. Resolves once the PATCH@@ -365,6 +384,19 @@ export const makeImageDurable = async (imageName: string): Promise<void> => {});};+/**+ * Adopts a utility result as canvas-owned pixels — durable AND out of the+ * gallery's Images view. Used wherever a graph result becomes a layer's+ * persisted source; {@link makeImageDurable} remains for callers that must keep+ * whatever category the image already had.+ */+export const makeImageCanvasAsset = async (imageName: string): Promise<void> => {+ await apiFetchJson<BackendImageDTO>(`/api/v1/images/i/${encodeURIComponent(imageName)}`, {+ body: JSON.stringify(imageMakeCanvasAssetChanges()),+ method: 'PATCH',+ });+};+/*** Promotes a single image (e.g. a staged canvas candidate) into the gallery via* `PATCH /api/v1/images/i/{image_name}` and returns the updated {@link GalleryImage}.diff --git a/invokeai/frontend/webv2/src/features/gallery/index.ts b/invokeai/frontend/webv2/src/features/gallery/index.tsindex b4f088edd4..44c1101f35 100644--- a/invokeai/frontend/webv2/src/features/gallery/index.ts+++ b/invokeai/frontend/webv2/src/features/gallery/index.ts@@ -18,6 +18,7 @@ import {getGalleryImagesByNames,isDateBoardId,listGalleryBoards,+ makeImageCanvasAsset,makeImageDurable,removeImagesFromGalleryBoard,saveImageToGallery,@@ -41,6 +42,8 @@ export const galleryTransfers = {/** Durability transitions for intermediate results. */export const galleryDurability = {+ /** Durable, and adopted as canvas-owned pixels (out of the gallery's Images view). */+ makeCanvasAsset: makeImageCanvasAsset,makeDurable: makeImageDurable,save: saveImageToGallery,} as const;diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/FilterOptions.tsx b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/FilterOptions.tsxindex fe2bdb21c8..a4b18bb59e 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/FilterOptions.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/FilterOptions.tsx@@ -171,7 +171,7 @@ export const FilterOptionsBar = ({roundedEnd="none"size="xs"onClick={() =>- void getCanvasOperations(engine).commitFilterOperation('apply', galleryDurability.makeDurable)+ void getCanvasOperations(engine).commitFilterOperation('apply', galleryDurability.makeCanvasAsset)}>{t('common.apply')}@@ -197,7 +197,10 @@ export const FilterOptionsBar = ({disabled={!saveTargetEligibility.raster}value="raster"onClick={() =>- void getCanvasOperations(engine).commitFilterOperation('raster', galleryDurability.makeDurable)+ void getCanvasOperations(engine).commitFilterOperation(+ 'raster',+ galleryDurability.makeCanvasAsset+ )}><Menu.ItemText>{t('widgets.layers.selectObject.saveAs_raster')}</Menu.ItemText>@@ -206,7 +209,10 @@ export const FilterOptionsBar = ({disabled={!saveTargetEligibility.control}value="control"onClick={() =>- void getCanvasOperations(engine).commitFilterOperation('control', galleryDurability.makeDurable)+ void getCanvasOperations(engine).commitFilterOperation(+ 'control',+ galleryDurability.makeCanvasAsset+ )}><Menu.ItemText>{t('widgets.layers.selectObject.saveAs_control')}</Menu.ItemText>diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/RunLayerWorkflowDialog.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/RunLayerWorkflowDialog.tsxindex 8e53eafc6d..df68769d41 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/RunLayerWorkflowDialog.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/RunLayerWorkflowDialog.tsx@@ -363,7 +363,7 @@ export const RunLayerWorkflowDialog = ({exportLayer: (targetLayerId) => engine.exports.exportBakedLayerBlob(targetLayerId, { includeDisabled: true }),getImage: galleryImages.resolve,isGuardCurrent: (guard) => engine.exports.isLayerExportGuardCurrent(guard),- makeDurable: galleryDurability.makeDurable,+ makeDurable: galleryDurability.makeCanvasAsset,runGraph: (options) => runUtilityGraph({ ...options, hub: socketHub }),saveToGallery: galleryDurability.save,touchGallery: (targetProjectId) => gallery.touchImages(targetProjectId),