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): expose retained image map refresh errors

joshistoast3904e7c70e72
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.browser.test.tsx
new file mode 100644
index 0000000000..d385d81638
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.browser.test.tsx
@@ -0,0 +1,97 @@
+import type { ImageMapState } from '@workbench/image-map/api';
+import type { WidgetViewProps } from '@workbench/widgetContracts';
+
+import { ChakraProvider } from '@chakra-ui/react';
+import { system } from '@theme/system';
+import { act } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+
+vi.mock('@workbench/WorkbenchContext', () => ({
+ useWidgetValuesSelector: () => false,
+}));
+
+vi.mock('@workbench/image-map/imageMapStore', async (importOriginal) => {
+ const original = (await importOriginal()) as object;
+
+ return {
+ ...original,
+ ensureImageMapLoaded: vi.fn(),
+ refreshImageIndexStatus: vi.fn(),
+ refreshImageMapPoints: vi.fn(),
+ setClusterLabelsEnabled: vi.fn(),
+ };
+});
+
+import { imageMapStore } from '@workbench/image-map/imageMapStore';
+
+import { ImageMapWidgetView } from './ImageMapWidgetView';
+
+let host: HTMLDivElement | null = null;
+let root: Root | null = null;
+(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
+
+const dataFor = (state: Extract<ImageMapState, 'disabled' | 'model_missing'>) => ({
+ clusterEps: null,
+ modelName: state === 'model_missing' ? 'clip-vit-large-patch14' : null,
+ pointCount: 0,
+ points: [],
+ stale: false,
+ state,
+ updatedAt: null,
+ visibleHash: null,
+});
+
+const renderState = async (state: Extract<ImageMapState, 'disabled' | 'model_missing'>) => {
+ imageMapStore.setSnapshot({
+ clusterLabels: null,
+ data: dataFor(state),
+ error: null,
+ indexCounts: null,
+ indexUpdatedAt: null,
+ loadState: 'loaded',
+ renderError: null,
+ });
+
+ await act(() =>
+ root?.render(
+ <ChakraProvider value={system}>
+ <ImageMapWidgetView {...({} as WidgetViewProps)} />
+ </ChakraProvider>
+ )
+ );
+};
+
+beforeEach(() => {
+ host = document.createElement('div');
+ document.body.append(host);
+ root = createRoot(host);
+});
+
+afterEach(async () => {
+ await act(() => root?.unmount());
+ host?.remove();
+ host = null;
+ root = null;
+});
+
+describe('Image Map unavailable states', () => {
+ it.each([
+ ['model_missing', 'Embedding model not installed'],
+ ['disabled', 'Image indexing is off'],
+ ] as const)('keeps the %s diagnosis visible while exposing a failed refresh', async (state, title) => {
+ await renderState(state);
+
+ expect(host?.textContent).toContain(title);
+ expect(host?.querySelector('button')).toBeNull();
+
+ await act(() => {
+ imageMapStore.patchSnapshot({ error: 'The server could not be reached.', loadState: 'error' });
+ });
+
+ expect(host?.textContent).toContain(title);
+ expect(host?.textContent).toContain('The server could not be reached.');
+ expect(host?.querySelector('[role="alert"]')?.textContent).toBe('The server could not be reached.');
+ expect(host?.querySelector('button')?.textContent).toBe('Retry');
+ });
+});
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.tsx b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.tsx
index 4044f90952..90338d65a7 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.tsx
@@ -106,12 +106,17 @@ export const ImageMapWidgetView = (_props: WidgetViewProps) => {
);
}
+ const retainedDataError = loadState === 'error' ? (error ?? 'Failed to load the image map.') : null;
+
if (data?.state === 'model_missing') {
const model = data.modelName ?? 'the model named by `image_index_model`';
return (
<CenteredMessage
+ actionLabel={retainedDataError ? 'Retry' : undefined}
detail={`Image indexing is enabled, but the embedding model '${model}' is not installed. Install the CLIP Vision model with this name, then restart the server.`}
+ errorDetail={retainedDataError}
+ onAction={retainedDataError ? handleRefresh : undefined}
title="Embedding model not installed"
/>
);
@@ -120,7 +125,10 @@ export const ImageMapWidgetView = (_props: WidgetViewProps) => {
if (!data || data.state === 'disabled') {
return (
<CenteredMessage
+ actionLabel={retainedDataError ? 'Retry' : undefined}
detail="Enable `image_index_enabled` in the server configuration and restart the server to build a semantic index of your gallery."
+ errorDetail={retainedDataError}
+ onAction={retainedDataError ? handleRefresh : undefined}
title="Image indexing is off"
/>
);
@@ -187,12 +195,14 @@ export const ImageMapWidgetView = (_props: WidgetViewProps) => {
const CenteredMessage = ({
actionLabel,
detail,
+ errorDetail,
onAction,
title,
}: {
title: string;
detail: string;
actionLabel?: string;
+ errorDetail?: string | null;
onAction?: () => void;
}) => (
<Center h="full" p="6">
@@ -201,6 +211,11 @@ const CenteredMessage = ({
<Text color="fg.muted" fontSize="sm">
{detail}
</Text>
+ {errorDetail ? (
+ <Text color="fg.error" fontSize="sm" maxW="full" minW="0" overflowWrap="anywhere" role="alert">
+ {errorDetail}
+ </Text>
+ ) : null}
{actionLabel && onAction ? (
<Button mt="2" onClick={onAction} size="xs" variant="outline">
{actionLabel}