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(widgets): show a loading state on the center view's icon

joshistoaste0c1b56f24a2
diff --git a/invokeai/frontend/webv2/src/workbench/shell/CenterArea.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/shell/CenterArea.browser.test.tsx
index 5bcb9a84d1..b2ba45ac98 100644
--- a/invokeai/frontend/webv2/src/workbench/shell/CenterArea.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/shell/CenterArea.browser.test.tsx
@@ -9,6 +9,17 @@ import { afterEach, describe, expect, it, vi } from 'vitest';
const centerAreaMocks = vi.hoisted(() => {
const icon = () => null;
+ // A settled deferred resource, the shape `use()` can read without
+ // suspending — the center view's icon resolves the implementation to decide
+ // whether to show a spinner, and this fixture is always "already loaded".
+ const loadedImplementation = () => {
+ const promise: Promise<object> & { status?: string; value?: object } = Promise.resolve({});
+
+ promise.status = 'fulfilled';
+ promise.value = {};
+
+ return { getStatus: () => 'loaded', load: () => promise, preload: () => {}, retry: () => promise };
+ };
const activeItem = {
icon,
id: 'preview-instance',
@@ -17,6 +28,7 @@ const centerAreaMocks = vi.hoisted(() => {
status: 'enabled',
typeId: 'preview',
widget: {
+ implementation: loadedImplementation(),
manifest: {
centerPlacement: 'view',
chrome: { header: 'visible' },
@@ -61,6 +73,9 @@ vi.mock('@workbench/WorkbenchContext', () => ({
selector({ backendConnection: { status: 'connected' } }),
}));
vi.mock('@workbench/widget-frame', () => ({
+ // Loading state is not what this suite measures; the real component would
+ // suspend on a chunk that does not exist under the mocked registry.
+ WidgetIdentityIcon: () => <Box boxSize="3.5" />,
WidgetChromeSlotById: ({ slot }: { slot: 'actions' | 'label' }) => {
if (slot === 'actions') {
return <Box data-testid="trailing-actions" flexShrink={0} w="189px" />;
diff --git a/invokeai/frontend/webv2/src/workbench/shell/CenterArea.tsx b/invokeai/frontend/webv2/src/workbench/shell/CenterArea.tsx
index ab26404128..8261e5a64b 100644
--- a/invokeai/frontend/webv2/src/workbench/shell/CenterArea.tsx
+++ b/invokeai/frontend/webv2/src/workbench/shell/CenterArea.tsx
@@ -1,3 +1,4 @@
+import type { RegisteredWidget } from '@workbench/widgetContracts';
import type {
PlacedWidgetRegionItem,
WidgetPlacementInstanceMeta,
@@ -10,6 +11,7 @@ import { useFocusRegionProps } from '@workbench/focusRegions';
import { WidgetIcon } from '@workbench/iconResolver';
import {
WidgetChromeSlotById,
+ WidgetIdentityIcon,
WidgetRendererById,
WidgetSourceLockBadge,
useWidgetIntentPreloadProps,
@@ -27,7 +29,7 @@ import {
import { getWidgetById, getWidgetsForRegion } from '@workbench/widgetRegistry';
import { useActiveProjectId, useActiveProjectSelector, useWorkbenchCommands } from '@workbench/WorkbenchContext';
import { CheckIcon, ChevronDownIcon, XIcon } from 'lucide-react';
-import { Activity, Suspense, useCallback, useMemo, useRef, type ReactNode } from 'react';
+import { Activity, Suspense, use, useCallback, useMemo, useRef, type ReactNode } from 'react';
import { useTranslation } from 'react-i18next';
import {
@@ -283,7 +285,7 @@ const CenterViewMenu = ({
variant="ghost"
>
<HStack gap="2" minW="0" position="relative" zIndex="1">
- {activeItem ? <WidgetIcon icon={activeItem.widget.manifest.icon} boxSize="3.5" /> : null}
+ {activeItem ? <CenterViewIcon widget={activeItem.widget} /> : null}
<Text fontSize="xs" fontWeight="700" truncate>
{label}
</Text>
@@ -340,6 +342,36 @@ const CenterViewMenu = ({
);
};
+/**
+ * The active center view's icon, showing a spinner while its implementation
+ * chunk is still downloading.
+ *
+ * Panel widgets get this from their frame header; the center has no header —
+ * `CenterArea` owns its chrome — so the identity slot in this trigger was the
+ * one place a cold widget looked fully loaded while it was not. Suspense is
+ * the mechanism because `DeferredResource` exposes a status but nothing to
+ * subscribe to; the same `use()`/fallback pair already drives the chrome slots
+ * in `WidgetRenderer`.
+ */
+const CenterViewIcon = ({ widget }: { widget: RegisteredWidget }) => {
+ const fallback = useMemo(
+ () => <WidgetIdentityIcon boxSize="3.5" icon={widget.manifest.icon} isLoading />,
+ [widget.manifest.icon]
+ );
+
+ return (
+ <Suspense fallback={fallback}>
+ <LoadedCenterViewIcon widget={widget} />
+ </Suspense>
+ );
+};
+
+const LoadedCenterViewIcon = ({ widget }: { widget: RegisteredWidget }) => {
+ use(widget.implementation.load());
+
+ return <WidgetIdentityIcon boxSize="3.5" icon={widget.manifest.icon} />;
+};
+
const CenterViewMenuRow = ({
isActive,
item,
diff --git a/invokeai/frontend/webv2/src/workbench/shell/PresetSwitchKeepAlive.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/shell/PresetSwitchKeepAlive.browser.test.tsx
index a16174e592..e018e78333 100644
--- a/invokeai/frontend/webv2/src/workbench/shell/PresetSwitchKeepAlive.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/shell/PresetSwitchKeepAlive.browser.test.tsx
@@ -14,12 +14,25 @@ import { afterEach, describe, expect, it, vi } from 'vitest';
*/
const keepAliveMocks = vi.hoisted(() => {
const icon = () => null;
- const widgets: Record<string, { manifest: unknown; status: string }> = {
+ // A settled deferred resource, the shape `use()` can read without
+ // suspending — the center view's icon resolves the implementation to decide
+ // whether to show a spinner, and these fixtures are always "already loaded".
+ const loadedImplementation = () => {
+ const promise: Promise<object> & { status?: string; value?: object } = Promise.resolve({});
+
+ promise.status = 'fulfilled';
+ promise.value = {};
+
+ return { getStatus: () => 'loaded', load: () => promise, preload: () => {}, retry: () => promise };
+ };
+ const widgets: Record<string, { implementation: unknown; manifest: unknown; status: string }> = {
canvas: {
+ implementation: loadedImplementation(),
manifest: { centerPlacement: 'view', chrome: { header: 'visible' }, icon, id: 'canvas' },
status: 'enabled',
},
workflow: {
+ implementation: loadedImplementation(),
manifest: { centerPlacement: 'view', chrome: { header: 'visible' }, icon, id: 'workflow' },
status: 'enabled',
},
@@ -132,6 +145,9 @@ vi.mock('@workbench/WorkbenchContext', async () => {
};
});
vi.mock('@workbench/widget-frame', () => ({
+ // Loading state is not what this suite measures; the real component would
+ // suspend on a chunk that does not exist under the mocked registry.
+ WidgetIdentityIcon: () => <Box boxSize="3.5" />,
WidgetChromeSlotById: () => null,
WidgetRendererById: ({ instanceId }: { instanceId: string }) => (
<Box
diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetIdentityIcon.tsx b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetIdentityIcon.tsx
index 9e5576b8d2..7c4944ed83 100644
--- a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetIdentityIcon.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetIdentityIcon.tsx
@@ -3,8 +3,17 @@ import type { WidgetIconComponent } from '@workbench/widgetContracts';
import { Box, Spinner } from '@chakra-ui/react';
import { WidgetIcon } from '@workbench/iconResolver';
-export const WidgetIdentityIcon = ({ icon, isLoading = false }: { icon: WidgetIconComponent; isLoading?: boolean }) => (
- <Box aria-hidden="true" boxSize="3" data-widget-identity-slot="" flexShrink="0">
+export const WidgetIdentityIcon = ({
+ boxSize = '3',
+ icon,
+ isLoading = false,
+}: {
+ /** The slot's size; the icon and the spinner both fill it. */
+ boxSize?: string;
+ icon: WidgetIconComponent;
+ isLoading?: boolean;
+}) => (
+ <Box aria-hidden="true" boxSize={boxSize} data-widget-identity-slot="" flexShrink="0">
{isLoading ? (
<Spinner borderWidth="1.5px" boxSize="full" color="fg.subtle" display="block" />
) : (
diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/index.ts b/invokeai/frontend/webv2/src/workbench/widget-frame/index.ts
index c2d76c6a60..9ace2a3737 100644
--- a/invokeai/frontend/webv2/src/workbench/widget-frame/index.ts
+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/index.ts
@@ -2,6 +2,7 @@ export { WidgetActionsMenu } from './WidgetActionsMenu';
export { WidgetBar, type WidgetBarItem } from './WidgetBar';
export { WidgetEnableMenu, type WidgetEnableMenuItem } from './WidgetEnableMenu';
export { WidgetFailureBoundary } from './WidgetFailureBoundary';
+export { WidgetIdentityIcon } from './WidgetIdentityIcon';
export { FieldPlaceholder, WidgetHeader, WidgetHeaderActionsGroup, WidgetPanelFrame } from './WidgetFrames';
export { StatusWidgetChip } from '@platform/ui';
export { WidgetInstanceContextMenu, type WidgetInstanceContextMenuTarget } from './WidgetInstanceContextMenu';