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): defer saved workflow reconciliation
JPPhotob709fcfb9be2
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.test.ts b/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.test.tsnew file mode 100644index 0000000000..5bf23d1440--- /dev/null+++ b/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.test.ts@@ -0,0 +1,38 @@+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';++import { createDeferredCallSavedWorkflowReconciler } from './CallSavedWorkflowSyncRuntime';++describe('createDeferredCallSavedWorkflowReconciler', () => {+ beforeEach(() => {+ vi.useFakeTimers();+ });++ afterEach(() => {+ vi.useRealTimers();+ });++ it('defers and coalesces synchronous notifications', () => {+ const reconcile = vi.fn();+ const scheduler = createDeferredCallSavedWorkflowReconciler(reconcile);++ scheduler.schedule();+ scheduler.schedule();++ expect(reconcile).not.toHaveBeenCalled();++ vi.runAllTimers();++ expect(reconcile).toHaveBeenCalledOnce();+ });++ it('cancels pending reconciliation on disposal', () => {+ const reconcile = vi.fn();+ const scheduler = createDeferredCallSavedWorkflowReconciler(reconcile);++ scheduler.schedule();+ scheduler.dispose();+ vi.runAllTimers();++ expect(reconcile).not.toHaveBeenCalled();+ });+});diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.tsxindex c46212ea97..e5afe49bbd 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.tsx+++ b/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.tsx@@ -14,6 +14,29 @@ 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;++ return {+ dispose: () => {+ if (timer !== null) {+ clearTimeout(timer);+ timer = null;+ }+ },+ schedule: () => {+ if (timer !== null) {+ return;+ }++ timer = setTimeout(() => {+ timer = null;+ reconcile();+ }, 0);+ },+ };+};+const hasSameFieldType = (left: unknown, right: unknown): boolean => {if (!left || !right || typeof left !== 'object' || typeof right !== 'object') {return false;@@ -144,13 +167,15 @@ export const CallSavedWorkflowSyncRuntime = () => {/* eslint-disable react-hooks/rules-of-hooks -- useMountEffect is the repository's explicit useEffect wrapper */useMountEffect(() => {- reconcile();+ const reconciler = createDeferredCallSavedWorkflowReconciler(reconcile);+ reconciler.schedule();- const unsubscribeProject = projectPort.subscribe(reconcile);- const unsubscribeTemplates = subscribeInvocationTemplates(reconcile);- const unsubscribeQueries = queryClient.getQueryCache().subscribe(reconcile);+ const unsubscribeProject = projectPort.subscribe(reconciler.schedule);+ const unsubscribeTemplates = subscribeInvocationTemplates(reconciler.schedule);+ const unsubscribeQueries = queryClient.getQueryCache().subscribe(reconciler.schedule);return () => {+ reconciler.dispose();unsubscribeProject();unsubscribeTemplates();unsubscribeQueries();