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): unblock Invoke when a capabilities retry succeeds

Alexander Eichhorn9c4fa637eb4b
diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/useInvocationState.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/shell/topbar/useInvocationState.browser.test.tsx
index 0d13f9c8df..d1769e1d42 100644
--- a/invokeai/frontend/webv2/src/workbench/shell/topbar/useInvocationState.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/useInvocationState.browser.test.tsx
@@ -19,7 +19,9 @@ vi.mock('@features/generation/react', () => ({
}));
vi.mock('@features/models', () => ({
ensureModelsLoaded: () => Promise.resolve(),
- useModelsSelector: (selector: (snapshot: unknown) => unknown) => selector({ models: [sdxlModel], status: 'loaded' }),
+ // One snapshot object, as the real store hands out. A fresh `models` array per render would change
+ // an input React Compiler memoises the route on, and re-resolve it by accident.
+ useModelsSelector: (selector: (snapshot: unknown) => unknown) => selector(modelsSnapshot),
}));
vi.mock('@workbench/activeInvocationSubmission', () => ({ submitActiveInvocation: () => Promise.resolve() }));
vi.mock('@workbench/canvasInvocationPreparation', () => ({ useIsCanvasInvocationPreparing: () => false }));
@@ -37,6 +39,7 @@ import { createInitialWorkbenchState, workbenchReducer } from '@workbench/workbe
import { useInvocationState } from './useInvocationState';
const sdxlModel: MainModelConfig = { base: 'sdxl', key: 'sdxl-model', name: 'SDXL', type: 'main' };
+const modelsSnapshot = { models: [sdxlModel], status: 'loaded' };
const buildProject = (): Project => {
// The table is needed to derive a *valid* saved project; the point of the test is what happens
diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/useInvocationState.ts b/invokeai/frontend/webv2/src/workbench/shell/topbar/useInvocationState.ts
index 5a3f2ddd71..2ee13358aa 100644
--- a/invokeai/frontend/webv2/src/workbench/shell/topbar/useInvocationState.ts
+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/useInvocationState.ts
@@ -1,5 +1,4 @@
import type { DynamicPromptsExpansion } from '@features/generation/react';
-import type { ArchitectureCapabilitiesSnapshot } from '@features/generation/runtime';
import type { GraphWidgetSource } from '@workbench/graphWidgets';
import type { InvocationRoute, ResultDestination } from '@workbench/invocationContracts';
import type { WidgetTypeId } from '@workbench/widgetContracts';
@@ -35,7 +34,6 @@ import { useCallback, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
const selectInvocationRouteInput = createInvocationRouteInputSelector();
-const selectCapabilitiesRevision = (snapshot: ArchitectureCapabilitiesSnapshot): number => snapshot.revision;
const areTypeIdSetsEqual = (left: ReadonlySet<WidgetTypeId>, right: ReadonlySet<WidgetTypeId>): boolean =>
left.size === right.size && [...left].every((typeId) => right.has(typeId));
@@ -87,19 +85,23 @@ export const useInvocationState = (): InvocationState => {
// Project-graph route validation reads the invocation templates imperatively;
// subscribing here keeps the resolved route live while they load.
useInvocationTemplatesSelector((snapshot) => snapshot.status);
- // Same shape, for the architecture capability table: `getGenerationValidationReasons` fails closed
- // while it is absent, so a load that only succeeds on retry has to reach Invoke on its own rather
- // than waiting for the next unrelated edit to re-render this hook.
- useExternalStoreSelector(
- subscribeArchitectureCapabilities,
- getArchitectureCapabilitiesSnapshot,
- selectCapabilitiesRevision
- );
useMountEffect(() => {
void ensureModelsLoaded();
});
- const resolvedRoute = resolveInvocationRouteInput(routeInput, 'global', invocation, availabilityModels);
+ // `getGenerationValidationReasons` fails closed while the capability table is absent, so a load
+ // that only succeeds on retry has to reach Invoke on its own. The route is resolved inside the
+ // store's selector, like `useModelGridSize`: the table is core module state, so to React Compiler a
+ // bare call is a pure function of these arguments and stays memoised -- Invoke would remain blocked
+ // until an unrelated edit changed one of them.
+ const resolvedRoute = useExternalStoreSelector(
+ subscribeArchitectureCapabilities,
+ getArchitectureCapabilitiesSnapshot,
+ useCallback(
+ () => resolveInvocationRouteInput(routeInput, 'global', invocation, availabilityModels),
+ [availabilityModels, invocation, routeInput]
+ )
+ );
const isConnected = backendConnectionStatus === 'connected';
const sourceValues =
invocation.sourceId === 'upscale'