Skip to content

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.

fix(webv2): stabilize Call Saved Workflow nodes

JPPhoto0345a32fb7bd
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/buildGraph.test.ts b/invokeai/frontend/webv2/src/features/workflow/core/buildGraph.test.ts
index a5c95769ca..0dc246fa73 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/buildGraph.test.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/buildGraph.test.ts
@@ -324,7 +324,7 @@ describe('compileProjectGraph', () => {
]);
});
- it('omits auto/none board sentinels and keeps explicit boards', () => {
+ it('preserves auto/none board sentinels and keeps explicit boards', () => {
const { doc, sinkId } = buildDocument();
const withAutoBoard = projectGraphReducer(doc, {
fieldName: 'board',
@@ -333,7 +333,16 @@ describe('compileProjectGraph', () => {
value: 'auto',
});
- expect(compileProjectGraph(withAutoBoard, templates).backendGraph?.nodes[sinkId]).not.toHaveProperty('board');
+ expect(compileProjectGraph(withAutoBoard, templates).backendGraph?.nodes[sinkId]).toMatchObject({ board: 'auto' });
+
+ const withNoneBoard = projectGraphReducer(doc, {
+ fieldName: 'board',
+ nodeId: sinkId,
+ type: 'setFieldValue',
+ value: 'none',
+ });
+
+ expect(compileProjectGraph(withNoneBoard, templates).backendGraph?.nodes[sinkId]).toMatchObject({ board: 'none' });
const withExplicitBoard = projectGraphReducer(doc, {
fieldName: 'board',
@@ -649,6 +658,19 @@ describe('planWorkflowSubmission', () => {
expect(plan.graph.nodes.find((node) => node.id === ids[1])?.inputs.seed).toBe(100);
});
+ it('plans persisted dynamic seed fields', () => {
+ const dynamicTemplate = template('dynamic_node', {});
+ const node = buildInvocationNode(dynamicTemplate, { x: 0, y: 0 });
+ node.data.dynamicInputTemplates = { seed: seedInput };
+ node.data.inputs.seed = { label: 'Seed', name: 'seed', seedMode: 'increment', value: 42 };
+ const document = { ...createProjectGraph('dynamic-seed-plan'), nodes: [node] };
+
+ const plan = planWorkflowSubmission(document, { dynamic_node: dynamicTemplate }, { batchCount: 2 });
+
+ expect(plan.seeds).toEqual([{ fieldName: 'seed', nodeId: node.id, seed: 42, seedStep: 1 }]);
+ expect(plan.graph.backendGraph.nodes[node.id]?.seed).toBe(42);
+ });
+
it('wraps the authored seed and the advance over the inclusive seed range', () => {
const { doc } = buildSeeded([{ seed: 1, seedMode: 'decrement' }]);
const plan = planWorkflowSubmission(doc, seededTemplates, { batchCount: 3 });
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/buildGraph.ts b/invokeai/frontend/webv2/src/features/workflow/core/buildGraph.ts
index 51c4c586aa..785dda864e 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/buildGraph.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/buildGraph.ts
@@ -63,10 +63,10 @@ const getNodeInputTemplates = (
/**
* Translates a board field value to the backend shape: `auto` and `none`
- * sentinels are omitted so the backend applies its default board behavior.
+ * sentinels are passed through for backend board handling.
*/
const toBoardGraphValue = (value: unknown): unknown => {
- if (value === 'auto' || value === 'none' || isEmptyValue(value)) {
+ if (isEmptyValue(value)) {
return undefined;
}
@@ -124,6 +124,25 @@ export const getProjectGraphReadiness = (
continue;
}
+ if (node.data.type === 'call_saved_workflow') {
+ const workflowId = node.data.inputs.workflow_id?.value;
+
+ if (typeof workflowId !== 'string' || workflowId.trim() === '') {
+ reasons.push('Call Saved Workflow requires a saved workflow.');
+ continue;
+ }
+
+ if (node.data.callSavedWorkflowStatus === 'loading' || node.data.callSavedWorkflowStatus === undefined) {
+ reasons.push('Call Saved Workflow inputs are still loading.');
+ continue;
+ }
+
+ if (node.data.callSavedWorkflowStatus === 'error') {
+ reasons.push('The selected saved workflow is unavailable or incompatible.');
+ continue;
+ }
+ }
+
for (const inputTemplate of getNodeInputTemplates(node, template)) {
if (connectedInputs.has(`${node.id}:${inputTemplate.name}`)) {
continue;
@@ -371,7 +390,7 @@ export const planWorkflowSeeds = (
continue;
}
- for (const inputTemplate of Object.values(template.inputs)) {
+ for (const inputTemplate of Object.values({ ...template.inputs, ...node.data.dynamicInputTemplates })) {
if (!isSeedInputField(inputTemplate) || connectedInputs.has(`${node.id}:${inputTemplate.name}`)) {
continue;
}
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/callSavedWorkflow.test.ts b/invokeai/frontend/webv2/src/features/workflow/core/callSavedWorkflow.test.ts
index 42616be75b..06b24afca8 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/callSavedWorkflow.test.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/callSavedWorkflow.test.ts
@@ -16,6 +16,7 @@ import {
syncCallSavedWorkflowFields,
} from './callSavedWorkflow';
import { buildInvocationNode, createProjectGraph, projectGraphReducer } from './document';
+import { parseWorkflowJson, serializeWorkflowJson } from './workflowJson';
const field = (name: string, typeName: string, overrides: Partial<FieldInputTemplate> = {}): FieldInputTemplate => ({
default: typeName === 'IntegerField' ? 0 : '',
@@ -151,6 +152,108 @@ describe('Call Saved Workflow dynamic fields', () => {
expect(node?.data.inputs[dynamicFieldName('b')]?.value).toBe(2);
});
+ it('preserves dynamic values and user presentation overrides after JSON reload', () => {
+ const callNode = buildInvocationNode(callSavedWorkflowTemplate, { x: 0, y: 0 });
+ callNode.id = 'call-1';
+ const fields = getSavedWorkflowDynamicFields(buildChildWorkflow(), templates);
+ let document = syncCallSavedWorkflowFields(
+ { ...createProjectGraph('parent'), nodes: [callNode] },
+ callNode.id,
+ fields,
+ []
+ );
+ document = projectGraphReducer(document, {
+ fieldName: dynamicFieldName('a'),
+ nodeId: callNode.id,
+ type: 'setFieldValue',
+ value: 99,
+ });
+ document = projectGraphReducer(document, {
+ fieldName: dynamicFieldName('a'),
+ label: 'Custom label',
+ nodeId: callNode.id,
+ type: 'setFieldLabel',
+ });
+ document = projectGraphReducer(document, {
+ description: 'Custom description',
+ fieldName: dynamicFieldName('a'),
+ nodeId: callNode.id,
+ type: 'setFieldDescription',
+ });
+
+ const reloaded = parseWorkflowJson(serializeWorkflowJson(document)).document;
+ const resynced = syncCallSavedWorkflowFields(reloaded, callNode.id, fields, []);
+ const node = resynced.nodes.find((candidate): candidate is WorkflowInvocationNode => candidate.id === callNode.id);
+
+ expect(node?.data.inputs[dynamicFieldName('a')]).toMatchObject({
+ description: 'Custom description',
+ label: 'Custom label',
+ value: 99,
+ });
+ });
+
+ it('deduplicates duplicate child form fields before syncing', () => {
+ const child = buildChildWorkflow();
+ const root = child.form.elements[child.form.rootElementId];
+ const firstField = Object.values(child.form.elements).find(
+ (element) => element.type === 'node-field' && element.data.fieldIdentifier.fieldName === 'a'
+ );
+
+ expect(root?.type).toBe('container');
+ expect(firstField?.type).toBe('node-field');
+
+ if (root?.type !== 'container' || firstField?.type !== 'node-field') {
+ return;
+ }
+
+ child.form.elements.duplicate = { ...firstField, id: 'duplicate' };
+ root.data.children.push('duplicate');
+
+ const fields = getSavedWorkflowDynamicFields(child, templates);
+
+ expect(fields.map((item) => item.fieldName)).toEqual([dynamicFieldName('a'), dynamicFieldName('b')]);
+ });
+
+ it('marks a selected Call Saved Workflow as not ready until its child is synchronized', () => {
+ const callNode = buildInvocationNode(callSavedWorkflowTemplate, { x: 0, y: 0 });
+ callNode.id = 'call-1';
+ const document = projectGraphReducer(
+ { ...createProjectGraph('parent'), nodes: [callNode] },
+ { fieldName: 'workflow_id', nodeId: callNode.id, type: 'setFieldValue', value: 'child-1' }
+ );
+ const readiness = getProjectGraphReadiness(document, { error: null, status: 'loaded', templates });
+
+ expect(readiness.canInvoke).toBe(false);
+ expect(readiness.reasons).toContain('Call Saved Workflow inputs are still loading.');
+ });
+
+ it('blocks empty and incompatible Call Saved Workflow selections', () => {
+ const callNode = buildInvocationNode(callSavedWorkflowTemplate, { x: 0, y: 0 });
+ callNode.id = 'call-1';
+ const emptyReadiness = getProjectGraphReadiness(
+ { ...createProjectGraph('empty-selection'), nodes: [callNode] },
+ { error: null, status: 'loaded', templates }
+ );
+ const selected = projectGraphReducer(
+ { ...createProjectGraph('incompatible-selection'), nodes: [callNode] },
+ { fieldName: 'workflow_id', nodeId: callNode.id, type: 'setFieldValue', value: 'child-1' }
+ );
+ const incompatible = projectGraphReducer(selected, {
+ nodeId: callNode.id,
+ status: 'error',
+ type: 'setCallSavedWorkflowStatus',
+ });
+
+ expect(emptyReadiness).toMatchObject({
+ canInvoke: false,
+ reasons: ['Call Saved Workflow requires a saved workflow.'],
+ });
+ expect(getProjectGraphReadiness(incompatible, { error: null, status: 'loaded', templates })).toMatchObject({
+ canInvoke: false,
+ reasons: ['The selected saved workflow is unavailable or incompatible.'],
+ });
+ });
+
it('removes dynamic edges whose exposed field disappeared or changed type', () => {
const source = buildInvocationNode(addTemplate, { x: 0, y: 0 });
source.id = 'source-1';
@@ -222,6 +325,7 @@ describe('Call Saved Workflow dynamic fields', () => {
it('checks required dynamic fields when determining workflow readiness', () => {
const callNode = buildInvocationNode(callSavedWorkflowTemplate, { x: 0, y: 0 });
callNode.id = 'call-1';
+ callNode.data.inputs.workflow_id = { label: '', name: 'workflow_id', value: 'child-1' };
const fields = getSavedWorkflowDynamicFields(buildChildWorkflow(), templates).map((field) => ({
...field,
fieldTemplate: { ...field.fieldTemplate, required: true },
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/callSavedWorkflow.ts b/invokeai/frontend/webv2/src/features/workflow/core/callSavedWorkflow.ts
index 03286f669e..af0ed3f402 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/callSavedWorkflow.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/callSavedWorkflow.ts
@@ -15,6 +15,8 @@ import { validateConnectionTypes } from './validation';
/** Prefix used by the backend to distinguish child-workflow inputs from node inputs. */
export const CALL_SAVED_WORKFLOW_DYNAMIC_FIELD_PREFIX = 'saved_workflow_input::';
+export type CallSavedWorkflowStatus = 'loading' | 'ready' | 'error';
+
export interface SavedWorkflowDynamicField {
fieldName: string;
fieldTemplate: FieldInputTemplate;
@@ -79,6 +81,7 @@ export const getSavedWorkflowDynamicFields = (
}
const dynamicFields: SavedWorkflowDynamicField[] = [];
+ const seenFieldNames = new Set<string>();
for (const element of getFormElementsInOrder(workflow.form)) {
if (element.type !== 'node-field') {
@@ -100,6 +103,12 @@ export const getSavedWorkflowDynamicFields = (
}
const dynamicFieldName = getDynamicFieldName(nodeId, fieldName);
+
+ if (seenFieldNames.has(dynamicFieldName)) {
+ continue;
+ }
+
+ seenFieldNames.add(dynamicFieldName);
const label = field.label || fieldTemplate.title || fieldName;
const description = field.description || fieldTemplate.description || '';
@@ -197,7 +206,8 @@ export const syncCallSavedWorkflowFields = (
document: ProjectGraphState,
nodeId: string,
fields: SavedWorkflowDynamicField[],
- edgeIdsToRemove: string[]
+ edgeIdsToRemove: string[],
+ status: CallSavedWorkflowStatus = 'ready'
): ProjectGraphState => {
const node = document.nodes.find((candidate) => candidate.id === nodeId);
@@ -205,7 +215,10 @@ export const syncCallSavedWorkflowFields = (
return document;
}
- const nextFieldNames = new Set(fields.map((field) => field.fieldName));
+ const uniqueFields = fields.filter(
+ (field, index) => fields.findIndex((candidate) => candidate.fieldName === field.fieldName) === index
+ );
+ const nextFieldNames = new Set(uniqueFields.map((field) => field.fieldName));
const previousTemplates = node.data.dynamicInputTemplates ?? {};
const nextInputs: typeof node.data.inputs = {};
const nextTemplates: NonNullable<typeof node.data.dynamicInputTemplates> = {};
@@ -216,16 +229,24 @@ export const syncCallSavedWorkflowFields = (
}
}
- for (const field of fields) {
+ for (const field of uniqueFields) {
const previous = node.data.inputs[field.fieldName];
const previousTemplate = previousTemplates[field.fieldName];
const keepValue = previous && previousTemplate && sameFieldType(previousTemplate, field.fieldTemplate);
+ const label =
+ keepValue && previous && previousTemplate && previous.label !== previousTemplate.title
+ ? previous.label
+ : field.label;
+ const description =
+ keepValue && previous && previousTemplate && (previous.description ?? '') !== previousTemplate.description
+ ? previous.description
+ : field.description;
nextTemplates[field.fieldName] = field.fieldTemplate;
nextInputs[field.fieldName] = {
...(keepValue ? previous : {}),
- description: field.description,
- label: field.label,
+ description,
+ label,
name: field.fieldName,
value: keepValue ? previous.value : field.initialValue,
};
@@ -233,7 +254,7 @@ export const syncCallSavedWorkflowFields = (
const nextNode: WorkflowInvocationNode = {
...node,
- data: { ...node.data, dynamicInputTemplates: nextTemplates, inputs: nextInputs },
+ data: { ...node.data, callSavedWorkflowStatus: status, dynamicInputTemplates: nextTemplates, inputs: nextInputs },
};
const removedEdgeIds = new Set(edgeIdsToRemove);
@@ -281,3 +302,28 @@ export const clearSavedWorkflowDynamicFields = (document: ProjectGraphState, nod
edgeIds
);
};
+
+export const setCallSavedWorkflowStatus = (
+ document: ProjectGraphState,
+ nodeId: string,
+ status: CallSavedWorkflowStatus
+): ProjectGraphState => {
+ const node = document.nodes.find((candidate) => candidate.id === nodeId);
+
+ if (!node || !isInvocationNode(node) || node.data.type !== 'call_saved_workflow') {
+ return document;
+ }
+
+ if (node.data.callSavedWorkflowStatus === status) {
+ return document;
+ }
+
+ return {
+ ...document,
+ nodes: document.nodes.map((candidate) =>
+ candidate.id === nodeId && isInvocationNode(candidate)
+ ? { ...candidate, data: { ...candidate.data, callSavedWorkflowStatus: status } }
+ : candidate
+ ),
+ };
+};
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/connectors.test.ts b/invokeai/frontend/webv2/src/features/workflow/core/connectors.test.ts
index 6214f6d049..f4b5f8936f 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/connectors.test.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/connectors.test.ts
@@ -1,8 +1,13 @@
import { describe, expect, it } from 'vitest';
-import type { WorkflowInvocationNode } from './types';
+import type { FieldInputTemplate, InvocationTemplates, WorkflowInvocationNode } from './types';
-import { getConnectorDeletionSpliceConnections } from './connectors';
+import {
+ CONNECTOR_INPUT_HANDLE,
+ CONNECTOR_OUTPUT_HANDLE,
+ getConnectorDeletionSpliceConnections,
+ resolveConnectorTarget,
+} from './connectors';
import { createProjectGraph, projectGraphReducer } from './document';
const node = (id: string, type: string): WorkflowInvocationNode => ({
@@ -22,6 +27,29 @@ const node = (id: string, type: string): WorkflowInvocationNode => ({
type: 'invocation',
});
+const dynamicInput = (name: string): FieldInputTemplate => ({
+ description: '',
+ exclusiveMaximum: null,
+ exclusiveMinimum: null,
+ fieldKind: 'input',
+ input: 'any',
+ maximum: null,
+ minimum: null,
+ multipleOf: null,
+ name,
+ options: null,
+ required: false,
+ title: name,
+ type: { batch: false, cardinality: 'SINGLE', name: 'IntegerField' },
+ uiChoiceLabels: null,
+ uiComponent: null,
+ uiHidden: false,
+ uiModelBase: null,
+ uiModelFormat: null,
+ uiModelType: null,
+ uiOrder: null,
+});
+
describe('connector deletion', () => {
it('reconnects ordinary data through a removed connector', () => {
const source = node('source', 'source');
@@ -278,3 +306,47 @@ describe('connector deletion', () => {
]);
});
});
+
+describe('connector target resolution', () => {
+ it('uses a persisted dynamic input template for a Call Saved Workflow target', () => {
+ const source = node('source', 'source');
+ const target = node('target', 'call_saved_workflow');
+ target.data.dynamicInputTemplates = { dynamic_input: dynamicInput('dynamic_input') };
+ const templates: InvocationTemplates = {};
+
+ expect(
+ resolveConnectorTarget(
+ 'connector',
+ [
+ source,
+ {
+ data: { label: '' },
+ id: 'connector',
+ position: { x: 0, y: 0 },
+ type: 'connector',
+ },
+ target,
+ ],
+ [
+ {
+ id: 'source-connector',
+ source: 'source',
+ sourceHandle: 'output',
+ target: 'connector',
+ targetHandle: CONNECTOR_INPUT_HANDLE,
+ type: 'default',
+ },
+ {
+ id: 'connector-target',
+ source: 'connector',
+ sourceHandle: CONNECTOR_OUTPUT_HANDLE,
+ target: 'target',
+ targetHandle: 'dynamic_input',
+ type: 'default',
+ },
+ ],
+ templates
+ )?.type
+ ).toEqual({ batch: false, cardinality: 'SINGLE', name: 'IntegerField' });
+ });
+});
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/connectors.ts b/invokeai/frontend/webv2/src/features/workflow/core/connectors.ts
index 468d3c5609..aac7905636 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/connectors.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/connectors.ts
@@ -435,7 +435,10 @@ const resolveConnectorTargetsWithCache = (
targets.push({
fieldName: outboundEdge.targetHandle,
nodeId: targetNode.id,
- type: templates?.[targetNode.data.type]?.inputs[outboundEdge.targetHandle]?.type ?? null,
+ type:
+ targetNode.data.dynamicInputTemplates?.[outboundEdge.targetHandle]?.type ??
+ templates?.[targetNode.data.type]?.inputs[outboundEdge.targetHandle]?.type ??
+ null,
});
continue;
}
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/document.ts b/invokeai/frontend/webv2/src/features/workflow/core/document.ts
index 5595b1a4ee..e99ced8612 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/document.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/document.ts
@@ -22,6 +22,7 @@ import type {
import {
clearSavedWorkflowDynamicFields,
+ setCallSavedWorkflowStatus,
syncCallSavedWorkflowFields,
type SavedWorkflowDynamicField,
} from './callSavedWorkflow';
@@ -102,6 +103,7 @@ export const buildInvocationNode = (template: InvocationTemplate, position: XYPo
type: template.type,
useCache: template.useCache,
version: template.version,
+ ...(template.type === 'call_saved_workflow' ? { callSavedWorkflowStatus: 'ready' as const } : {}),
},
id: createWorkflowId(template.type),
position,
@@ -309,7 +311,9 @@ export type ProjectGraphAction =
nodeId: string;
fields: SavedWorkflowDynamicField[];
edgeIdsToRemove: string[];
+ status?: 'loading' | 'ready' | 'error';
}
+ | { type: 'setCallSavedWorkflowStatus'; nodeId: string; status: 'loading' | 'ready' | 'error' }
| { type: 'setFieldLabel'; nodeId: string; fieldName: string; label: string }
| { type: 'setFieldDescription'; nodeId: string; fieldName: string; description: string }
| { type: 'setFieldSeedMode'; nodeId: string; fieldName: string; seedMode: SeedMode }
@@ -559,14 +563,25 @@ const applyProjectGraphAction = (document: ProjectGraphState, action: ProjectGra
const clearedDocument = shouldClearDynamicFields
? clearSavedWorkflowDynamicFields(document, action.nodeId)
: document;
-
- return setFieldInstance(clearedDocument, action.nodeId, action.fieldName, (instance) => ({
+ const nextDocument =
+ shouldClearDynamicFields && node && isInvocationNode(node) && node.data.type === 'call_saved_workflow'
+ ? setCallSavedWorkflowStatus(
+ clearedDocument,
+ action.nodeId,
+ typeof action.value === 'string' && action.value.trim() ? 'loading' : 'ready'
+ )
+ : clearedDocument;
+
+ return setFieldInstance(nextDocument, action.nodeId, action.fieldName, (instance) => ({
...instance,
value: action.value,
}));
}
case 'syncCallSavedWorkflowFields': {
- return syncCallSavedWorkflowFields(document, action.nodeId, action.fields, action.edgeIdsToRemove);
+ return syncCallSavedWorkflowFields(document, action.nodeId, action.fields, action.edgeIdsToRemove, action.status);
+ }
+ case 'setCallSavedWorkflowStatus': {
+ return setCallSavedWorkflowStatus(document, action.nodeId, action.status);
}
case 'setFieldLabel': {
return setFieldInstance(document, action.nodeId, action.fieldName, (instance) => ({
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/layerWorkflow.test.ts b/invokeai/frontend/webv2/src/features/workflow/core/layerWorkflow.test.ts
index 7b1294ae0e..2f9377d808 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/layerWorkflow.test.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/layerWorkflow.test.ts
@@ -200,6 +200,16 @@ describe('layer workflow binding discovery', () => {
]);
});
+ it('finds persisted dynamic image inputs on Call Saved Workflow nodes', () => {
+ const callTemplate = template('call_saved_workflow');
+ const callNode = node('call', callTemplate);
+ callNode.data.dynamicInputTemplates = { image: input('image', { title: 'Child image' }) };
+
+ expect(getLayerWorkflowInputs(document([callNode]), { call_saved_workflow: callTemplate })).toEqual([
+ binding('call', 'image', 'call_saved_workflow → Child image'),
+ ]);
+ });
+
it('finds only single non-batch image outputs and skips image primitive nodes', () => {
const processorTemplate = template(
'processor',
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/layerWorkflow.ts b/invokeai/frontend/webv2/src/features/workflow/core/layerWorkflow.ts
index 8160c1cc09..ed6d5b914e 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/layerWorkflow.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/layerWorkflow.ts
@@ -134,7 +134,9 @@ export const getLayerWorkflowInputs = (
continue;
}
- for (const field of sortInputFields(Object.values(template.inputs))) {
+ for (const field of sortInputFields(
+ Object.values({ ...template.inputs, ...candidate.data.dynamicInputTemplates })
+ )) {
if (!isSingleImageField(field) || connectedInputs.has(`${candidate.id}:${field.name}`)) {
continue;
}
@@ -238,7 +240,10 @@ export const buildLayerWorkflowGraph = (options: BuildLayerWorkflowGraphOptions)
const inputNode = cloned.nodes.find(
(candidate): candidate is WorkflowInvocationNode => candidate.id === input.nodeId && isInvocationNode(candidate)
);
- const inputTemplate = inputNode ? templates[inputNode.data.type]?.inputs[input.fieldName] : undefined;
+ const inputTemplate = inputNode
+ ? (inputNode.data.dynamicInputTemplates?.[input.fieldName] ??
+ templates[inputNode.data.type]?.inputs[input.fieldName])
+ : undefined;
if (!inputNode || !inputTemplate) {
throw new Error('The selected workflow input binding is no longer available.');
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/modelRequirements.test.ts b/invokeai/frontend/webv2/src/features/workflow/core/modelRequirements.test.ts
index 4e881b9914..da8a038151 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/modelRequirements.test.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/modelRequirements.test.ts
@@ -121,6 +121,35 @@ describe('extractWorkflowModelRequirements', () => {
]);
});
+ it('extracts model requirements from persisted dynamic input templates', () => {
+ const model = fieldInput('model', { required: true });
+ const templates: InvocationTemplates = {
+ call_saved_workflow: invocationTemplate('call_saved_workflow', {}),
+ };
+ const document = graphDocument([
+ {
+ ...invocationNode('call', 'call_saved_workflow', {
+ model: { base: 'sdxl', hash: 'hash-1', key: 'model-key-1', name: 'My Model', type: 'main' },
+ }),
+ data: {
+ ...invocationNode('call', 'call_saved_workflow').data,
+ dynamicInputTemplates: { model },
+ inputs: { model: { label: 'Model', name: 'model', value: { base: 'sdxl', key: 'model-key-1' } } },
+ },
+ },
+ ]);
+
+ const { requirements } = extractWorkflowModelRequirements(document, templates);
+
+ expect(requirements).toEqual([
+ {
+ identifier: { base: 'sdxl', key: 'model-key-1' },
+ kind: 'exact',
+ label: 'model-key-1',
+ },
+ ]);
+ });
+
it('skips inputs that are fed by a connection', () => {
const templates: InvocationTemplates = {
main_model_loader: invocationTemplate('main_model_loader', {
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/modelRequirements.ts b/invokeai/frontend/webv2/src/features/workflow/core/modelRequirements.ts
index d3c3ccd33b..a6a76b8263 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/modelRequirements.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/modelRequirements.ts
@@ -247,7 +247,7 @@ export const extractWorkflowModelRequirements = (
requirements.push({ identifier, kind: 'exact', label: identifier.name ?? identifier.key });
};
- for (const fieldTemplate of Object.values(template.inputs)) {
+ for (const fieldTemplate of Object.values({ ...template.inputs, ...node.data.dynamicInputTemplates })) {
const isLoraCollection = fieldTemplate.type.name === 'LoRAField';
if (!isModelFieldType(fieldTemplate.type) && !isLoraCollection) {
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/types.ts b/invokeai/frontend/webv2/src/features/workflow/core/types.ts
index 6b92bf9bd9..000b0c201c 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/types.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/types.ts
@@ -118,8 +118,10 @@ export interface WorkflowInvocationNodeData {
useCache: boolean;
nodePack: string;
inputs: Record<string, WorkflowFieldInstance>;
- /** Runtime-only templates for fields exposed by the selected saved workflow. */
+ /** Persisted templates for fields exposed by the selected saved workflow. */
dynamicInputTemplates?: Record<string, FieldInputTemplate>;
+ /** Runtime reconciliation state for the selected saved workflow. */
+ callSavedWorkflowStatus?: 'loading' | 'ready' | 'error';
}
export interface WorkflowInvocationNode {
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/validation.test.ts b/invokeai/frontend/webv2/src/features/workflow/core/validation.test.ts
index 7572f319aa..67a7edb676 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/validation.test.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/validation.test.ts
@@ -387,6 +387,22 @@ describe('getWorkflowTargetFieldType', () => {
expect(getWorkflowTargetFieldType(document, templates, 'connector', 'in')).toBeNull();
});
+ it('resolves a persisted dynamic input template when the static template lacks the field', () => {
+ const dynamicNode = makeNode('dynamic', 'number');
+ dynamicNode.data.dynamicInputTemplates = {
+ dynamic_value: { ...templates.number.inputs.value, name: 'dynamic_value' },
+ };
+
+ expect(
+ getWorkflowTargetFieldType(
+ { edges: [], nodes: [dynamicNode] },
+ { number: { ...templates.number, inputs: {} } },
+ 'dynamic',
+ 'dynamic_value'
+ )
+ ).toEqual(single('IntegerField'));
+ });
+
it('rejects direct-only inputs', () => {
const directTemplates: InvocationTemplates = {
number: {
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/workflowJson.test.ts b/invokeai/frontend/webv2/src/features/workflow/core/workflowJson.test.ts
index 19b6a486a8..543e962fc3 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/workflowJson.test.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/workflowJson.test.ts
@@ -100,7 +100,7 @@ describe('workflow JSON round-trip', () => {
expect(serialized).toHaveProperty('form');
});
- it('does not persist runtime-only dynamic input templates', () => {
+ it('persists dynamic input templates needed to preserve Call Saved Workflow values', () => {
const node = buildInvocationNode(template, { x: 0, y: 0 });
node.data.dynamicInputTemplates = { runtime: template.inputs.prompt! };
let doc = createProjectGraph('runtime-fields');
@@ -110,7 +110,10 @@ describe('workflow JSON round-trip', () => {
nodes: Array<{ data: Record<string, unknown> }>;
};
- expect(serialized.nodes[0]?.data).not.toHaveProperty('dynamicInputTemplates');
+ expect(serialized.nodes[0]?.data).toHaveProperty('dynamicInputTemplates');
+ expect(parseWorkflowJson(serialized).document.nodes[0]).toMatchObject({
+ data: { dynamicInputTemplates: { runtime: template.inputs.prompt } },
+ });
});
it('round-trips notes, current_image, and connector UI nodes', () => {
@@ -223,7 +226,7 @@ describe('parseWorkflowJson tolerance', () => {
});
});
- it('adds exposed fields that are missing from an existing stored form', () => {
+ it('does not merge stale exposed fields into an existing stored form', () => {
const { document, warnings } = parseWorkflowJson({
edges: [],
exposedFields: [
@@ -264,7 +267,7 @@ describe('parseWorkflowJson tolerance', () => {
getFormChildren(document.form).map(
(element) => element.type === 'node-field' && element.data.fieldIdentifier.fieldName
)
- ).toEqual(['prompt', 'other']);
+ ).toEqual(['prompt']);
});
it('preserves connector nodes and edges', () => {
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/workflowJson.ts b/invokeai/frontend/webv2/src/features/workflow/core/workflowJson.ts
index a53f2a62f8..407d258519 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/workflowJson.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/workflowJson.ts
@@ -2,6 +2,7 @@ import { SEED_MODES } from '@platform/core/seed';
import { z } from 'zod';
import type {
+ FieldInputTemplate,
ProjectGraphState,
WorkflowEdge,
WorkflowFieldInstance,
@@ -82,6 +83,45 @@ const zConnectorNode = z.object({
const zAnyNode = z.union([zInvocationNode, zNotesNode, zCurrentImageNode, zConnectorNode]);
+const isRecord = (value: unknown): value is Record<string, unknown> =>
+ typeof value === 'object' && value !== null && !Array.isArray(value);
+
+const isPersistedFieldInputTemplate = (value: unknown): value is FieldInputTemplate => {
+ if (!isRecord(value) || !isRecord(value.type)) {
+ return false;
+ }
+
+ return (
+ typeof value.name === 'string' &&
+ typeof value.title === 'string' &&
+ typeof value.description === 'string' &&
+ typeof value.required === 'boolean' &&
+ (value.fieldKind === 'input' || value.fieldKind === 'internal') &&
+ (value.input === 'connection' || value.input === 'direct' || value.input === 'any') &&
+ typeof value.type.name === 'string' &&
+ (value.type.cardinality === 'SINGLE' ||
+ value.type.cardinality === 'COLLECTION' ||
+ value.type.cardinality === 'SINGLE_OR_COLLECTION') &&
+ typeof value.type.batch === 'boolean'
+ );
+};
+
+const parsePersistedDynamicInputTemplates = (value: unknown): Record<string, FieldInputTemplate> | undefined => {
+ if (!isRecord(value)) {
+ return undefined;
+ }
+
+ const templates: Record<string, FieldInputTemplate> = {};
+
+ for (const [name, template] of Object.entries(value)) {
+ if (isPersistedFieldInputTemplate(template)) {
+ templates[name] = template;
+ }
+ }
+
+ return templates;
+};
+
const zWorkflowEdge = z.object({
id: z.string().catch(''),
source: z.string().min(1),
@@ -220,39 +260,6 @@ const parseForm = (
}
}
- // Legacy workflows may carry both a form and an exposedFields list. Keep
- // fields added after the form was saved instead of silently dropping them.
- const root = form.elements[form.rootElementId];
-
- if (root?.type === 'container') {
- const existingFieldKeys = new Set(
- Object.values(form.elements)
- .filter(
- (element): element is Extract<WorkflowFormElement, { type: 'node-field' }> => element.type === 'node-field'
- )
- .map((element) => `${element.data.fieldIdentifier.nodeId}:${element.data.fieldIdentifier.fieldName}`)
- );
-
- for (const fieldIdentifier of exposedFields) {
- const fieldKey = `${fieldIdentifier.nodeId}:${fieldIdentifier.fieldName}`;
-
- if (!nodeIds.has(fieldIdentifier.nodeId) || existingFieldKeys.has(fieldKey)) {
- continue;
- }
-
- const element: WorkflowFormElement = {
- data: { fieldIdentifier, showDescription: false, showShuffle: false },
- id: createWorkflowId('node-field'),
- parentId: root.id,
- type: 'node-field',
- };
-
- form.elements[element.id] = element;
- root.data.children.push(element.id);
- existingFieldKeys.add(fieldKey);
- }
- }
-
// Drop node-field elements that point at nodes which did not survive parsing.
for (const element of Object.values(form.elements)) {
if (element.type !== 'node-field' || nodeIds.has(element.data.fieldIdentifier.nodeId)) {
@@ -335,8 +342,11 @@ export const parseWorkflowJson = (raw: unknown): ParsedWorkflow => {
};
}
+ const dynamicInputTemplates = parsePersistedDynamicInputTemplates(node.data.dynamicInputTemplates);
+
nodes.push({
data: {
+ ...(dynamicInputTemplates ? { dynamicInputTemplates } : {}),
inputs,
isIntermediate: node.data.isIntermediate,
isOpen: node.data.isOpen,
@@ -346,6 +356,14 @@ export const parseWorkflowJson = (raw: unknown): ParsedWorkflow => {
type: node.data.type,
useCache: node.data.useCache,
version: node.data.version,
+ ...(node.data.type === 'call_saved_workflow'
+ ? {
+ callSavedWorkflowStatus:
+ typeof inputs.workflow_id?.value === 'string' && inputs.workflow_id.value.trim()
+ ? ('loading' as const)
+ : ('ready' as const),
+ }
+ : {}),
},
id: node.id,
position: node.position,
@@ -399,7 +417,7 @@ export const parseWorkflowJson = (raw: unknown): ParsedWorkflow => {
};
const serializeInvocationNode = (node: Extract<WorkflowNode, { type: 'invocation' }>) => {
- const { dynamicInputTemplates: _dynamicInputTemplates, ...data } = structuredClone(node.data);
+ const { callSavedWorkflowStatus: _callSavedWorkflowStatus, ...data } = structuredClone(node.data);
return {
data: { ...data, id: node.id },
diff --git a/invokeai/frontend/webv2/src/features/workflow/data/savedWorkflowQueries.test.ts b/invokeai/frontend/webv2/src/features/workflow/data/savedWorkflowQueries.test.ts
new file mode 100644
index 0000000000..ba8f0ab8da
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/workflow/data/savedWorkflowQueries.test.ts
@@ -0,0 +1,51 @@
+import { describe, expect, it } from 'vitest';
+
+import {
+ getSavedWorkflowDetailQueryStatus,
+ isSavedWorkflowDetailQueryKey,
+ savedWorkflowDetailQueryOptions,
+ shouldFetchSavedWorkflowDetail,
+} from './savedWorkflowQueries';
+
+describe('saved workflow detail query policy', () => {
+ it('recognizes only detail query keys with a workflow id', () => {
+ expect(isSavedWorkflowDetailQueryKey(['workflow', 'call-saved', 'detail', 'workflow-1'])).toBe(true);
+ expect(isSavedWorkflowDetailQueryKey(['workflow', 'call-saved', 'picker', 'workflow-1'])).toBe(false);
+ expect(isSavedWorkflowDetailQueryKey(['workflow', 'call-saved', 'detail'])).toBe(false);
+ });
+
+ it('fetches missing or invalidated detail queries but never retries an error from cache notifications', () => {
+ expect(shouldFetchSavedWorkflowDetail(undefined)).toBe(true);
+ expect(
+ shouldFetchSavedWorkflowDetail({ state: { fetchStatus: 'idle', isInvalidated: true, status: 'success' } })
+ ).toBe(true);
+ expect(
+ shouldFetchSavedWorkflowDetail({ state: { fetchStatus: 'idle', isInvalidated: false, status: 'success' } })
+ ).toBe(false);
+ expect(
+ shouldFetchSavedWorkflowDetail({ state: { fetchStatus: 'fetching', isInvalidated: true, status: 'pending' } })
+ ).toBe(false);
+ expect(
+ shouldFetchSavedWorkflowDetail({ state: { fetchStatus: 'idle', isInvalidated: true, status: 'error' } })
+ ).toBe(false);
+ });
+
+ it('classifies detail query state for reconciliation', () => {
+ expect(getSavedWorkflowDetailQueryStatus(undefined)).toBe('missing');
+ expect(
+ getSavedWorkflowDetailQueryStatus({ state: { fetchStatus: 'fetching', isInvalidated: false, status: 'pending' } })
+ ).toBe('loading');
+ expect(
+ getSavedWorkflowDetailQueryStatus({ state: { fetchStatus: 'idle', isInvalidated: false, status: 'error' } })
+ ).toBe('error');
+ expect(
+ getSavedWorkflowDetailQueryStatus({
+ state: { data: { workflow_id: 'workflow-1' }, fetchStatus: 'idle', isInvalidated: false, status: 'success' },
+ })
+ ).toBe('ready');
+ });
+
+ it('does not retry a failed detail lookup', () => {
+ expect(savedWorkflowDetailQueryOptions('workflow-1').retry).toBe(false);
+ });
+});
diff --git a/invokeai/frontend/webv2/src/features/workflow/data/savedWorkflowQueries.ts b/invokeai/frontend/webv2/src/features/workflow/data/savedWorkflowQueries.ts
index fc8fc019b7..c79071d8d5 100644
--- a/invokeai/frontend/webv2/src/features/workflow/data/savedWorkflowQueries.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/data/savedWorkflowQueries.ts
@@ -8,10 +8,54 @@ import {
type WorkflowRecordDTO,
} from './api';
+export const savedWorkflowDetailQueryKey = (workflowId: string) =>
+ ['workflow', 'call-saved', 'detail', workflowId] as const;
+
+export const isSavedWorkflowDetailQueryKey = (
+ queryKey: readonly unknown[]
+): queryKey is readonly ['workflow', 'call-saved', 'detail', string] =>
+ queryKey[0] === 'workflow' &&
+ queryKey[1] === 'call-saved' &&
+ queryKey[2] === 'detail' &&
+ typeof queryKey[3] === 'string' &&
+ queryKey[3].length > 0;
+
+type SavedWorkflowDetailQueryLike = {
+ state: {
+ data?: unknown;
+ fetchStatus: 'fetching' | 'paused' | 'idle';
+ isInvalidated: boolean;
+ status: 'pending' | 'error' | 'success';
+ };
+};
+
+export const shouldFetchSavedWorkflowDetail = (query: SavedWorkflowDetailQueryLike | undefined): boolean =>
+ query === undefined ||
+ (query.state.status === 'success' && query.state.isInvalidated && query.state.fetchStatus === 'idle');
+
+export const getSavedWorkflowDetailQueryStatus = (
+ query: SavedWorkflowDetailQueryLike | undefined
+): 'missing' | 'loading' | 'ready' | 'error' => {
+ if (!query) {
+ return 'missing';
+ }
+
+ if (query.state.status === 'error') {
+ return 'error';
+ }
+
+ if (query.state.status !== 'success' || query.state.fetchStatus !== 'idle') {
+ return 'loading';
+ }
+
+ return query.state.data ? 'ready' : 'error';
+};
+
export const savedWorkflowDetailQueryOptions = (workflowId: string) => ({
- queryKey: ['workflow', 'call-saved', 'detail', workflowId] as const,
+ queryKey: savedWorkflowDetailQueryKey(workflowId),
queryFn: ({ signal }: { signal: AbortSignal }): Promise<WorkflowRecordDTO> =>
getLibraryWorkflowRecord(workflowId, signal),
+ retry: false,
staleTime: 30_000,
});
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/WorkflowDialogHost.browser.test.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/WorkflowDialogHost.browser.test.tsx
index d28eaf600f..59a31f3388 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/WorkflowDialogHost.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/WorkflowDialogHost.browser.test.tsx
@@ -1,6 +1,7 @@
import { ChakraProvider } from '@chakra-ui/react';
import { createProjectGraph } from '@features/workflow/utility';
import { accountLifecycle } from '@platform/state/accountLifecycle';
+import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { system } from '@theme/system';
import { act, Profiler, StrictMode } from 'react';
import { createRoot, type Root } from 'react-dom/client';
@@ -77,16 +78,19 @@ const createMutablePort = <Snapshot,>(initialSnapshot: Snapshot) => {
describe('WorkflowDialogHost library autosave under StrictMode', () => {
let host: HTMLDivElement;
let root: Root;
+ let queryClient: QueryClient;
beforeEach(() => {
host = document.createElement('div');
document.body.append(host);
+ queryClient = new QueryClient();
updateLibraryWorkflowMock.mockReset();
updateLibraryWorkflowMock.mockResolvedValue(undefined);
});
afterEach(async () => {
await act(() => root.unmount());
+ queryClient.clear();
host.remove();
});
@@ -124,9 +128,11 @@ describe('WorkflowDialogHost library autosave under StrictMode', () => {
root.render(
<StrictMode>
<ChakraProvider value={system}>
- <WorkflowUiProvider adapter={adapter}>
- <WorkflowDialogHost />
- </WorkflowUiProvider>
+ <QueryClientProvider client={queryClient}>
+ <WorkflowUiProvider adapter={adapter}>
+ <WorkflowDialogHost />
+ </WorkflowUiProvider>
+ </QueryClientProvider>
</ChakraProvider>
</StrictMode>
);
@@ -220,11 +226,13 @@ describe('WorkflowDialogHost library autosave under StrictMode', () => {
root.render(
<StrictMode>
<ChakraProvider value={system}>
- <WorkflowUiProvider adapter={adapter}>
- <Profiler id="dialog-host" onRender={countRender}>
- <WorkflowDialogHost />
- </Profiler>
- </WorkflowUiProvider>
+ <QueryClientProvider client={queryClient}>
+ <WorkflowUiProvider adapter={adapter}>
+ <Profiler id="dialog-host" onRender={countRender}>
+ <WorkflowDialogHost />
+ </Profiler>
+ </WorkflowUiProvider>
+ </QueryClientProvider>
</ChakraProvider>
</StrictMode>
);
@@ -297,9 +305,11 @@ describe('WorkflowDialogHost library autosave under StrictMode', () => {
root.render(
<StrictMode>
<ChakraProvider value={system}>
- <WorkflowUiProvider adapter={adapter}>
- <WorkflowDialogHost />
- </WorkflowUiProvider>
+ <QueryClientProvider client={queryClient}>
+ <WorkflowUiProvider adapter={adapter}>
+ <WorkflowDialogHost />
+ </WorkflowUiProvider>
+ </QueryClientProvider>
</ChakraProvider>
</StrictMode>
);
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/WorkflowWidgetChrome.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/WorkflowWidgetChrome.tsx
index db929947cf..70ae63ca38 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/WorkflowWidgetChrome.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/WorkflowWidgetChrome.tsx
@@ -34,6 +34,7 @@ import { useTranslation } from 'react-i18next';
import type { WorkflowWidgetLabelProps, WorkflowWidgetViewProps } from './contracts';
import { AddNodeDialog } from './editor/AddNodeDialog';
+import { CallSavedWorkflowSyncRuntime } from './editor/CallSavedWorkflowSyncRuntime';
import { getWorkflowFlowInstance } from './editor/flowInstanceStore';
import { createLibraryAutosaver, type LibrarySyncStatus } from './library/libraryAutosave';
import { registerLibraryGraphSyncedHandler, releaseLibraryGraphSyncedHandler } from './library/librarySyncBridge';
@@ -521,6 +522,7 @@ export const WorkflowDialogHost = () => {
return (
<>
+ <CallSavedWorkflowSyncRuntime />
<input ref={fileInputRef} accept=".json,application/json" hidden type="file" onChange={handleImportFile} />
<AddNodeDialog
connectionFilter={addNodeConnection}
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.tsx
index e5afe49bbd..9e1cd65b5f 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.tsx
@@ -1,8 +1,14 @@
import type { WorkflowRecordDTO } from '@features/workflow/data/api';
-import { savedWorkflowDetailQueryOptions } from '@features/workflow/data/savedWorkflowQueries';
+import { onWorkflowLibraryCacheInvalidated } from '@features/workflow/data/libraryCache';
+import {
+ getSavedWorkflowDetailQueryStatus,
+ isSavedWorkflowDetailQueryKey,
+ savedWorkflowDetailQueryOptions,
+ shouldFetchSavedWorkflowDetail,
+} from '@features/workflow/data/savedWorkflowQueries';
import { getInvocationTemplatesSnapshot, subscribeInvocationTemplates } from '@features/workflow/data/templates';
-import { useWorkflowProjectSelector, useWorkflowUi } from '@features/workflow/ui/WorkflowUiContext';
+import { useWorkflowUi } from '@features/workflow/ui/WorkflowUiContext';
import {
CALL_SAVED_WORKFLOW_DYNAMIC_FIELD_PREFIX,
getSavedWorkflowDynamicEdgeIdsToRemove,
@@ -12,7 +18,6 @@ import {
} from '@features/workflow/utility';
import { useMountEffect } from '@platform/react/useMountEffect';
import { useQueryClient } from '@tanstack/react-query';
-import { useEffectEvent } from 'react';
export const createDeferredCallSavedWorkflowReconciler = (reconcile: () => void) => {
let timer: ReturnType<typeof setTimeout> | null = null;
@@ -86,8 +91,9 @@ const needsDynamicFieldSync = (
!currentInstance ||
!hasSameFieldType(currentTemplate, field.fieldTemplate) ||
JSON.stringify(currentTemplate) !== JSON.stringify(field.fieldTemplate) ||
- currentInstance.label !== field.label ||
- (currentInstance.description ?? '') !== field.description
+ (currentInstance.label === currentTemplate.title && currentInstance.label !== field.label) ||
+ ((currentInstance.description ?? '') === currentTemplate.description &&
+ (currentInstance.description ?? '') !== field.description)
);
})
) {
@@ -100,16 +106,28 @@ const needsDynamicFieldSync = (
/** Reconciles asynchronously loaded child workflow forms into the project document. */
export const CallSavedWorkflowSyncRuntime = () => {
const queryClient = useQueryClient();
- const projectGraph = useWorkflowProjectSelector((snapshot) => snapshot.projectGraph);
const { commands, project: projectPort } = useWorkflowUi();
- const reconcile = useEffectEvent(() => {
+ const reconcile = () => {
const templatesSnapshot = getInvocationTemplatesSnapshot();
if (templatesSnapshot.status !== 'loaded') {
return;
}
- const document = projectGraph;
+ const document = projectPort.getSnapshot().projectGraph;
+ const setStatus = (nodeId: string, workflowId: string, status: 'loading' | 'ready' | 'error') => {
+ const currentDocument = projectPort.getSnapshot().projectGraph;
+ const currentNode = currentDocument.nodes.find((candidate) => candidate.id === nodeId);
+
+ if (
+ currentNode?.type === 'invocation' &&
+ currentNode.data.type === 'call_saved_workflow' &&
+ currentNode.data.inputs.workflow_id?.value === workflowId &&
+ currentNode.data.callSavedWorkflowStatus !== status
+ ) {
+ commands.editGraph({ nodeId, status, type: 'setCallSavedWorkflowStatus' });
+ }
+ };
for (const node of document.nodes) {
if (node.type !== 'invocation' || node.data.type !== 'call_saved_workflow') {
@@ -124,30 +142,59 @@ export const CallSavedWorkflowSyncRuntime = () => {
Object.keys(node.data.dynamicInputTemplates ?? {}).length > 0 ||
Object.keys(node.data.inputs).some((name) => name.startsWith(CALL_SAVED_WORKFLOW_DYNAMIC_FIELD_PREFIX));
- if (hasDynamicFields) {
- commands.editGraph({ edgeIdsToRemove: [], fields: [], nodeId: node.id, type: 'syncCallSavedWorkflowFields' });
+ if (hasDynamicFields || node.data.callSavedWorkflowStatus !== 'ready') {
+ commands.editGraph({
+ edgeIdsToRemove: [],
+ fields: [],
+ nodeId: node.id,
+ status: 'ready',
+ type: 'syncCallSavedWorkflowFields',
+ });
}
continue;
}
const detailOptions = savedWorkflowDetailQueryOptions(workflowId);
- const record = queryClient.getQueryData<WorkflowRecordDTO>(detailOptions.queryKey);
+ const query = queryClient.getQueryCache().find({ queryKey: detailOptions.queryKey });
- if (!record) {
- void queryClient.ensureQueryData(detailOptions).catch(() => undefined);
+ if (shouldFetchSavedWorkflowDetail(query)) {
+ setStatus(node.id, workflowId, 'loading');
+ void queryClient.ensureQueryData({ ...detailOptions, revalidateIfStale: true }).catch(() => {
+ setStatus(node.id, workflowId, 'error');
+ });
+ continue;
+ }
+
+ const queryStatus = getSavedWorkflowDetailQueryStatus(query);
+
+ if (queryStatus === 'loading') {
+ setStatus(node.id, workflowId, 'loading');
+ continue;
+ }
+
+ if (queryStatus === 'error') {
+ setStatus(node.id, workflowId, 'error');
+ continue;
+ }
+
+ const record = query?.state.data as WorkflowRecordDTO | undefined;
+ const selectedWorkflow = record ? getSelectedSavedWorkflow(workflowId, record) : undefined;
+
+ if (!selectedWorkflow || selectedWorkflow.call_saved_workflow_compatibility?.is_callable === false) {
+ setStatus(node.id, workflowId, 'error');
continue;
}
- const selectedWorkflow = getSelectedSavedWorkflow(workflowId, record);
let childDocument;
try {
- childDocument = selectedWorkflow ? parseWorkflowJson(selectedWorkflow.workflow).document : undefined;
+ childDocument = parseWorkflowJson(selectedWorkflow.workflow).document;
} catch {
childDocument = undefined;
}
if (!childDocument) {
+ setStatus(node.id, workflowId, 'error');
continue;
}
@@ -159,11 +206,20 @@ export const CallSavedWorkflowSyncRuntime = () => {
templatesSnapshot.templates
);
- if (needsDynamicFieldSync(node, fields, edgeIdsToRemove, document.edges)) {
- commands.editGraph({ edgeIdsToRemove, fields, nodeId: node.id, type: 'syncCallSavedWorkflowFields' });
+ if (
+ node.data.callSavedWorkflowStatus !== 'ready' ||
+ needsDynamicFieldSync(node, fields, edgeIdsToRemove, document.edges)
+ ) {
+ commands.editGraph({
+ edgeIdsToRemove,
+ fields,
+ nodeId: node.id,
+ status: 'ready',
+ type: 'syncCallSavedWorkflowFields',
+ });
}
}
- });
+ };
/* eslint-disable react-hooks/rules-of-hooks -- useMountEffect is the repository's explicit useEffect wrapper */
useMountEffect(() => {
@@ -172,13 +228,22 @@ export const CallSavedWorkflowSyncRuntime = () => {
const unsubscribeProject = projectPort.subscribe(reconciler.schedule);
const unsubscribeTemplates = subscribeInvocationTemplates(reconciler.schedule);
- const unsubscribeQueries = queryClient.getQueryCache().subscribe(reconciler.schedule);
+ const unsubscribeQueries = queryClient.getQueryCache().subscribe((event) => {
+ if (isSavedWorkflowDetailQueryKey(event.query.queryKey)) {
+ reconciler.schedule();
+ }
+ });
+ const unsubscribeLibrary = onWorkflowLibraryCacheInvalidated(() => {
+ void queryClient.invalidateQueries({ queryKey: ['workflow', 'call-saved', 'detail'] });
+ reconciler.schedule();
+ });
return () => {
reconciler.dispose();
unsubscribeProject();
unsubscribeTemplates();
unsubscribeQueries();
+ unsubscribeLibrary();
};
});
/* eslint-enable react-hooks/rules-of-hooks */
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/editor/InvocationFlowNode.test.ts b/invokeai/frontend/webv2/src/features/workflow/ui/editor/InvocationFlowNode.test.ts
new file mode 100644
index 0000000000..50463dafa8
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/editor/InvocationFlowNode.test.ts
@@ -0,0 +1,18 @@
+import type { WorkflowInvocationNode } from '@features/workflow/contracts';
+
+import { describe, expect, it } from 'vitest';
+
+import { shouldShowCallSavedWorkflowLoadingHint } from './InvocationFlowNode';
+
+const node = (type: string, status?: WorkflowInvocationNode['data']['callSavedWorkflowStatus']) =>
+ ({ data: { type, callSavedWorkflowStatus: status } }) as WorkflowInvocationNode;
+
+describe('shouldShowCallSavedWorkflowLoadingHint', () => {
+ it('shows the hint only while a selected child workflow is loading', () => {
+ expect(shouldShowCallSavedWorkflowLoadingHint(node('call_saved_workflow', 'loading'))).toBe(true);
+ expect(shouldShowCallSavedWorkflowLoadingHint(node('call_saved_workflow', 'ready'))).toBe(false);
+ expect(shouldShowCallSavedWorkflowLoadingHint(node('call_saved_workflow', 'error'))).toBe(false);
+ expect(shouldShowCallSavedWorkflowLoadingHint(node('call_saved_workflow'))).toBe(false);
+ expect(shouldShowCallSavedWorkflowLoadingHint(node('other', 'loading'))).toBe(false);
+ });
+});
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/editor/InvocationFlowNode.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/editor/InvocationFlowNode.tsx
index 5eb13baddb..58de4fa580 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/editor/InvocationFlowNode.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/editor/InvocationFlowNode.tsx
@@ -19,7 +19,6 @@ import {
import { useProjectGraphCommands } from '@features/workflow/ui/useProjectGraphCommands';
import { useWorkflowNodeExecutionState } from '@features/workflow/ui/WorkflowUiContext';
import {
- CALL_SAVED_WORKFLOW_DYNAMIC_FIELD_PREFIX,
cloneWorkflowFieldDefault,
formatOutputFieldValue,
getFieldTypeLabel,
@@ -50,6 +49,10 @@ const CONTENT_VISIBILITY_ZOOM = 0.4;
/** True while the viewport is zoomed out far enough that field content is unreadable noise. */
const useIsZoomedOut = (): boolean => useStore((state) => state.transform[2] < CONTENT_VISIBILITY_ZOOM);
+/** The node-level loading hint is only useful while a selected child signature is being fetched. */
+export const shouldShowCallSavedWorkflowLoadingHint = (node: WorkflowInvocationNode): boolean =>
+ node.data.type === 'call_saved_workflow' && node.data.callSavedWorkflowStatus === 'loading';
+
/** Static placeholder bar standing in for text/controls at far zoom. No animation — there may be hundreds. */
const SkeletonBar = ({ h = '2', w }: { h?: string; w?: string }) => <Box bg="bg.emphasized" h={h} rounded="sm" w={w} />;
@@ -772,12 +775,9 @@ const ExpandedInvocationNode = ({ data, selected }: NodeProps<InvocationFlowNode
template={inputTemplate}
/>
))}
- {node.data.type === 'call_saved_workflow' &&
- inputTemplates.every(
- (inputTemplate) => !inputTemplate.name.startsWith(CALL_SAVED_WORKFLOW_DYNAMIC_FIELD_PREFIX)
- ) ? (
+ {shouldShowCallSavedWorkflowLoadingHint(node) ? (
<Text color="fg.subtle" fontSize="2xs" px={WORKFLOW_NODE_DENSITY.rowPaddingX} py="1">
- {t('nodes.savedWorkflowSelectExposedFields')}
+ {t('nodes.savedWorkflowUpdating')}
</Text>
) : null}
</Box>
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/editor/WorkflowEditorView.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/editor/WorkflowEditorView.tsx
index 29105474a1..7fe3b8d728 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/editor/WorkflowEditorView.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/editor/WorkflowEditorView.tsx
@@ -57,7 +57,6 @@ import {
type MouseEvent as ReactMouseEvent,
} from 'react';
-import { CallSavedWorkflowSyncRuntime } from './CallSavedWorkflowSyncRuntime';
import { buildDuplicateElements, buildPasteElements, copyNodesToClipboard, useHasClipboardNodes } from './clipboard';
import { ConnectorFlowNode } from './ConnectorFlowNode';
import { CurrentImageFlowNode } from './CurrentImageFlowNode';
@@ -1215,7 +1214,6 @@ export const WorkflowEditorView = ({ runtime }: { runtime: WorkflowRuntimeApi })
return (
<ReactFlowProvider>
- <CallSavedWorkflowSyncRuntime />
<Flex direction="column" h="full" minH="0" w="full">
<Box flex="1" minH="0" position="relative">
<WorkflowFlow key={flowIdentity} runtime={runtime} />
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.browser.test.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.browser.test.tsx
index c338749300..e487356669 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.browser.test.tsx
@@ -417,12 +417,14 @@ describe('WorkflowFieldInput saved workflows', () => {
});
describe('WorkflowFieldInput media inputs', () => {
- it('still renders media controls when the host does not provide a dnd context', async () => {
+ it('renders media controls when the host provides the workflow dnd context', async () => {
await act(() => {
root.render(
<ChakraProvider value={system}>
<QueryClientProvider client={queryClient}>
- <WorkflowFieldInput template={VIDEO_TEMPLATE} value={undefined} onChange={vi.fn()} />
+ <DndContext>
+ <WorkflowFieldInput template={VIDEO_TEMPLATE} value={undefined} onChange={vi.fn()} />
+ </DndContext>
</QueryClientProvider>
</ChakraProvider>
);
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.tsx
index 86c1fa7bf7..ebb44f04a0 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.tsx
@@ -94,7 +94,6 @@ import { FilmIcon, ImageIcon, ImagePlusIcon, Trash2Icon, XIcon } from 'lucide-re
import {
lazy,
Suspense,
- Component,
useCallback,
useDeferredValue,
useEffect,
@@ -104,7 +103,6 @@ import {
useState,
type ChangeEvent,
type MouseEvent,
- type ReactNode,
} from 'react';
import { useTranslation } from 'react-i18next';
@@ -557,28 +555,6 @@ const MEDIA_FIELD_CONFIG = {
>;
const HIDDEN_FILE_INPUT_STYLE = { display: 'none' } as const;
-const DND_CONTEXT_ERROR = 'useDndMonitor must be used within a children of <DndContext>';
-
-/**
- * Workflow fields are also rendered by isolated workflow surfaces and tests
- * that do not own the workbench-wide dnd context. The media controls still
- * work there; only gallery drag-to-field registration is unavailable.
- */
-class OptionalDndMonitorBoundary extends Component<{ children: ReactNode }, { failed: boolean }> {
- state = { failed: false };
-
- static getDerivedStateFromError(error: unknown) {
- if (error instanceof Error && error.message === DND_CONTEXT_ERROR) {
- return { failed: true };
- }
-
- throw error;
- }
-
- render() {
- return this.state.failed ? null : this.props.children;
- }
-}
const IMAGE_ONLY = ['image'] as const;
const VIDEO_ONLY = ['video'] as const;
const MEDIA_INPUT_FOCUS_PROPS = { outline: '2px solid {colors.accent.focusRing}', outlineOffset: '2px' } as const;
@@ -855,9 +831,7 @@ const ImageCollectionInput = ({ id, invalid, nodeId, onChange, template, value }
return (
<Box position="relative" w="full" {...invalidAriaProps}>
- <OptionalDndMonitorBoundary>
- <ImageCollectionDropMonitor dropId={dropId} onDrop={appendNames} />
- </OptionalDndMonitorBoundary>
+ <ImageCollectionDropMonitor dropId={dropId} onDrop={appendNames} />
<Box
ref={setNodeRef}
boxShadow={invalid ? '0 0 0 1px {colors.red.solid}' : undefined}
@@ -1019,9 +993,7 @@ const MediaInput = ({ id, invalid, kind, onChange, value }: WorkflowFieldInputPr
return (
<Box position="relative" w="full" {...invalidAriaProps}>
- <OptionalDndMonitorBoundary>
- <MediaDropMonitor dropId={dropId} kind={kind} onDrop={onMediaDrop} />
- </OptionalDndMonitorBoundary>
+ <MediaDropMonitor dropId={dropId} kind={kind} onDrop={onMediaDrop} />
{/* The whole preview area is the drop target, like the legacy editor's widget. */}
<Box
ref={setNodeRef}
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/linear/FormBuilderTab.test.ts b/invokeai/frontend/webv2/src/features/workflow/ui/linear/FormBuilderTab.test.ts
new file mode 100644
index 0000000000..fb0eb3a2d6
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/linear/FormBuilderTab.test.ts
@@ -0,0 +1,77 @@
+import type { FieldInputTemplate, InvocationTemplate } from '@features/workflow/contracts';
+
+import { buildInvocationNode, createProjectGraph } from '@features/workflow/utility';
+import { describe, expect, it } from 'vitest';
+
+import { getInvalidNodeFieldElementIds } from './FormBuilderTab';
+
+const dynamicInput: FieldInputTemplate = {
+ default: '',
+ description: 'Dynamic input',
+ exclusiveMaximum: null,
+ exclusiveMinimum: null,
+ fieldKind: 'input',
+ input: 'any',
+ maximum: null,
+ minimum: null,
+ multipleOf: null,
+ name: 'dynamic_input',
+ options: null,
+ required: true,
+ title: 'Dynamic input',
+ type: { batch: false, cardinality: 'SINGLE', name: 'StringField' },
+ uiChoiceLabels: null,
+ uiComponent: null,
+ uiHidden: false,
+ uiModelBase: null,
+ uiModelFormat: null,
+ uiModelType: null,
+ uiOrder: null,
+};
+
+const callSavedWorkflowTemplate: InvocationTemplate = {
+ category: 'workflow',
+ classification: 'stable',
+ description: '',
+ inputs: {},
+ nodePack: 'invokeai',
+ outputs: {},
+ outputType: 'call_saved_workflow_output',
+ tags: [],
+ title: 'Call Saved Workflow',
+ type: 'call_saved_workflow',
+ useCache: true,
+ version: '1.0.0',
+};
+
+describe('getInvalidNodeFieldElementIds', () => {
+ it('validates a form field through its persisted dynamic input template', () => {
+ const node = buildInvocationNode(callSavedWorkflowTemplate, { x: 0, y: 0 });
+ node.id = 'call';
+ node.data.dynamicInputTemplates = { dynamic_input: dynamicInput };
+ node.data.inputs.dynamic_input = { label: 'Dynamic input', name: 'dynamic_input', value: 'ready' };
+ const document = createProjectGraph('form-builder-dynamic-input');
+ document.nodes = [node];
+ const root = document.form.elements[document.form.rootElementId];
+
+ if (root?.type !== 'container') {
+ throw new Error('Expected a form root container.');
+ }
+
+ root.data.children.push('dynamic-field');
+ document.form.elements['dynamic-field'] = {
+ data: {
+ fieldIdentifier: { fieldName: 'dynamic_input', nodeId: node.id },
+ showDescription: false,
+ showShuffle: false,
+ },
+ id: 'dynamic-field',
+ parentId: root.id,
+ type: 'node-field',
+ };
+
+ expect(
+ getInvalidNodeFieldElementIds(document, 'loaded', { call_saved_workflow: callSavedWorkflowTemplate })
+ ).toEqual(new Set());
+ });
+});
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/linear/FormBuilderTab.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/linear/FormBuilderTab.tsx
index 9055861378..d7ad611ddc 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/linear/FormBuilderTab.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/linear/FormBuilderTab.tsx
@@ -566,7 +566,7 @@ const AddElementMenu = () => {
);
};
-const getInvalidNodeFieldElementIds = (
+export const getInvalidNodeFieldElementIds = (
projectGraph: ProjectGraphState,
templatesStatus: InvocationTemplatesSnapshot['status'],
templates: InvocationTemplates
@@ -596,7 +596,7 @@ const getInvalidNodeFieldElementIds = (
continue;
}
- const template = templates[node.data.type]?.inputs[fieldName];
+ const template = node.data.dynamicInputTemplates?.[fieldName] ?? templates[node.data.type]?.inputs[fieldName];
if (!template) {
invalidElementIds.add(element.id);
diff --git a/invokeai/frontend/webv2/src/platform/ui/Combobox.browser.test.tsx b/invokeai/frontend/webv2/src/platform/ui/Combobox.browser.test.tsx
index fe65c58c08..c0e42f1942 100644
--- a/invokeai/frontend/webv2/src/platform/ui/Combobox.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/platform/ui/Combobox.browser.test.tsx
@@ -1,4 +1,4 @@
-/* oxlint-disable react-perf/jsx-no-new-function-as-prop */
+/* oxlint-disable react-perf/jsx-no-new-array-as-prop, react-perf/jsx-no-new-function-as-prop */
import { ChakraProvider } from '@chakra-ui/react';
import { system } from '@theme/system';
import { createInstance } from 'i18next';
@@ -45,15 +45,28 @@ const interact = (action: () => void): Promise<void> =>
});
});
-const Harness = ({ disabled = false, onChange }: { disabled?: boolean; onChange: (value: string) => void }) => {
+const Harness = ({
+ disabled = false,
+ filterOptions = false,
+ onChange,
+}: {
+ disabled?: boolean;
+ filterOptions?: boolean;
+ onChange: (value: string) => void;
+}) => {
const [value, setValue] = useState('euler_a');
+ const [search, setSearch] = useState('');
+ const visibleOptions = filterOptions
+ ? options.filter((option) => option.label.toLocaleLowerCase().includes(search.toLocaleLowerCase()))
+ : options;
return (
<Combobox
aria-label="Scheduler"
disabled={disabled}
- options={options}
+ options={visibleOptions}
value={value}
+ onInputValueChange={filterOptions ? setSearch : undefined}
onValueChange={(nextValue) => {
setValue(nextValue);
onChange(nextValue);
@@ -62,7 +75,7 @@ const Harness = ({ disabled = false, onChange }: { disabled?: boolean; onChange:
);
};
-const renderCombobox = async (disabled = false) => {
+const renderCombobox = async (disabled = false, filterOptions = false) => {
host = document.createElement('div');
document.body.append(host);
root = createRoot(host);
@@ -72,7 +85,7 @@ const renderCombobox = async (disabled = false) => {
root?.render(
<I18nextProvider i18n={i18n}>
<ChakraProvider value={system}>
- <Harness disabled={disabled} onChange={onChange} />
+ <Harness disabled={disabled} filterOptions={filterOptions} onChange={onChange} />
</ChakraProvider>
</I18nextProvider>
);
@@ -134,6 +147,23 @@ describe('Combobox', () => {
expect(input.value).toBe('Euler Ancestral');
});
+ it('clears the controlled search query when reopened', async () => {
+ const { input } = await renderCombobox(false, true);
+
+ await interact(() => input.click());
+ await setInputValue(input, 'DPM');
+ expect(document.querySelectorAll('[role="option"]')).toHaveLength(1);
+
+ await interact(() => {
+ input.dispatchEvent(new KeyboardEvent('keydown', { bubbles: true, key: 'Escape' }));
+ });
+ expect(input.getAttribute('aria-expanded')).toBe('false');
+ await interact(() => input.click());
+
+ expect(input.value).toBe('');
+ expect(document.querySelectorAll('[role="option"]')).toHaveLength(options.length);
+ });
+
it('honors the disabled state', async () => {
const { input } = await renderCombobox(true);
diff --git a/invokeai/frontend/webv2/src/platform/ui/Combobox.tsx b/invokeai/frontend/webv2/src/platform/ui/Combobox.tsx
index 3567bd8ed3..f517ff08b5 100644
--- a/invokeai/frontend/webv2/src/platform/ui/Combobox.tsx
+++ b/invokeai/frontend/webv2/src/platform/ui/Combobox.tsx
@@ -85,10 +85,17 @@ export const Combobox = ({
}),
[filteredOptions]
);
- const handleOpenChange = useCallback((details: { open: boolean }) => {
- setIsOpen(details.open);
- setQuery('');
- }, []);
+ const handleOpenChange = useCallback(
+ (details: { open: boolean }) => {
+ setIsOpen(details.open);
+ setQuery('');
+
+ if (!details.open) {
+ onInputValueChange?.('');
+ }
+ },
+ [onInputValueChange]
+ );
const handleInputValueChange = useCallback(
(details: { inputValue: string; reason?: string }) => {
if (details.reason === 'input-change' || details.reason === 'clear-trigger') {
diff --git a/invokeai/frontend/webv2/src/workbench/autoRoutePolicy.ts b/invokeai/frontend/webv2/src/workbench/autoRoutePolicy.ts
index 03554bf576..56588ce3c0 100644
--- a/invokeai/frontend/webv2/src/workbench/autoRoutePolicy.ts
+++ b/invokeai/frontend/webv2/src/workbench/autoRoutePolicy.ts
@@ -105,6 +105,7 @@ const GRAPH_EDIT_CONFIDENCE = {
setNodeNotes: false,
setNodePosition: false,
setNodeUseCache: false,
+ setCallSavedWorkflowStatus: false,
syncCallSavedWorkflowFields: false,
unexposeField: false,
} satisfies Record<ProjectGraphAction['type'], boolean>;