From 301a8fef92d15d485be5b20b9c8d4a6b65729624 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Wed, 18 Oct 2023 22:33:17 +1100 Subject: [PATCH] fix(ui): fix batch metadata logic when graph has no metadata On canvas, images have no metadata yet, so this needs to be handled --- .../graphBuilders/buildLinearBatchConfig.ts | 74 +++++++++++-------- .../nodes/util/graphBuilders/metadata.ts | 8 ++ 2 files changed, 50 insertions(+), 32 deletions(-) diff --git a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildLinearBatchConfig.ts b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildLinearBatchConfig.ts index 8bf9a2785a..59f8d4123f 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildLinearBatchConfig.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildLinearBatchConfig.ts @@ -11,7 +11,7 @@ import { NOISE, POSITIVE_CONDITIONING, } from './constants'; -import { removeMetadata } from './metadata'; +import { getHasMetadata, removeMetadata } from './metadata'; export const prepareLinearUIBatch = ( state: RootState, @@ -40,13 +40,15 @@ export const prepareLinearUIBatch = ( }); } - // add to metadata - removeMetadata(graph, 'seed'); - zipped.push({ - node_path: METADATA, - field_name: 'seed', - items: seeds, - }); + if (getHasMetadata(graph)) { + // add to metadata + removeMetadata(graph, 'seed'); + zipped.push({ + node_path: METADATA, + field_name: 'seed', + items: seeds, + }); + } if (graph.nodes[CANVAS_COHERENCE_NOISE]) { zipped.push({ @@ -78,12 +80,14 @@ export const prepareLinearUIBatch = ( } // add to metadata - removeMetadata(graph, 'seed'); - firstBatchDatumList.push({ - node_path: METADATA, - field_name: 'seed', - items: seeds, - }); + if (getHasMetadata(graph)) { + removeMetadata(graph, 'seed'); + firstBatchDatumList.push({ + node_path: METADATA, + field_name: 'seed', + items: seeds, + }); + } if (graph.nodes[CANVAS_COHERENCE_NOISE]) { firstBatchDatumList.push({ @@ -108,12 +112,14 @@ export const prepareLinearUIBatch = ( } // add to metadata - removeMetadata(graph, 'seed'); - secondBatchDatumList.push({ - node_path: METADATA, - field_name: 'seed', - items: seeds, - }); + if (getHasMetadata(graph)) { + removeMetadata(graph, 'seed'); + secondBatchDatumList.push({ + node_path: METADATA, + field_name: 'seed', + items: seeds, + }); + } if (graph.nodes[CANVAS_COHERENCE_NOISE]) { secondBatchDatumList.push({ @@ -140,12 +146,14 @@ export const prepareLinearUIBatch = ( } // add to metadata - removeMetadata(graph, 'positive_prompt'); - firstBatchDatumList.push({ - node_path: METADATA, - field_name: 'positive_prompt', - items: extendedPrompts, - }); + if (getHasMetadata(graph)) { + removeMetadata(graph, 'positive_prompt'); + firstBatchDatumList.push({ + node_path: METADATA, + field_name: 'positive_prompt', + items: extendedPrompts, + }); + } if (shouldConcatSDXLStylePrompt && model?.base_model === 'sdxl') { const stylePrompts = extendedPrompts.map((p) => @@ -161,12 +169,14 @@ export const prepareLinearUIBatch = ( } // add to metadata - removeMetadata(graph, 'positive_style_prompt'); - firstBatchDatumList.push({ - node_path: METADATA, - field_name: 'positive_style_prompt', - items: extendedPrompts, - }); + if (getHasMetadata(graph)) { + removeMetadata(graph, 'positive_style_prompt'); + firstBatchDatumList.push({ + node_path: METADATA, + field_name: 'positive_style_prompt', + items: extendedPrompts, + }); + } } data.push(firstBatchDatumList); diff --git a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/metadata.ts b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/metadata.ts index 547c45addf..5cc397ce68 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/metadata.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/metadata.ts @@ -56,3 +56,11 @@ export const removeMetadata = ( delete metadataNode[key]; }; + +export const getHasMetadata = (graph: NonNullableGraph): boolean => { + const metadataNode = graph.nodes[METADATA] as + | CoreMetadataInvocation + | undefined; + + return Boolean(metadataNode); +};