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): deduplicate duplicate-return autosave errors

JPPhoto674f725aa230
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 3b6df101a7..a3e9a61c8b 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
@@ -246,6 +246,70 @@ describe('WorkflowDialogHost library autosave under StrictMode', () => {
expect(notifications.error).toHaveBeenCalledTimes(1);
});
+ it('does not repeat the duplicate-return autosave notification for every edit', async () => {
+ const boundGraph = createGraphWithDuplicateWorkflowReturns();
+ const project = createMutablePort({
+ galleryValues: {},
+ id: 'project-1',
+ isWorkflowRunning: false,
+ projectGraph: boundGraph,
+ workflowValues: {},
+ });
+ const notifications = { error: vi.fn(), info: vi.fn(), success: vi.fn() };
+
+ // eslint-disable-next-line react-perf/jsx-no-new-object-as-prop -- intentionally stable for this render lifetime
+ const adapter = {
+ commands: {
+ bindLibraryWorkflow: vi.fn(),
+ editGraph: vi.fn(),
+ redo: vi.fn(),
+ replace: vi.fn(),
+ undo: vi.fn(),
+ },
+ getProjectGraph: () => project.port.getSnapshot().projectGraph,
+ notifications,
+ project: project.port,
+ widgets: { open: vi.fn(), patchValues: vi.fn() },
+ } as unknown as WorkflowUiAdapter;
+
+ root = createRoot(host);
+
+ await act(() => {
+ root.render(
+ <StrictMode>
+ <ChakraProvider value={system}>
+ <QueryClientProvider client={queryClient}>
+ <WorkflowUiProvider adapter={adapter}>
+ <WorkflowDialogHost />
+ </WorkflowUiProvider>
+ </QueryClientProvider>
+ </ChakraProvider>
+ </StrictMode>
+ );
+ });
+
+ const editAndWaitForAutosave = async (name: string) => {
+ await act(() => {
+ project.setSnapshot({
+ ...project.port.getSnapshot(),
+ projectGraph: { ...boundGraph, name },
+ });
+ });
+ await act(
+ () =>
+ new Promise<void>((resolve) => {
+ setTimeout(resolve, 2100);
+ })
+ );
+ };
+
+ await editAndWaitForAutosave('First invalid edit');
+ await editAndWaitForAutosave('Second invalid edit');
+
+ expect(notifications.error).toHaveBeenCalledTimes(1);
+ expect(updateLibraryWorkflowMock).not.toHaveBeenCalled();
+ });
+
/**
* The host used to learn about graph edits through a selector
* (`useWorkflowProjectSelector`) feeding a change-detecting effect, which
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/WorkflowWidgetChrome.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/WorkflowWidgetChrome.tsx
index a472f8a5a4..457096f27b 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/WorkflowWidgetChrome.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/WorkflowWidgetChrome.tsx
@@ -308,6 +308,8 @@ export const WorkflowDialogHost = () => {
// never outlives the account it was captured for.
useEffect(() => {
const hostScope = captureAccountScope();
+ let autosaverActive = true;
+ let duplicateReturnNotificationShown = false;
const autosaver = createLibraryAutosaver({
onStatus: (status) => {
if (isAccountScopeCurrent(hostScope)) {
@@ -322,13 +324,20 @@ export const WorkflowDialogHost = () => {
// Same scope discipline as the manual save paths: never let a
// debounced write land in the next account's library.
assertAccountScopeCurrent(hostScope);
- if (hasMultipleWorkflowReturnNodes(projectStore.getSnapshot().projectGraph)) {
- notifyRef.current.error(
- translationRef.current('workflowLibrary.saveFailed'),
- translationRef.current('workflowLibrary.multipleWorkflowReturnNodes')
- );
+ const hasDuplicateWorkflowReturns = hasMultipleWorkflowReturnNodes(projectStore.getSnapshot().projectGraph);
+
+ if (hasDuplicateWorkflowReturns) {
+ if (autosaverActive && !duplicateReturnNotificationShown) {
+ duplicateReturnNotificationShown = true;
+ notifyRef.current.error(
+ translationRef.current('workflowLibrary.saveFailed'),
+ translationRef.current('workflowLibrary.multipleWorkflowReturnNodes')
+ );
+ }
throw new Error('Workflow contains multiple workflow_return nodes.');
}
+
+ duplicateReturnNotificationShown = false;
await updateLibraryWorkflow(workflowId, serialized, hostScope.signal);
assertAccountScopeCurrent(hostScope);
// The library dialog serves cached payloads and pages; a save changes both.
@@ -350,6 +359,7 @@ export const WorkflowDialogHost = () => {
registerLibraryGraphSyncedHandler(handler);
return () => {
+ autosaverActive = false;
unsubscribe();
releaseLibraryGraphSyncedHandler(handler);
autosaver.dispose();