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): select the cluster's board, and use the shared toggle control

Lincoln Stein408859c9ec5b
diff --git a/invokeai/frontend/webv2/performance/browser-baseline.json b/invokeai/frontend/webv2/performance/browser-baseline.json
index a14a68293d..ef827ab3f9 100644
--- a/invokeai/frontend/webv2/performance/browser-baseline.json
+++ b/invokeai/frontend/webv2/performance/browser-baseline.json
@@ -25,11 +25,11 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 143.7999997138977,
+ "domContentLoadedMedianMs": 135.90000009536743,
"id": "launchpad",
"layoutSwitchMedianMs": 0,
- "loadMedianMs": 143.90000009536743,
- "longestTaskMaxMs": 72,
+ "loadMedianMs": 136,
+ "longestTaskMaxMs": 77,
"owner": "app",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:launchpad",
@@ -56,7 +56,7 @@
"scriptRequestCount": 32,
"totalRawBytes": 1779666
},
- "routeReadyMedianMs": 295.59999990463257,
+ "routeReadyMedianMs": 297.8999996185303,
"scriptSourceOwnerSet": "launchpad-static",
"stateProfile": "empty"
},
@@ -83,11 +83,11 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 155.2000002861023,
+ "domContentLoadedMedianMs": 131.09999990463257,
"id": "launchpad",
"layoutSwitchMedianMs": 0,
- "loadMedianMs": 155.2000002861023,
- "longestTaskMaxMs": 72,
+ "loadMedianMs": 131.19999980926514,
+ "longestTaskMaxMs": 77,
"owner": "app",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:launchpad",
@@ -114,7 +114,7 @@
"scriptRequestCount": 32,
"totalRawBytes": 1779666
},
- "routeReadyMedianMs": 322.8999996185303,
+ "routeReadyMedianMs": 303.90000009536743,
"scriptSourceOwnerSet": "launchpad-static",
"stateProfile": "representative"
},
@@ -141,13 +141,13 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 156.40000009536743,
+ "domContentLoadedMedianMs": 133.90000009536743,
"id": "editor-minimal",
"layoutSwitchMedianMs": 0,
- "loadMedianMs": 156.40000009536743,
- "longestTaskMaxMs": 103,
+ "loadMedianMs": 133.90000009536743,
+ "longestTaskMaxMs": 121,
"owner": "workbench",
- "projectSwitchMedianMs": 45.39999961853027,
+ "projectSwitchMedianMs": 34.59999990463257,
"readyMark": "invokeai:ready:widget:center:preview",
"remediationTicket": "deepen-widget-registry-loading",
"resourceBaseline": {
@@ -157,9 +157,9 @@
"largestAssetRawBytes": 746314,
"otherRawBytes": 135095,
"requestCount": 113,
- "scriptRawBytes": 3343388,
+ "scriptRawBytes": 3343019,
"scriptRequestCount": 107,
- "totalRawBytes": 3676095
+ "totalRawBytes": 3675726
},
"resourceLimits": {
"cssRawBytes": 17748,
@@ -168,11 +168,11 @@
"largestAssetRawBytes": 753778,
"otherRawBytes": 136446,
"requestCount": 113,
- "scriptRawBytes": 3376822,
+ "scriptRawBytes": 3376450,
"scriptRequestCount": 107,
- "totalRawBytes": 3712856
+ "totalRawBytes": 3712484
},
- "routeReadyMedianMs": 702.1000003814697,
+ "routeReadyMedianMs": 704.2000002861023,
"scriptSourceOwnerSet": "editor-minimal-static",
"stateProfile": "empty"
},
@@ -199,13 +199,13 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 150.30000019073486,
+ "domContentLoadedMedianMs": 136.09999990463257,
"id": "editor-minimal",
"layoutSwitchMedianMs": 0,
- "loadMedianMs": 150.30000019073486,
- "longestTaskMaxMs": 104,
+ "loadMedianMs": 136.2000002861023,
+ "longestTaskMaxMs": 125,
"owner": "workbench",
- "projectSwitchMedianMs": 59,
+ "projectSwitchMedianMs": 57.89999961853027,
"readyMark": "invokeai:ready:widget:center:preview",
"remediationTicket": "deepen-widget-registry-loading",
"resourceBaseline": {
@@ -215,9 +215,9 @@
"largestAssetRawBytes": 746314,
"otherRawBytes": 135095,
"requestCount": 113,
- "scriptRawBytes": 3343388,
+ "scriptRawBytes": 3343019,
"scriptRequestCount": 107,
- "totalRawBytes": 3676095
+ "totalRawBytes": 3675726
},
"resourceLimits": {
"cssRawBytes": 17748,
@@ -226,11 +226,11 @@
"largestAssetRawBytes": 753778,
"otherRawBytes": 136446,
"requestCount": 113,
- "scriptRawBytes": 3376822,
+ "scriptRawBytes": 3376450,
"scriptRequestCount": 107,
- "totalRawBytes": 3712856
+ "totalRawBytes": 3712484
},
- "routeReadyMedianMs": 781.8000001907349,
+ "routeReadyMedianMs": 835.0999999046326,
"scriptSourceOwnerSet": "editor-minimal-static",
"stateProfile": "representative"
},
@@ -257,11 +257,11 @@
"scriptRequestCount": 5,
"totalRawBytes": 286571
},
- "domContentLoadedMedianMs": 139.2999997138977,
+ "domContentLoadedMedianMs": 133.09999990463257,
"id": "editor-canvas",
- "layoutSwitchMedianMs": 76.60000038146973,
- "loadMedianMs": 139.2999997138977,
- "longestTaskMaxMs": 104,
+ "layoutSwitchMedianMs": 81,
+ "loadMedianMs": 133.09999990463257,
+ "longestTaskMaxMs": 125,
"owner": "canvas",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:canvas",
@@ -273,9 +273,9 @@
"largestAssetRawBytes": 746314,
"otherRawBytes": 135095,
"requestCount": 118,
- "scriptRawBytes": 3627121,
+ "scriptRawBytes": 3626752,
"scriptRequestCount": 112,
- "totalRawBytes": 3959828
+ "totalRawBytes": 3959459
},
"resourceLimits": {
"cssRawBytes": 17748,
@@ -284,11 +284,11 @@
"largestAssetRawBytes": 753778,
"otherRawBytes": 136446,
"requestCount": 118,
- "scriptRawBytes": 3663393,
+ "scriptRawBytes": 3663020,
"scriptRequestCount": 112,
- "totalRawBytes": 3999427
+ "totalRawBytes": 3999054
},
- "routeReadyMedianMs": 1213.3000001907349,
+ "routeReadyMedianMs": 1193.9000000953674,
"scriptSourceOwnerSet": "editor-canvas-static",
"stateProfile": "empty"
},
@@ -315,11 +315,11 @@
"scriptRequestCount": 5,
"totalRawBytes": 286571
},
- "domContentLoadedMedianMs": 135.5,
+ "domContentLoadedMedianMs": 128.39999961853027,
"id": "editor-canvas",
- "layoutSwitchMedianMs": 184.80000019073486,
- "loadMedianMs": 135.59999990463257,
- "longestTaskMaxMs": 369,
+ "layoutSwitchMedianMs": 193,
+ "loadMedianMs": 128.39999961853027,
+ "longestTaskMaxMs": 472,
"owner": "canvas",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:canvas",
@@ -331,9 +331,9 @@
"largestAssetRawBytes": 746314,
"otherRawBytes": 135095,
"requestCount": 118,
- "scriptRawBytes": 3627121,
+ "scriptRawBytes": 3626752,
"scriptRequestCount": 112,
- "totalRawBytes": 3959828
+ "totalRawBytes": 3959459
},
"resourceLimits": {
"cssRawBytes": 17748,
@@ -342,11 +342,11 @@
"largestAssetRawBytes": 753778,
"otherRawBytes": 136446,
"requestCount": 118,
- "scriptRawBytes": 3663393,
+ "scriptRawBytes": 3663020,
"scriptRequestCount": 112,
- "totalRawBytes": 3999427
+ "totalRawBytes": 3999054
},
- "routeReadyMedianMs": 1360.4000000953674,
+ "routeReadyMedianMs": 1382.7999997138977,
"scriptSourceOwnerSet": "editor-canvas-static",
"stateProfile": "representative"
},
@@ -373,11 +373,11 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 151.40000009536743,
+ "domContentLoadedMedianMs": 122.2999997138977,
"id": "editor-workflow",
- "layoutSwitchMedianMs": 72.7999997138977,
- "loadMedianMs": 151.40000009536743,
- "longestTaskMaxMs": 106,
+ "layoutSwitchMedianMs": 78.59999990463257,
+ "loadMedianMs": 122.2999997138977,
+ "longestTaskMaxMs": 141,
"owner": "workflow",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:workflow",
@@ -389,9 +389,9 @@
"largestAssetRawBytes": 746314,
"otherRawBytes": 135095,
"requestCount": 113,
- "scriptRawBytes": 3343388,
+ "scriptRawBytes": 3343019,
"scriptRequestCount": 107,
- "totalRawBytes": 3676095
+ "totalRawBytes": 3675726
},
"resourceLimits": {
"cssRawBytes": 17748,
@@ -400,11 +400,11 @@
"largestAssetRawBytes": 753778,
"otherRawBytes": 136446,
"requestCount": 113,
- "scriptRawBytes": 3376822,
+ "scriptRawBytes": 3376450,
"scriptRequestCount": 107,
- "totalRawBytes": 3712856
+ "totalRawBytes": 3712484
},
- "routeReadyMedianMs": 1235,
+ "routeReadyMedianMs": 1155.4000000953674,
"scriptSourceOwnerSet": "editor-minimal-static",
"stateProfile": "empty"
},
@@ -431,11 +431,11 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 142,
+ "domContentLoadedMedianMs": 135.60000038146973,
"id": "editor-workflow",
- "layoutSwitchMedianMs": 115.10000038146973,
- "loadMedianMs": 142,
- "longestTaskMaxMs": 379,
+ "layoutSwitchMedianMs": 120.09999990463257,
+ "loadMedianMs": 135.60000038146973,
+ "longestTaskMaxMs": 443,
"owner": "workflow",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:workflow",
@@ -447,9 +447,9 @@
"largestAssetRawBytes": 746314,
"otherRawBytes": 135095,
"requestCount": 113,
- "scriptRawBytes": 3343388,
+ "scriptRawBytes": 3343019,
"scriptRequestCount": 107,
- "totalRawBytes": 3676095
+ "totalRawBytes": 3675726
},
"resourceLimits": {
"cssRawBytes": 17748,
@@ -458,11 +458,11 @@
"largestAssetRawBytes": 753778,
"otherRawBytes": 136446,
"requestCount": 113,
- "scriptRawBytes": 3376822,
+ "scriptRawBytes": 3376450,
"scriptRequestCount": 107,
- "totalRawBytes": 3712856
+ "totalRawBytes": 3712484
},
- "routeReadyMedianMs": 1302.9000000953674,
+ "routeReadyMedianMs": 1271.8000001907349,
"scriptSourceOwnerSet": "editor-minimal-static",
"stateProfile": "representative"
},
@@ -489,11 +489,11 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 141.59999990463257,
+ "domContentLoadedMedianMs": 121.5,
"id": "editor-gallery",
- "layoutSwitchMedianMs": 39.39999961853027,
- "loadMedianMs": 141.59999990463257,
- "longestTaskMaxMs": 105,
+ "layoutSwitchMedianMs": 32.90000009536743,
+ "loadMedianMs": 121.5,
+ "longestTaskMaxMs": 104,
"owner": "gallery",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:gallery",
@@ -505,9 +505,9 @@
"largestAssetRawBytes": 746314,
"otherRawBytes": 135095,
"requestCount": 113,
- "scriptRawBytes": 3343388,
+ "scriptRawBytes": 3343019,
"scriptRequestCount": 107,
- "totalRawBytes": 3676095
+ "totalRawBytes": 3675726
},
"resourceLimits": {
"cssRawBytes": 17748,
@@ -516,11 +516,11 @@
"largestAssetRawBytes": 753778,
"otherRawBytes": 136446,
"requestCount": 113,
- "scriptRawBytes": 3376822,
+ "scriptRawBytes": 3376450,
"scriptRequestCount": 107,
- "totalRawBytes": 3712856
+ "totalRawBytes": 3712484
},
- "routeReadyMedianMs": 1474.0999999046326,
+ "routeReadyMedianMs": 1394.3000001907349,
"scriptSourceOwnerSet": "editor-minimal-static",
"stateProfile": "empty"
},
@@ -547,11 +547,11 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 143.30000019073486,
+ "domContentLoadedMedianMs": 123.5,
"id": "editor-gallery",
- "layoutSwitchMedianMs": 94.40000009536743,
- "loadMedianMs": 143.30000019073486,
- "longestTaskMaxMs": 136,
+ "layoutSwitchMedianMs": 98.69999980926514,
+ "loadMedianMs": 123.5,
+ "longestTaskMaxMs": 142,
"owner": "gallery",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:gallery",
@@ -563,9 +563,9 @@
"largestAssetRawBytes": 746314,
"otherRawBytes": 135095,
"requestCount": 113,
- "scriptRawBytes": 3343388,
+ "scriptRawBytes": 3343019,
"scriptRequestCount": 107,
- "totalRawBytes": 3676095
+ "totalRawBytes": 3675726
},
"resourceLimits": {
"cssRawBytes": 17748,
@@ -574,11 +574,11 @@
"largestAssetRawBytes": 753778,
"otherRawBytes": 136446,
"requestCount": 113,
- "scriptRawBytes": 3376822,
+ "scriptRawBytes": 3376450,
"scriptRequestCount": 107,
- "totalRawBytes": 3712856
+ "totalRawBytes": 3712484
},
- "routeReadyMedianMs": 1567.5,
+ "routeReadyMedianMs": 1528.0999999046326,
"scriptSourceOwnerSet": "editor-minimal-static",
"stateProfile": "representative"
}
@@ -1635,6 +1635,7 @@
"source:src/workbench/image-actions/useDeletionConfirmation.tsx",
"source:src/workbench/image-actions/useImageActions.ts",
"source:src/workbench/image-map/api.ts",
+ "source:src/workbench/image-map/imageMapSettings.ts",
"source:src/workbench/image-map/imageMapStore.ts",
"source:src/workbench/invocation.ts",
"source:src/workbench/invocationSubmit.ts",
@@ -2577,6 +2578,7 @@
"source:src/workbench/image-actions/useDeletionConfirmation.tsx",
"source:src/workbench/image-actions/useImageActions.ts",
"source:src/workbench/image-map/api.ts",
+ "source:src/workbench/image-map/imageMapSettings.ts",
"source:src/workbench/image-map/imageMapStore.ts",
"source:src/workbench/invocation.ts",
"source:src/workbench/invocationSubmit.ts",
diff --git a/invokeai/frontend/webv2/src/workbench/image-map/imageMapSettings.ts b/invokeai/frontend/webv2/src/workbench/image-map/imageMapSettings.ts
new file mode 100644
index 0000000000..48f26a956d
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/image-map/imageMapSettings.ts
@@ -0,0 +1,7 @@
+/**
+ * Accessors for the Image Map widget's persisted view settings, so the header
+ * toggle and the view read the same shape from one place.
+ */
+
+export const getImageMapClickSelectsCluster = (values: Record<string, unknown>): boolean =>
+ values.clickSelectsCluster === true;
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapHeaderActions.tsx b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapHeaderActions.tsx
index 35654c45dd..46ed07959b 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapHeaderActions.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapHeaderActions.tsx
@@ -1,7 +1,7 @@
import type { WidgetViewProps } from '@workbench/widgetContracts';
-import { Icon } from '@chakra-ui/react';
-import { IconButton, Tooltip } from '@platform/ui';
+import { ToggleIconButton } from '@platform/ui';
+import { getImageMapClickSelectsCluster } from '@workbench/image-map/imageMapSettings';
import { useWidgetValuesSelector, useWorkbenchCommands } from '@workbench/WorkbenchContext';
import { GroupIcon } from 'lucide-react';
import { useCallback } from 'react';
@@ -13,24 +13,19 @@ import { useCallback } from 'react';
*/
export const ImageMapHeaderActions = (_props: WidgetViewProps) => {
const { widgets } = useWorkbenchCommands();
- const clickSelectsCluster = useWidgetValuesSelector('image-map', (values) => Boolean(values.clickSelectsCluster));
+ const clickSelectsCluster = useWidgetValuesSelector('image-map', getImageMapClickSelectsCluster);
const handleToggle = useCallback(
- () => widgets.patchValues('image-map', { clickSelectsCluster: !clickSelectsCluster }),
- [clickSelectsCluster, widgets]
+ (checked: boolean) => widgets.patchValues('image-map', { clickSelectsCluster: checked }),
+ [widgets]
);
return (
- <Tooltip content={clickSelectsCluster ? 'Click selects the whole cluster' : 'Click selects one image'}>
- <IconButton
- aria-label="Toggle cluster selection mode"
- aria-pressed={clickSelectsCluster}
- color={clickSelectsCluster ? 'accent.fg' : 'fg.muted'}
- size="2xs"
- variant={clickSelectsCluster ? 'subtle' : 'ghost'}
- onClick={handleToggle}
- >
- <Icon as={GroupIcon} boxSize="3.5" />
- </IconButton>
- </Tooltip>
+ <ToggleIconButton
+ checked={clickSelectsCluster}
+ icon={GroupIcon}
+ label="Toggle cluster selection mode"
+ tooltip={clickSelectsCluster ? 'Click selects the whole cluster' : 'Click selects one image'}
+ onCheckedChange={handleToggle}
+ />
);
};
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 516610ceb4..14089f6f48 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.tsx
@@ -1,6 +1,7 @@
import type { WidgetViewProps } from '@workbench/widgetContracts';
import { Button, Center, Spinner, Stack, Text } from '@chakra-ui/react';
+import { getImageMapClickSelectsCluster } from '@workbench/image-map/imageMapSettings';
import { ensureImageMapLoaded, imageMapStore, refreshImageMapPoints } from '@workbench/image-map/imageMapStore';
import { useWidgetValuesSelector } from '@workbench/WorkbenchContext';
import { lazy, Suspense, useEffect } from 'react';
@@ -29,7 +30,7 @@ const plotLoadingFallback = (
*/
export const ImageMapWidgetView = (_props: WidgetViewProps) => {
const { data, error, loadState, renderError } = imageMapStore.useSnapshot();
- const clickSelectsCluster = useWidgetValuesSelector('image-map', (values) => Boolean(values.clickSelectsCluster));
+ const clickSelectsCluster = useWidgetValuesSelector('image-map', getImageMapClickSelectsCluster);
useEffect(() => {
ensureImageMapLoaded();
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/image-map/useSelectMapImage.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/image-map/useSelectMapImage.browser.test.tsx
index 38b2b39a21..26029edda7 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/image-map/useSelectMapImage.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/image-map/useSelectMapImage.browser.test.tsx
@@ -5,6 +5,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest';
const mocks = vi.hoisted(() => ({
resolveMany: vi.fn(),
selectBoard: vi.fn(),
+ setItemMultiSelection: vi.fn(),
selectItem: vi.fn(),
}));
@@ -16,7 +17,11 @@ vi.mock('@features/gallery', () => ({
vi.mock('@workbench/WorkbenchContext', () => ({
useWorkbenchCommands: () => ({
- gallery: { selectBoard: mocks.selectBoard, selectItem: mocks.selectItem },
+ gallery: {
+ selectBoard: mocks.selectBoard,
+ selectItem: mocks.selectItem,
+ setItemMultiSelection: mocks.setItemMultiSelection,
+ },
}),
}));
@@ -28,14 +33,18 @@ let host: HTMLDivElement | null = null;
let root: Root | null = null;
/** Published from an effect, not during render, so the probe stays render-pure. */
-const handle: { click: ((imageName: string) => void) | null } = { click: null };
+const handle: {
+ click: ((imageName: string) => void) | null;
+ clickCluster: ((primaryImageName: string, imageNames: string[]) => void) | null;
+} = { click: null, clickCluster: null };
const Probe = () => {
- const { selectImage } = useMapSelection();
+ const { selectCluster, selectImage } = useMapSelection();
useEffect(() => {
handle.click = selectImage;
- }, [selectImage]);
+ handle.clickCluster = selectCluster;
+ }, [selectCluster, selectImage]);
return null;
};
@@ -61,6 +70,7 @@ const unmount = async () => {
root = null;
host = null;
handle.click = null;
+ handle.clickCluster = null;
};
/** A promise plus the trigger that settles it, so click ordering can be forced. */
@@ -80,6 +90,7 @@ afterEach(async () => {
mocks.resolveMany.mockReset();
mocks.selectBoard.mockReset();
mocks.selectItem.mockReset();
+ mocks.setItemMultiSelection.mockReset();
});
describe('useMapSelection', () => {
@@ -118,6 +129,71 @@ describe('useMapSelection', () => {
expect(mocks.selectItem).not.toHaveBeenCalled();
});
+ it('selects the primary image\u2019s board before the cluster', async () => {
+ // Same reason as the single-image case: setItemMultiSelection stamps the
+ // navigation query from the list the gallery is currently showing, so a
+ // cluster picked from another board would leave that query describing a
+ // list none of these images are in.
+ mocks.resolveMany.mockResolvedValue([{ boardId: 'board-landscapes', image_name: 'a.png' }]);
+ await mount();
+
+ await flush(() => handle.clickCluster?.('a.png', ['a.png', 'b.png', 'c.png']));
+
+ expect(mocks.selectBoard).toHaveBeenCalledWith('board-landscapes');
+ expect(mocks.selectBoard.mock.invocationCallOrder[0]).toBeLessThan(
+ mocks.setItemMultiSelection.mock.invocationCallOrder[0]
+ );
+ });
+
+ it('passes every cluster member as an image-kinded key, anchored on the clicked one', async () => {
+ mocks.resolveMany.mockResolvedValue([{ boardId: 'board-a', image_name: 'a.png' }]);
+ await mount();
+
+ await flush(() => handle.clickCluster?.('a.png', ['a.png', 'b.png']));
+
+ expect(mocks.setItemMultiSelection).toHaveBeenCalledTimes(1);
+ const [keys, primary] = mocks.setItemMultiSelection.mock.calls[0] ?? [];
+ expect(keys).toEqual([
+ { kind: 'image', name: 'a.png' },
+ { kind: 'image', name: 'b.png' },
+ ]);
+ expect(primary).toEqual({ boardId: 'board-a', image_name: 'a.png' });
+ });
+
+ it('leaves the selection alone when the primary image cannot be resolved', async () => {
+ mocks.resolveMany.mockResolvedValue([]);
+ await mount();
+
+ await flush(() => handle.clickCluster?.('gone.png', ['gone.png', 'b.png']));
+
+ expect(mocks.selectBoard).not.toHaveBeenCalled();
+ expect(mocks.setItemMultiSelection).not.toHaveBeenCalled();
+ });
+
+ it('shares one sequence guard across both modes, so the newer click wins', async () => {
+ // The two entry points must not race each other: switching cluster mode
+ // mid-flight would otherwise let a stale resolution overwrite a newer
+ // selection.
+ const slow = deferred<{ image_name: string }[]>();
+ const fast = deferred<{ image_name: string }[]>();
+
+ mocks.resolveMany.mockReturnValueOnce(slow.promise).mockReturnValueOnce(fast.promise);
+ await mount();
+
+ await flush(() => {
+ handle.clickCluster?.('slow.png', ['slow.png']);
+ handle.click?.('fast.png');
+ });
+ await flush(() => {
+ fast.resolve([{ image_name: 'fast.png' }]);
+ slow.resolve([{ image_name: 'slow.png' }]);
+ });
+
+ expect(mocks.setItemMultiSelection).not.toHaveBeenCalled();
+ expect(mocks.selectItem).toHaveBeenCalledTimes(1);
+ expect(mocks.selectItem.mock.calls[0]?.[0]).toEqual({ image_name: 'fast.png' });
+ });
+
it('ignores a slow click that resolves after a newer one', async () => {
const slow = deferred<{ image_name: string }[]>();
const fast = deferred<{ image_name: string }[]>();
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/image-map/useSelectMapImage.ts b/invokeai/frontend/webv2/src/workbench/widgets/image-map/useSelectMapImage.ts
index 7d4d5a5c23..1d3f65ecc7 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/image-map/useSelectMapImage.ts
+++ b/invokeai/frontend/webv2/src/workbench/widgets/image-map/useSelectMapImage.ts
@@ -82,6 +82,11 @@ export const useMapSelection = (): MapSelectionActions => {
return;
}
+ // Same reason as `selectImage` above: the multi-selection command
+ // stamps `selectedImageQuery` from the board the gallery is showing,
+ // so without landing on the primary image's board first the query
+ // describes a list none of these images are in.
+ commands.gallery.selectBoard(image.boardId);
// Map points are always images, so every key is kind-tagged 'image'.
const itemKeys = imageNames.map((name) => toGalleryItemKey({ kind: 'image', name }));
commands.gallery.setItemMultiSelection(itemKeys, legacyGeneratedImageToGalleryItem(image));