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.

feat(webv2): show concurrent live sessions in the preview filmstrip

Josh Corbett7b8b018618bb
diff --git a/invokeai/frontend/webv2/performance/browser-baseline.json b/invokeai/frontend/webv2/performance/browser-baseline.json
index 5ca366125c..7b22b372ad 100644
--- a/invokeai/frontend/webv2/performance/browser-baseline.json
+++ b/invokeai/frontend/webv2/performance/browser-baseline.json
@@ -1722,7 +1722,6 @@
"source:src/workbench/widgets/preview/PreviewCompareDropZone.tsx",
"source:src/workbench/widgets/preview/PreviewDetailsPopover.tsx",
"source:src/workbench/widgets/preview/PreviewFilmstrip.tsx",
- "source:src/workbench/widgets/preview/PreviewFooter.tsx",
"source:src/workbench/widgets/preview/PreviewFrame.tsx",
"source:src/workbench/widgets/preview/PreviewHeaderActions.tsx",
"source:src/workbench/widgets/preview/PreviewMetadataPanel.tsx",
@@ -2917,7 +2916,6 @@
"source:src/workbench/widgets/preview/PreviewCompareDropZone.tsx",
"source:src/workbench/widgets/preview/PreviewDetailsPopover.tsx",
"source:src/workbench/widgets/preview/PreviewFilmstrip.tsx",
- "source:src/workbench/widgets/preview/PreviewFooter.tsx",
"source:src/workbench/widgets/preview/PreviewFrame.tsx",
"source:src/workbench/widgets/preview/PreviewHeaderActions.tsx",
"source:src/workbench/widgets/preview/PreviewMetadataPanel.tsx",
@@ -4032,7 +4030,6 @@
"source:src/workbench/widgets/preview/PreviewCompareDropZone.tsx",
"source:src/workbench/widgets/preview/PreviewDetailsPopover.tsx",
"source:src/workbench/widgets/preview/PreviewFilmstrip.tsx",
- "source:src/workbench/widgets/preview/PreviewFooter.tsx",
"source:src/workbench/widgets/preview/PreviewFrame.tsx",
"source:src/workbench/widgets/preview/PreviewHeaderActions.tsx",
"source:src/workbench/widgets/preview/PreviewMetadataPanel.tsx",
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.json
index 4074635ea9..9b079c35a7 100644
--- a/invokeai/frontend/webv2/public/locales/en.json
+++ b/invokeai/frontend/webv2/public/locales/en.json
@@ -2564,7 +2564,6 @@
"viewing": "Viewing",
"workflow": "Workflow",
"workflowJsonLabel": "Video workflow JSON",
- "showAllActivePreviews": "Show all active previews",
"zoom": "Zoom",
"zoomLevel": "Zoom {{percent}}%",
"zoomPercent": "{{percent}}%",
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFilmstrip.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFilmstrip.tsx
index 22fdc73471..a1f9440397 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFilmstrip.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFilmstrip.tsx
@@ -1,34 +1,62 @@
import type { GalleryItem, GalleryItemKey } from '@features/gallery';
+import type { QueueProgressSession } from '@features/queue/contracts';
-import { Box, HStack } from '@chakra-ui/react';
+import { Box, HStack, Icon, ProgressCircle, Skeleton } from '@chakra-ui/react';
import { useDraggable } from '@dnd-kit/core';
import { toGalleryItemKey, toGalleryItemRef } from '@features/gallery/contracts';
import { getGalleryItemDragData, getGalleryItemDragId } from '@features/gallery/utility';
+import { getDeterminateProgressPercent } from '@features/queue/contracts';
+import { useDeviceLabel } from '@features/queue/devices';
+import { useItemProgress, useQueueItemProgressImage } from '@features/queue/react';
import { Scrollable } from '@platform/ui/Scrollable';
+import { StreamingImageFrame } from '@platform/ui/streaming-image/StreamingImageFrame';
+import { progressImageToStreamingSource } from '@platform/ui/streaming-image/streamingImageSource';
+import { CheckIcon, HourglassIcon, PinIcon } from 'lucide-react';
import { useCallback, useMemo, type MouseEvent } from 'react';
+import { useTranslation } from 'react-i18next';
import type { PreviewDensity } from './previewDensity';
/**
* The current board's thumbnails as a row docked under the stage — the same
* `boardImages` the Details position counter is derived from, made spatial.
- * It takes its own height rather than floating over the media, so the fitted
- * frame is never covered and Details has a clean edge to stop above. Thumbs
- * are standard all-image gallery-item drag sources, so they work with every
- * existing drop target (canvas zones, boards, drop-to-compare).
+ * Live sessions lead the row in the gallery's in-progress order, one thumb
+ * per GPU slot, so however many run the stage keeps one of them large and
+ * the rest stay a glance (and a click) away; a session that finishes becomes
+ * its image's thumb in place. It takes its own height rather than floating
+ * over the media, so the fitted frame is never covered and Details has a
+ * clean edge to stop above. Item thumbs are standard all-image gallery-item
+ * drag sources, so they work with every existing drop target (canvas zones,
+ * boards, drop-to-compare).
*/
export const PreviewFilmstrip = ({
density,
+ followedSessionId = null,
+ isSessionPinned = false,
items,
selectedItemKey,
+ sessions = EMPTY_SESSIONS,
onCompare,
onContextMenu,
+ onFollowSession,
onSelect,
+ onUnpinSession,
+ shouldAntialiasLiveImage = true,
}: {
density: PreviewDensity;
+ /** The live session on the stage, if the preview is following one. */
+ followedSessionId?: string | null;
+ /** Whether that session was pinned by hand; clicking it again unpins. */
+ isSessionPinned?: boolean;
items: GalleryItem[];
selectedItemKey: GalleryItemKey | null;
+ /** In-progress slots in the gallery's order, leading the row. */
+ sessions?: readonly QueueProgressSession[];
+ onFollowSession?: (sessionId: string) => void;
+ onUnpinSession?: () => void;
+ /** The project's live-frame antialiasing setting, mirrored on the live thumbs. */
+ shouldAntialiasLiveImage?: boolean;
/** Alt-click: arm this thumb for comparison against the selection. */
onCompare?: (item: GalleryItem) => void;
/** Right-click: the image context menu for this thumb, at viewport coordinates. */
@@ -37,7 +65,9 @@ export const PreviewFilmstrip = ({
}) => {
const thumbSize = density === 'full' ? '12' : '8';
- if (items.length < 2) {
+ // A lone item has nothing to step to; a live session always earns the row,
+ // or a single running slot on an empty board would have no thumb at all.
+ if (items.length < 2 && sessions.length === 0) {
return null;
}
@@ -63,6 +93,18 @@ export const PreviewFilmstrip = ({
w="full"
>
<HStack align="center" gap="1" h="full">
+ {sessions.map((session) => (
+ <FilmstripLiveThumb
+ key={session.id}
+ isFollowed={session.id === followedSessionId}
+ isPinned={isSessionPinned && session.id === followedSessionId}
+ session={session}
+ shouldAntialiasLiveImage={shouldAntialiasLiveImage}
+ size={thumbSize}
+ onFollow={onFollowSession}
+ onUnpin={onUnpinSession}
+ />
+ ))}
{items.map((item) => {
const itemKey = toGalleryItemKey(item);
@@ -83,6 +125,152 @@ export const PreviewFilmstrip = ({
);
};
+/**
+ * One running, settling, or queued slot. Mirrors the gallery's in-progress
+ * tile: the latest denoise frame under a progress ring, a device chip in the
+ * name, `aria-current` while it is the session on the stage, and a pin in
+ * place of the ring while it is pinned there — so the next click visibly
+ * unpins. Only a running slot can be followed.
+ */
+const FilmstripLiveThumb = ({
+ isFollowed,
+ isPinned,
+ onFollow,
+ onUnpin,
+ session,
+ shouldAntialiasLiveImage,
+ size,
+}: {
+ isFollowed: boolean;
+ isPinned: boolean;
+ onFollow?: (sessionId: string) => void;
+ onUnpin?: () => void;
+ session: QueueProgressSession;
+ shouldAntialiasLiveImage: boolean;
+ size: string;
+}) => {
+ const { t } = useTranslation();
+ const image = useQueueItemProgressImage(session.queueItemId, session.itemIndex);
+ const progress = useItemProgress(session.backendItemId);
+ const deviceLabel = useDeviceLabel(progress?.device);
+ const percentage = getDeterminateProgressPercent(progress?.percentage);
+ const isRunning = session.state === 'running';
+ const name =
+ session.itemCount > 1
+ ? t('widgets.gallery.progressSession', {
+ index: session.itemIndex,
+ name: session.label,
+ total: session.itemCount,
+ })
+ : session.label;
+ const status =
+ session.state === 'queued'
+ ? t('widgets.gallery.progressQueued')
+ : session.state === 'settling'
+ ? t('widgets.gallery.progressSettling')
+ : percentage !== null
+ ? `${percentage}%`
+ : progress?.message || t('widgets.gallery.progressPreparing');
+ const label = [
+ name,
+ ...(deviceLabel ? [t('widgets.queue.device.shortLabel', { index: deviceLabel.index })] : []),
+ status,
+ ].join(' · ');
+ const handleClick = useCallback(() => {
+ if (!isRunning) {
+ return;
+ }
+ if (isPinned) {
+ onUnpin?.();
+ } else {
+ onFollow?.(session.id);
+ }
+ }, [isPinned, isRunning, onFollow, onUnpin, session.id]);
+ // Keeps the followed slot in view like the selected item thumb does, and
+ // hands focus back to the preview when the slot finishes under the
+ // keyboard — its element goes with it, and nothing else would take over.
+ const thumbRef = useCallback(
+ (node: HTMLElement | null) => {
+ if (!node) {
+ return;
+ }
+ if (isFollowed) {
+ node.scrollIntoView({ block: 'nearest', inline: 'nearest' });
+ }
+ const region = node.closest<HTMLElement>('[role="region"]');
+
+ // React re-runs this cleanup when `isFollowed` flips while the node is
+ // still mounted — exactly the click that focused it — so only a node
+ // that really left the document gives focus away.
+ return () => {
+ if (document.activeElement === node) {
+ queueMicrotask(() => {
+ if (!node.isConnected) {
+ region?.focus({ preventScroll: true });
+ }
+ });
+ }
+ };
+ },
+ [isFollowed]
+ );
+
+ return (
+ <Box
+ ref={thumbRef}
+ as="button"
+ aria-current={isFollowed || undefined}
+ aria-disabled={!isRunning}
+ aria-label={label}
+ aria-pressed={isRunning ? isPinned : undefined}
+ borderColor={isFollowed ? 'accent.solid' : 'border.subtle'}
+ borderWidth="2px"
+ boxSize={size}
+ data-preview-live-pinned={isPinned || undefined}
+ data-preview-live-thumb={session.id}
+ flexShrink={0}
+ overflow="hidden"
+ position="relative"
+ rounded="sm"
+ tabIndex={isRunning ? 0 : -1}
+ onClick={handleClick}
+ >
+ <StreamingImageFrame
+ fit="cover"
+ h="full"
+ liveImage={progressImageToStreamingSource(image)}
+ shouldAntialiasLiveImage={shouldAntialiasLiveImage}
+ w="full"
+ >
+ {session.state === 'queued' ? <Box bg="bg.subtle" h="full" w="full" /> : <Skeleton h="full" w="full" />}
+ </StreamingImageFrame>
+ <Box
+ bg="bg/85"
+ bottom="0.5"
+ display="flex"
+ p="0.5"
+ pointerEvents="none"
+ position="absolute"
+ right="0.5"
+ rounded="full"
+ >
+ {isPinned ? (
+ <Icon aria-hidden as={PinIcon} boxSize="3" />
+ ) : isRunning ? (
+ <ProgressCircle.Root aria-hidden size="xs" value={percentage}>
+ <ProgressCircle.Circle>
+ <ProgressCircle.Track />
+ <ProgressCircle.Range />
+ </ProgressCircle.Circle>
+ </ProgressCircle.Root>
+ ) : (
+ <Icon aria-hidden as={session.state === 'queued' ? HourglassIcon : CheckIcon} boxSize="3" />
+ )}
+ </Box>
+ </Box>
+ );
+};
+
const FilmstripThumb = ({
item,
isSelected,
@@ -170,6 +358,8 @@ const FilmstripThumb = ({
);
};
+const EMPTY_SESSIONS: readonly QueueProgressSession[] = [];
+
const FILMSTRIP_CONTAIN_CSS = { contain: 'inline-size' } as const;
/** Same touch drag cue as the gallery grid: the source thumb desaturates while dragged. */
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFooter.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFooter.tsx
deleted file mode 100644
index c5947257d5..0000000000
--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFooter.tsx
+++ /dev/null
@@ -1,44 +0,0 @@
-import type { ReactNode } from 'react';
-
-import { HStack, Stack, Text } from '@chakra-ui/react';
-import { useTranslation } from 'react-i18next';
-
-/** The opaque island a multi-session tile's status footer floats in over its stage. */
-export const PreviewFooterIsland = ({ children }: { children: ReactNode }) => (
- <Stack bg="bg.subtle" borderColor="border.subtle" borderWidth="1px" gap="2" minW="0" p="3" rounded="md" shadow="sm">
- {children}
- </Stack>
-);
-
-/**
- * The footer for one tile in the multi-session grid.
- *
- * A tile has no board position to report and no prev/next to offer, so it
- * spends the same row on the two facts that are specific to it: which device is
- * rendering, and how far along it is. It always names its state — with several
- * sessions racing, a tile saying nothing reads as a stuck one.
- */
-export const PreviewTileFooter = ({ deviceLabel, percent }: { deviceLabel: string | null; percent: number | null }) => {
- const { t } = useTranslation();
- const statusLabel = percent === null ? t('common.generating') : `${percent}%`;
-
- return (
- <PreviewFooterIsland>
- <HStack align="center" gap="1" minW="0">
- {deviceLabel === null ? null : (
- <>
- <Text color="fg.muted" fontSize="2xs" truncate>
- {deviceLabel}
- </Text>
- <Text color="fg.subtle" flexShrink={0} fontSize="2xs">
- ·
- </Text>
- </>
- )}
- <Text color="fg.muted" flexShrink={0} fontSize="2xs" fontVariantNumeric="tabular-nums">
- {statusLabel}
- </Text>
- </HStack>
- </PreviewFooterIsland>
- );
-};
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewMediaChrome.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewMediaChrome.browser.test.tsx
index 03a7a16f55..8d258c82a2 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewMediaChrome.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewMediaChrome.browser.test.tsx
@@ -1,5 +1,6 @@
/* oxlint-disable react-perf/jsx-no-new-array-as-prop, react-perf/jsx-no-new-function-as-prop, react-perf/jsx-no-new-object-as-prop */
import type { GalleryImageItem, GalleryVideoItem } from '@features/gallery';
+import type { QueueProgressSession } from '@features/queue/contracts';
import type * as queueDevicesModule from '@features/queue/devices';
import type { ImageActions } from '@workbench/image-actions';
@@ -15,7 +16,6 @@ import { page } from 'vitest/browser';
import { PreviewActionStrip } from './PreviewActionStrip';
import { PreviewFilmstrip } from './PreviewFilmstrip';
-import { LivePreviewTile } from './PreviewWidgetView';
const sharedImage: GalleryImageItem = {
boardId: 'none',
@@ -96,6 +96,12 @@ void i18n.use(initReactI18next).init({
common: { countOfTotal: '{{count}} of {{total}}', edit: 'Edit', generating: 'Generating' },
widgets: {
canvas: { import: { control: 'Control Layer', raster: 'Raster Layer' } },
+ gallery: {
+ progressPreparing: 'Preparing',
+ progressQueued: 'Queued',
+ progressSession: '{{name}} {{index}}/{{total}}',
+ progressSettling: 'Finishing',
+ },
preview: {
copyCurrentFrame: 'Copy Current Frame',
details: 'Details',
@@ -457,81 +463,180 @@ describe('Preview mixed media actions', () => {
});
});
-describe('Multi-session live preview tiles', () => {
- const placeholder = {
- backendItemId: 1,
- boardId: 'none',
- label: 'Generate',
- sourceId: 'generate' as const,
- itemCount: 1,
- state: 'running' as const,
+describe('PreviewFilmstrip live sessions', () => {
+ const session = (id: string, state: QueueProgressSession['state'], backendItemId = 1): QueueProgressSession => ({
+ backendItemId,
height: 512,
- id: 'queue-1:0',
- itemIndex: 0,
+ id,
+ itemCount: 2,
+ itemIndex: Number(id.split(':')[1]),
+ label: 'Generate',
queueItemId: 'queue-1',
+ sourceId: 'generate',
+ state,
width: 512,
- };
+ });
+
+ it('leads the strip with one thumb per slot, naming device and progress, and follows a running one on click', async () => {
+ mocks.itemProgress = { device: 'cuda:1', percentage: 0.4 };
+ mocks.deviceLabel = { index: 1 };
+ const onFollowSession = vi.fn();
+ const onUnpinSession = vi.fn();
- const renderTile = async () => {
+ // A single board item would hide the strip; the live sessions earn it.
await render(
<DndContext>
- <LivePreviewTile placeholder={placeholder} shouldAntialiasProgressImage={false} />
+ <PreviewFilmstrip
+ density="full"
+ followedSessionId="queue-1:1"
+ items={[sharedImage]}
+ selectedItemKey={null}
+ sessions={[session('queue-1:1', 'running'), session('queue-1:2', 'queued', 2)]}
+ onFollowSession={onFollowSession}
+ onSelect={() => undefined}
+ onUnpinSession={onUnpinSession}
+ />
</DndContext>
);
- return Array.from(host!.querySelectorAll<HTMLElement>('p')).map((element) => element.textContent ?? '');
- };
+ const thumbs = [...host!.querySelectorAll<HTMLButtonElement>('[data-preview-live-thumb]')];
+ expect(thumbs.map((thumb) => thumb.getAttribute('aria-label'))).toEqual([
+ 'Generate 1/2 · GPU 1 · 40%',
+ 'Generate 2/2 · GPU 1 · Queued',
+ ]);
+ // Live thumbs come first; the item thumb follows them.
+ expect(host!.querySelector('button')).toBe(thumbs[0]);
+ expect(thumbs[0]?.getAttribute('aria-current')).toBe('true');
+ expect(thumbs[1]?.getAttribute('aria-current')).toBeNull();
+ expect(thumbs[1]?.getAttribute('aria-disabled')).toBe('true');
+
+ await interact(() => thumbs[1]?.click());
+ expect(onFollowSession).not.toHaveBeenCalled();
+ await interact(() => thumbs[0]?.click());
+ expect(onFollowSession).toHaveBeenCalledExactlyOnceWith('queue-1:1');
+ expect(onUnpinSession).not.toHaveBeenCalled();
+ });
- it('reports percent from the footer when no device label is available', async () => {
- mocks.itemProgress = { device: null, percentage: 0.4 };
+ it('reads as a pressed toggle while pinned and unpins on the next click', async () => {
+ mocks.itemProgress = { device: null, percentage: null };
mocks.deviceLabel = null;
+ const onFollowSession = vi.fn();
+ const onUnpinSession = vi.fn();
- const footerText = await renderTile();
+ await render(
+ <DndContext>
+ <PreviewFilmstrip
+ density="compact"
+ followedSessionId="queue-1:1"
+ isSessionPinned
+ items={[]}
+ selectedItemKey={null}
+ sessions={[session('queue-1:1', 'running'), session('queue-1:2', 'settling', 2)]}
+ onFollowSession={onFollowSession}
+ onSelect={() => undefined}
+ onUnpinSession={onUnpinSession}
+ />
+ </DndContext>
+ );
- expect(footerText).toContain('40%');
+ const [pinned, settling] = [...host!.querySelectorAll<HTMLButtonElement>('[data-preview-live-thumb]')];
+ // A silent thumb reads as a stuck one, so it says it is preparing.
+ expect(pinned?.getAttribute('aria-label')).toBe('Generate 1/2 · Preparing');
+ expect(pinned?.getAttribute('aria-pressed')).toBe('true');
+ // The pin shows in place of the progress ring, so the next click reads as "unpin".
+ expect(pinned?.hasAttribute('data-preview-live-pinned')).toBe(true);
+ expect(pinned?.querySelector('[data-scope="progress-circle"]')).toBeNull();
+ expect(settling?.hasAttribute('data-preview-live-pinned')).toBe(false);
+ expect(settling?.getAttribute('aria-label')).toBe('Generate 2/2 · Finishing');
+ expect(settling?.getAttribute('aria-pressed')).toBeNull();
+
+ await interact(() => pinned?.click());
+ expect(onUnpinSession).toHaveBeenCalledOnce();
+ expect(onFollowSession).not.toHaveBeenCalled();
});
- it('names the device alongside percent once the label resolves', async () => {
- mocks.itemProgress = { device: 'cuda:1', percentage: 0.4 };
- mocks.deviceLabel = { index: 1 };
+ it('earns the strip for a lone item only while a session is live', async () => {
+ mocks.itemProgress = null;
+ mocks.deviceLabel = null;
+ const strip = () => host!.querySelector('[data-preview-filmstrip]');
- const footerText = await renderTile();
+ await render(
+ <DndContext>
+ <PreviewFilmstrip density="full" items={[sharedImage]} selectedItemKey={null} onSelect={() => undefined} />
+ </DndContext>
+ );
+ expect(strip()).toBeNull();
- expect(footerText).toContain('GPU 1');
- expect(footerText).toContain('40%');
+ await render(
+ <DndContext>
+ <PreviewFilmstrip
+ density="full"
+ items={[sharedImage]}
+ selectedItemKey={null}
+ sessions={[session('queue-1:1', 'running')]}
+ onSelect={() => undefined}
+ />
+ </DndContext>
+ );
+ expect(strip()).not.toBeNull();
});
- it('still declares itself live before progress is quantified', async () => {
- // A silent tile reads as a stuck one when several sessions race, so the
- // footer says "Generating" rather than going blank.
- mocks.itemProgress = { device: null, percentage: null };
+ it('hands focus back to the preview region when the focused live thumb finishes', async () => {
+ mocks.itemProgress = { device: null, percentage: 0.5 };
mocks.deviceLabel = null;
+ const strip = (sessions: QueueProgressSession[]) => (
+ // The preview's navigation boundary is a focusable region too.
+ // oxlint-disable-next-line jsx-a11y/no-noninteractive-tabindex
+ <div role="region" tabIndex={0} data-testid="preview-region">
+ <DndContext>
+ <PreviewFilmstrip
+ density="full"
+ items={[sharedImage, sharedVideo]}
+ selectedItemKey={null}
+ sessions={sessions}
+ onSelect={() => undefined}
+ />
+ </DndContext>
+ </div>
+ );
- const footerText = await renderTile();
+ await render(strip([session('queue-1:1', 'running')]));
+ const thumb = host!.querySelector<HTMLButtonElement>('[data-preview-live-thumb]')!;
+ await interact(() => thumb.focus());
+ expect(document.activeElement).toBe(thumb);
- expect(footerText).toContain('Generating');
+ await render(strip([]));
+ await interact(() => undefined);
+ expect(document.activeElement).toBe(host!.querySelector('[data-testid="preview-region"]'));
});
- it('carries no caption over the image itself', async () => {
- // The frame must be indistinguishable from a finished item's, so that
- // nothing moves at the moment denoising ends.
- mocks.itemProgress = { device: 'cuda:1', percentage: 0.4 };
- mocks.deviceLabel = { index: 1 };
-
- await render(
- <DndContext>
- <LivePreviewTile placeholder={placeholder} shouldAntialiasProgressImage={false} />
- </DndContext>
+ it('keeps focus on a thumb that becomes the followed one', async () => {
+ mocks.itemProgress = { device: null, percentage: 0.5 };
+ mocks.deviceLabel = null;
+ const strip = (followedSessionId: string | null) => (
+ // oxlint-disable-next-line jsx-a11y/no-noninteractive-tabindex
+ <div role="region" tabIndex={0}>
+ <DndContext>
+ <PreviewFilmstrip
+ density="full"
+ followedSessionId={followedSessionId}
+ items={[]}
+ selectedItemKey={null}
+ sessions={[session('queue-1:1', 'running'), session('queue-1:2', 'running', 2)]}
+ onSelect={() => undefined}
+ />
+ </DndContext>
+ </div>
);
- const image = host!.querySelector('img');
- const captionInsideFrame = image?.closest('div')?.querySelector('p, span');
+ await render(strip('queue-1:1'));
+ const second = host!.querySelector<HTMLButtonElement>('[data-preview-live-thumb="queue-1:2"]')!;
+ await interact(() => second.focus());
- expect(image).not.toBeNull();
- expect(captionInsideFrame).toBeNull();
+ // The click that follows it re-renders it as current; focus must stay put.
+ await render(strip('queue-1:2'));
+ await interact(() => undefined);
+ expect(document.activeElement).toBe(second);
+ expect(second.getAttribute('aria-current')).toBe('true');
});
});
-
-vi.mock('./livePreviewFollow', () => ({
- useLivePreviewFollow: () => ({ sessions: [], pinnedSessionId: null, pin: vi.fn(), showAll: vi.fn() }),
-}));
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewNavigation.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewNavigation.browser.test.tsx
index bcc2a1eff2..a66b17013e 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewNavigation.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewNavigation.browser.test.tsx
@@ -1633,7 +1633,9 @@ describe('preview keyboard navigation boundary', () => {
await render();
- expect(host?.querySelectorAll<HTMLImageElement>('img[src^="data:image/png"]')).toHaveLength(1);
+ expect(
+ host?.querySelectorAll<HTMLImageElement>('img[src^="data:image/png"]:not([data-preview-filmstrip] img)')
+ ).toHaveLength(1);
});
it("shows the followed slot's own frame even when the store-wide latest frame is gone", async () => {
@@ -1693,7 +1695,7 @@ describe('preview keyboard navigation boundary', () => {
expect(host?.querySelector<HTMLImageElement>('img[src="data:image/png;base64,slot-one"]')).toBeNull();
});
- it('pins one concurrent session, returns to overview, and continues after the pinned session settles', async () => {
+ it('keeps every concurrent session in the filmstrip, follows the newest session, and pins on request', async () => {
mocks.project.queue.items = [{ ...queueItem, backendItemIds: [1, 2] }];
mocks.project.settings.showProgressImagesInViewer = true;
mocks.runningProgressTargets = [
@@ -1702,17 +1704,44 @@ describe('preview keyboard navigation boundary', () => {
];
mocks.slotProgressImage = { dataUrl: 'data:image/png;base64,live', width: 64, height: 64 };
await render();
- expect(host?.querySelectorAll('img[src^="data:image/png"]')).toHaveLength(2);
- await act(() => followControls.pin('queue-item-live:2'));
- expect(host?.querySelectorAll('img[src^="data:image/png"]')).toHaveLength(1);
- expect(followControls.pinnedSessionId).toBe('queue-item-live:2');
+ const liveThumbs = () => [...host!.querySelectorAll<HTMLElement>('[data-preview-live-thumb]')];
+ const followedThumb = () =>
+ host!.querySelector<HTMLElement>('[data-preview-live-thumb][aria-current="true"]')?.dataset.previewLiveThumb;
+ // One stage, two thumbs: never a grid. The session that started last is on the stage.
+ expect(liveThumbs()).toHaveLength(2);
+ expect(host?.querySelectorAll('[data-preview-filmstrip] img[src^="data:image/png"]')).toHaveLength(2);
+ expect(followedThumb()).toBe('queue-item-live:2');
+
+ // Frames from the other slot do not move the stage: following the latest
+ // frame is what used to flip it several times a second.
+ mocks.useProgressImage.mockReturnValue({
+ dataUrl: 'data:image/png;base64,live',
+ height: 64,
+ target: { itemIndex: 1, queueItemId: queueItem.id },
+ width: 64,
+ });
+ await rerender();
+ expect(followedThumb()).toBe('queue-item-live:2');
+ expect(followControls.pinnedSessionId).toBeNull();
+
+ await act(() => followControls.pin('queue-item-live:1'));
+ expect(followedThumb()).toBe('queue-item-live:1');
+ expect(host!.querySelector('[data-preview-live-thumb="queue-item-live:1"]')?.getAttribute('aria-pressed')).toBe(
+ 'true'
+ );
+ expect(host!.querySelector<HTMLElement>('[data-preview-live-pinned]')?.dataset.previewLiveThumb).toBe(
+ 'queue-item-live:1'
+ );
await act(() => followControls.showAll());
- expect(host?.querySelectorAll('img[src^="data:image/png"]')).toHaveLength(2);
+ expect(followedThumb()).toBe('queue-item-live:2');
+ expect(host!.querySelector('[data-preview-live-pinned]')).toBeNull();
+
await act(() => followControls.pin('queue-item-live:2'));
mocks.runningProgressTargets = [{ queueItemId: queueItem.id, itemIndex: 1 }];
await rerender();
+ // The pinned session settled, so the pin releases and the stage moves on.
expect(followControls.pinnedSessionId).toBeNull();
- expect(host?.querySelectorAll('img[src^="data:image/png"]')).toHaveLength(1);
+ expect(followedThumb()).toBe('queue-item-live:1');
});
it('keeps live previews available during similarity search and temporary comparison override', async () => {
@@ -1724,7 +1753,7 @@ describe('preview keyboard navigation boundary', () => {
values.semanticImageQuery = { kind: 'text', query: 'blue sky' };
values.compareImage = mocks.recentImages[1];
await render();
- expect(host?.querySelectorAll('img[src^="data:image/png"]')).toHaveLength(1);
+ expect(host?.querySelectorAll('img[src^="data:image/png"]:not([data-preview-filmstrip] img)')).toHaveLength(1);
await act(() => followControls.pin('queue-item-live:1'));
mocks.project.id = 'project-2';
mocks.project.queue.items = [];
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx
index 82c354bc0b..567f9b3cbe 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx
@@ -2,7 +2,7 @@ import type { SystemStyleObject } from '@chakra-ui/react';
import type { QueueActiveSession, QueueItem } from '@features/queue/contracts';
import type { WidgetViewProps } from '@workbench/widgetContracts';
-import { Box, Flex, SimpleGrid, Stack, Text } from '@chakra-ui/react';
+import { Box, Flex, Stack, Text } from '@chakra-ui/react';
import { useDndMonitor, type DragEndEvent } from '@dnd-kit/core';
import {
galleryImages,
@@ -30,16 +30,12 @@ import {
} from '@features/gallery/contracts';
import { galleryBoardsOptions } from '@features/gallery/queries';
import { createGenerateFormValuesSelector } from '@features/generation/react';
-import { getDeterminateProgressPercent } from '@features/queue/contracts';
-import { useDeviceLabel } from '@features/queue/devices';
import {
consumeQueueItemSwapProgressImage,
- useItemProgress,
useQueueItemBridgeProgressImage,
useQueueItemProgressImage,
useQueueItemSwapProgressImage,
} from '@features/queue/react';
-import { Button } from '@platform/ui';
import {
imageUrlToStreamingSource,
progressImageToStreamingSource,
@@ -72,7 +68,6 @@ import { PreviewCompare } from './PreviewCompare';
import { resolvePreviewCompareDrop } from './previewCompareDnd';
import { usePreviewDensity, type PreviewDensity } from './previewDensity';
import { PreviewFilmstrip } from './PreviewFilmstrip';
-import { PreviewTileFooter } from './PreviewFooter';
import {
PreviewFrame,
type PreviewMediaSource,
@@ -144,15 +139,6 @@ const getBoardName = (
const selectGenerateRecallValues = createGenerateFormValuesSelector();
-/**
- * A multi-session tile floats its status island over its stage and reserves
- * that much bottom padding for it. Its stage padding stays compact for the
- * same reason the grid exists at all: at four sessions each cell is a quarter
- * of the widget.
- */
-const PREVIEW_TILE_OVERLAY_RESERVE = '3.25rem';
-const PREVIEW_TILE_STAGE_PADDING = '3';
-
/** Pinned to the floating window body's top edge, under the title bar's divider. */
const FLOATING_RAIL_SX: SystemStyleObject = {
display: 'flex',
@@ -193,11 +179,6 @@ export const PreviewWidgetView = ({ region, runtime }: WidgetViewProps) => {
[galleryValues.semanticImageQuery]
);
const selectedItemKey = selectedItem ? toGalleryItemKey(selectedItem) : null;
- const liveGalleryPlaceholders = useMemo(
- () => livePreview.sessions.filter((session) => session.state === 'running'),
- [livePreview.sessions]
- );
- const pinnedSession = livePreview.sessions.find((session) => session.id === livePreview.pinnedSessionId);
const activeGalleryPlaceholder =
livePreview.sessions.find((session) => session.id === livePreview.followedSessionId) ?? null;
const shouldFollowLive = activeGalleryPlaceholder !== null;
@@ -208,16 +189,6 @@ export const PreviewWidgetView = ({ region, runtime }: WidgetViewProps) => {
toGalleryItemKey({ kind: 'image', name: compareImage.imageName }) !== selectedItemKey;
const { t } = useTranslation();
const navigationBoundaryRef = useRef<HTMLDivElement | null>(null);
- const overviewButtonRef = useCallback((element: HTMLButtonElement | null) => {
- if (!element) {
- return;
- }
- return () => {
- if (document.activeElement === element) {
- queueMicrotask(() => navigationBoundaryRef.current?.focus({ preventScroll: true }));
- }
- };
- }, []);
const loupeControlsRef = useRef<PreviewLoupeControls | null>(null);
// The header's zoom commands close over the controls ref, so they are stable
// per mount; the readout itself streams through `previewStageStore`.
@@ -485,6 +456,37 @@ export const PreviewWidgetView = ({ region, runtime }: WidgetViewProps) => {
// action strip's image + actions) for the widget frame; the chrome renders
// outside this view, so an external store is the sync channel. Cleared on
// unmount so stale chrome never outlives us.
+ const filmstrip = useMemo<PreviewFilmstripProps | null>(
+ () =>
+ isFilmstripVisible && density !== 'minimal'
+ ? {
+ followedSessionId: livePreview.followedSessionId,
+ isSessionPinned: livePreview.pinnedSessionId !== null,
+ items: boardItems,
+ onCompare: compareFilmstripItem,
+ onContextMenu: openFilmstripItemContextMenu,
+ onFollowSession: livePreview.follow,
+ onSelect: selectPreviewItem,
+ onUnpinSession: livePreview.showAll,
+ sessions: livePreview.gallerySessions,
+ shouldAntialiasLiveImage: antialiasProgressImages,
+ }
+ : null,
+ [
+ antialiasProgressImages,
+ boardItems,
+ compareFilmstripItem,
+ density,
+ isFilmstripVisible,
+ livePreview.follow,
+ livePreview.followedSessionId,
+ livePreview.gallerySessions,
+ livePreview.pinnedSessionId,
+ livePreview.showAll,
+ openFilmstripItemContextMenu,
+ selectPreviewItem,
+ ]
+ );
const hasHeaderItem = !shouldFollowLive && contextMenuItem !== null;
useEffect(() => {
previewHeaderStore.set({
@@ -602,34 +604,12 @@ export const PreviewWidgetView = ({ region, runtime }: WidgetViewProps) => {
w="full"
onKeyDown={handleNavigationKeyDown}
>
- {shouldFollowLive && pinnedSession ? (
- <Button
- ref={overviewButtonRef}
- alignSelf="start"
- flexShrink={0}
- // Clears the centre region's floating header islands, which
- // otherwise sit on top of the first row of the widget body.
- ms="2"
- mt="var(--wb-center-chrome-inset, 0px)"
- size="2xs"
- variant="ghost"
- onClick={livePreview.showAll}
- >
- {t('widgets.preview.showAllActivePreviews')}
- </Button>
- ) : null}
- {shouldFollowLive && !pinnedSession && liveGalleryPlaceholders.length > 1 ? (
- <LivePreviewTiles
- placeholders={liveGalleryPlaceholders}
- shouldAntialiasProgressImage={antialiasProgressImages}
- />
- ) : shouldFollowLive && activeGalleryPlaceholder ? (
+ {shouldFollowLive && activeGalleryPlaceholder ? (
<LivePreview
density={density}
- filmstripItems={isFilmstripVisible && density !== 'minimal' ? boardItems : null}
+ filmstrip={filmstrip}
placeholder={activeGalleryPlaceholder}
shouldAntialiasProgressImage={antialiasProgressImages}
- onSelectItem={selectPreviewItem}
/>
) : selectedItem ? (
<>
@@ -646,28 +626,22 @@ export const PreviewWidgetView = ({ region, runtime }: WidgetViewProps) => {
) : selectedItem.kind === 'image' ? (
<SelectedImagePreview
density={density}
- filmstripItems={isFilmstripVisible && density !== 'minimal' ? boardItems : null}
+ filmstrip={filmstrip}
isItemCurrent={isItemCurrent}
item={selectedItem}
loupeControlsRef={loupeControlsRef}
shouldAntialiasProgressImage={antialiasProgressImages}
- onCompareItem={compareFilmstripItem}
onContextMenu={openItemContextMenu}
- onItemContextMenu={openFilmstripItemContextMenu}
- onSelectItem={selectPreviewItem}
/>
) : (
<SelectedVideoPreview
density={density}
- filmstripItems={isFilmstripVisible && density !== 'minimal' ? boardItems : null}
+ filmstrip={filmstrip}
isItemCurrent={isItemCurrent}
item={selectedItem}
videoControllerRef={videoControllerRef}
onContextMenu={openItemContextMenu}
onCopyAvailabilityChange={handleVideoCopyAvailabilityChange}
- onCompareItem={compareFilmstripItem}
- onItemContextMenu={openFilmstripItemContextMenu}
- onSelectItem={selectPreviewItem}
/>
)}
<ImageContextMenu
@@ -763,18 +737,17 @@ const SelectedVideoPreview = ({
);
};
+/** The filmstrip's inputs, or null when the strip is hidden. */
+type PreviewFilmstripProps = Omit<Parameters<typeof PreviewFilmstrip>[0], 'density' | 'selectedItemKey'>;
+
interface SelectedMediaPreviewProps {
density: PreviewDensity;
- /** Board thumbnails for the filmstrip, or null when the strip is hidden. */
- filmstripItems: GalleryItem[] | null;
+ filmstrip: PreviewFilmstripProps | null;
isItemCurrent: (itemKey: GalleryItemKey) => boolean;
item: GalleryItem;
loupeControlsRef?: Ref<PreviewLoupeControls>;
onCopyAvailabilityChange?: (itemKey: GalleryItemKey, isAvailable: boolean) => void;
- onCompareItem: (item: GalleryItem) => void;
onContextMenu: (x: number, y: number) => void;
- onItemContextMenu: (item: GalleryItem, x: number, y: number) => void;
- onSelectItem: (item: GalleryItem) => void;
videoControllerRef?: Ref<PreviewVideoFrameController>;
}
@@ -784,7 +757,9 @@ interface SelectedMediaPreviewProps {
* toggling the strip refits the media rather than covering it. Live and
* finished renders MUST pass through the same scaffold — the denoise→done
* boundary may change only the pixels inside the frame, never the geometry
- * around it.
+ * around it. Several live sessions are the filmstrip's leading thumbs, never
+ * a grid: the stage shows one of them large and the strip keeps the rest in
+ * reach.
*/
const PreviewMediaScaffold = ({ children }: { children: ReactNode }) => (
<Flex direction="column" h="full" minH="0" position="relative" w="full">
@@ -792,20 +767,13 @@ const PreviewMediaScaffold = ({ children }: { children: ReactNode }) => (
</Flex>
);
-/** The floating island a multi-session tile's status footer sits in. */
-const PreviewOverlayStack = ({ children }: { children: ReactNode }) => (
- <Stack bottom="2" gap="2" insetX="2" position="absolute" zIndex="1">
- {children}
- </Stack>
-);
-
const getMediaStagePadding = (density: PreviewDensity): string => (density === 'full' ? '6' : '3');
const { setStageElement, setZoom: setZoomReadout } = previewStageStore;
const SelectedMediaPreview = ({
density,
dragItem,
- filmstripItems,
+ filmstrip,
frameHeight,
frameWidth,
holdSource,
@@ -816,10 +784,7 @@ const SelectedMediaPreview = ({
onSourceLoaded,
shouldAntialiasHoldImage,
source,
- onCompareItem,
onContextMenu,
- onItemContextMenu,
- onSelectItem,
videoControllerRef,
}: SelectedMediaPreviewProps & {
dragItem?: GalleryItemRef;
@@ -853,16 +818,7 @@ const SelectedMediaPreview = ({
onContextMenu={onContextMenu}
/>
</Flex>
- {filmstripItems ? (
- <PreviewFilmstrip
- density={density}
- items={filmstripItems}
- selectedItemKey={toGalleryItemKey(item)}
- onCompare={onCompareItem}
- onContextMenu={onItemContextMenu}
- onSelect={onSelectItem}
- />
- ) : null}
+ {filmstrip ? <PreviewFilmstrip {...filmstrip} density={density} selectedItemKey={toGalleryItemKey(item)} /> : null}
</PreviewMediaScaffold>
);
@@ -874,16 +830,14 @@ const SelectedMediaPreview = ({
*/
const LivePreview = ({
density,
- filmstripItems,
+ filmstrip,
placeholder,
shouldAntialiasProgressImage,
- onSelectItem,
}: {
density: PreviewDensity;
- filmstripItems: GalleryItem[] | null;
+ filmstrip: PreviewFilmstripProps | null;
placeholder: QueueActiveSession;
shouldAntialiasProgressImage: boolean;
- onSelectItem: (item: GalleryItem) => void;
}) => {
// The followed slot's own frame, not the store-wide latest: with two slots
// live (a long video next to a quick image batch) the latest belongs to
@@ -920,97 +874,11 @@ const LivePreview = ({
source={source}
variant="framed"
/>
- {filmstripItems ? (
- <PreviewFilmstrip density={density} items={filmstripItems} selectedItemKey={null} onSelect={onSelectItem} />
- ) : null}
+ {filmstrip ? <PreviewFilmstrip {...filmstrip} density={density} selectedItemKey={null} /> : null}
</PreviewMediaScaffold>
);
};
-/**
- * One tile in the multi-session grid.
- *
- * Subscribes to its own slot's progress image rather than receiving it from the
- * parent, so a frame from one GPU's session re-renders only that tile.
- */
-export const LivePreviewTile = ({
- placeholder,
- shouldAntialiasProgressImage,
-}: {
- placeholder: QueueActiveSession;
- shouldAntialiasProgressImage: boolean;
-}) => {
- const { t } = useTranslation();
- const progressImage = useQueueItemProgressImage(placeholder.queueItemId, placeholder.itemIndex);
- // Keyed by the backend item id, not the local one: two slots of the same batch can
- // be running on two GPUs, and the local-keyed store holds one entry for both.
- const itemProgress = useItemProgress(placeholder.backendItemId);
- const deviceLabel = useDeviceLabel(itemProgress?.device);
- const previewImage = useStreamingImageSource({
- liveImage: progressImageToStreamingSource(progressImage),
- });
- const source = useMemo<PreviewMediaSource | null>(
- () =>
- previewImage
- ? {
- itemKey: `image:live:${placeholder.id}`,
- kind: 'image',
- source: previewImage,
- }
- : null,
- [placeholder.id, previewImage]
- );
-
- const percent = getDeterminateProgressPercent(itemProgress?.percentage);
- // Device identity and progress read from the footer, not from a badge over
- // the image: a tile is the same media card as any other preview surface, and
- // the one thing that must never differ between them is the frame itself.
- const tileDeviceLabel = deviceLabel ? t('widgets.queue.device.shortLabel', { index: deviceLabel.index }) : null;
-
- return (
- <PreviewMediaScaffold>
- <PreviewFrame
- frameHeight={previewImage?.height ?? placeholder.height}
- frameWidth={previewImage?.width ?? placeholder.width}
- isLive
- padding={PREVIEW_TILE_STAGE_PADDING}
- paddingBottom={PREVIEW_TILE_OVERLAY_RESERVE}
- shouldAntialiasLiveImage={shouldAntialiasProgressImage}
- source={source}
- variant="framed"
- />
- <PreviewOverlayStack>
- <PreviewTileFooter deviceLabel={tileDeviceLabel} percent={percent} />
- </PreviewOverlayStack>
- </PreviewMediaScaffold>
- );
-};
-
-/**
- * Side-by-side previews for concurrent sessions (multi-GPU).
- *
- * Only mounted for two or more live slots; a single session keeps the full-size
- * single-frame preview so nothing changes on a single-GPU install. The grid is a
- * plain auto-fit so two GPUs sit side by side and four wrap to a 2×2.
- */
-export const LivePreviewTiles = ({
- placeholders,
- shouldAntialiasProgressImage,
-}: {
- placeholders: QueueActiveSession[];
- shouldAntialiasProgressImage: boolean;
-}) => (
- <SimpleGrid gap="2" h="full" minH="0" columns={placeholders.length > 2 ? 2 : placeholders.length}>
- {placeholders.map((placeholder) => (
- <LivePreviewTile
- key={placeholder.id}
- placeholder={placeholder}
- shouldAntialiasProgressImage={shouldAntialiasProgressImage}
- />
- ))}
- </SimpleGrid>
-);
-
const EmptyPreview = () => {
const { t } = useTranslation();
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/livePreviewFollow.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/livePreviewFollow.tsx
index cce8c53069..50ea9af4f1 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/livePreviewFollow.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/livePreviewFollow.tsx
@@ -16,9 +16,10 @@ interface LivePreviewFollow {
gallerySessions: QueueProgressSession[];
pinnedSessionId: string | null;
/**
- * The session on screen while live-follow is on — pinned, else the first
- * running, else the first settling, in the gallery's tile order — or null.
- * Gallery and Preview both step from it, so it is decided once, here.
+ * The session on screen while live-follow is on — pinned, else the running
+ * session that started last, else the first settling, in the gallery's tile
+ * order — or null. Gallery and Preview both step from it, so it is decided
+ * once, here.
*/
followedSessionId: string | null;
/** Turns live-follow on and pins `sessionId`: a tile click, or an arrow step onto a tile. */
@@ -59,7 +60,16 @@ export const LivePreviewFollowProvider = ({ children }: { children: ReactNode })
setSelection({ projectId, sessionId: null });
}
const pinnedSessionId = isStale ? null : selection.sessionId;
- const followedSessionId = enabled ? (getFollowedProgressSession(gallerySessions, pinnedSessionId)?.id ?? null) : null;
+ // With several GPUs the stage follows the newest running session (highest
+ // backend item id — start order for the FIFO queue), so a busy box keeps the
+ // newest work in view without anyone choosing, and only moves at session
+ // boundaries. Following whichever slot stepped last would flip the stage
+ // several times a second (see activeProgressTargetStore). A pin wins.
+ const newestRunningSessionId = sessions.filter((session) => session.state === 'running').at(-1)?.id ?? null;
+ const preferredSessionId = pinnedSessionId ?? newestRunningSessionId;
+ const followedSessionId = enabled
+ ? (getFollowedProgressSession(gallerySessions, preferredSessionId)?.id ?? null)
+ : null;
const { account } = useWorkbenchCommands();
const value = useMemo<LivePreviewFollow>(
() => ({