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.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
feat(preview): live progress readout, reveal window, and neighbor preloading
joshistoast914588dafe8f
diff --git a/invokeai/frontend/webv2/src/workbench/backend/queueCoordinator.ts b/invokeai/frontend/webv2/src/workbench/backend/queueCoordinator.tsindex 71795c3ca5..e85810f4e6 100644--- a/invokeai/frontend/webv2/src/workbench/backend/queueCoordinator.ts+++ b/invokeai/frontend/webv2/src/workbench/backend/queueCoordinator.ts@@ -35,6 +35,7 @@ import { modelLoadStore } from './modelLoadStore';import { nodeExecutionStore, type NodeExecutionSink } from './nodeExecutionStore';import { progressImageStore, type ProgressImageSink, type ProgressImageTarget } from './progressImageStore';import { queueItemProgressStore, type QueueItemProgressSink } from './progressStore';+import { revealHoldStore, type RevealHoldSink } from './revealHoldStore';const GALLERY_REFRESH_COALESCE_MS = 400;const SAFETY_SWEEP_INTERVAL_MS = 30_000;@@ -173,6 +174,7 @@ export const createQueueCoordinator = (nodeExecution?: NodeExecutionSink;progress?: QueueItemProgressSink;progressImage?: ProgressImageSink;+ revealHold?: RevealHoldSink;sweepIntervalMs?: number;}): QueueCoordinator => {@@ -181,6 +183,7 @@ export const createQueueCoordinator = (const progress = options.progress ?? queueItemProgressStore;const nodeExecution = options.nodeExecution ?? nodeExecutionStore;const progressImage = options.progressImage ?? progressImageStore;+ const revealHold = options.revealHold ?? revealHoldStore;const galleryRefreshCoalesceMs = options.galleryRefreshCoalesceMs ?? GALLERY_REFRESH_COALESCE_MS;const sweepIntervalMs = options.sweepIntervalMs ?? SAFETY_SWEEP_INTERVAL_MS;@@ -287,13 +290,22 @@ export const createQueueCoordinator = (if (outcome.status === 'completed') {const routingPromise = callbacks.onBackendItemComplete?.(wait.localQueueItemId, backendItemId);+ // Reveal window: while sibling items keep generating, hold off the next+ // live frames briefly so the just-finished result is actually seen.+ const settleCompleted = (): void => {+ clearProgressImage();++ if (waits.size > 0) {+ revealHold.arm();+ }+ };if (routingPromise) {void Promise.resolve(routingPromise)- .finally(clearProgressImage)+ .finally(settleCompleted).catch(() => undefined);} else {- clearProgressImage();+ settleCompleted();}}diff --git a/invokeai/frontend/webv2/src/workbench/backend/revealHoldStore.test.ts b/invokeai/frontend/webv2/src/workbench/backend/revealHoldStore.test.tsnew file mode 100644index 0000000000..3848007bd2--- /dev/null+++ b/invokeai/frontend/webv2/src/workbench/backend/revealHoldStore.test.ts@@ -0,0 +1,43 @@+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';++import { isRevealHolding, revealHoldStore, REVEAL_HOLD_DURATION_MS } from './revealHoldStore';++describe('revealHoldStore', () => {+ beforeEach(() => {+ vi.useFakeTimers();+ });++ afterEach(() => {+ revealHoldStore.clear();+ vi.useRealTimers();+ });++ it('holds for the default duration and expires on its own', () => {+ expect(isRevealHolding()).toBe(false);++ revealHoldStore.arm();+ expect(isRevealHolding()).toBe(true);++ vi.advanceTimersByTime(REVEAL_HOLD_DURATION_MS - 1);+ expect(isRevealHolding()).toBe(true);++ vi.advanceTimersByTime(1);+ expect(isRevealHolding()).toBe(false);+ });++ it('re-arming extends the hold instead of expiring early', () => {+ revealHoldStore.arm();+ vi.advanceTimersByTime(REVEAL_HOLD_DURATION_MS - 500);+ revealHoldStore.arm();+ vi.advanceTimersByTime(REVEAL_HOLD_DURATION_MS - 1);+ expect(isRevealHolding()).toBe(true);+ vi.advanceTimersByTime(1);+ expect(isRevealHolding()).toBe(false);+ });++ it('clear releases the hold immediately', () => {+ revealHoldStore.arm();+ revealHoldStore.clear();+ expect(isRevealHolding()).toBe(false);+ });+});diff --git a/invokeai/frontend/webv2/src/workbench/backend/revealHoldStore.ts b/invokeai/frontend/webv2/src/workbench/backend/revealHoldStore.tsnew file mode 100644index 0000000000..2c1f925a68--- /dev/null+++ b/invokeai/frontend/webv2/src/workbench/backend/revealHoldStore.ts@@ -0,0 +1,46 @@+import { createExternalStore } from '@workbench/externalStore';++/**+ * A short "reveal window" after a generation completes: consumers that show+ * live denoise frames suppress them while the hold is armed, so the finished+ * result is actually seen before the next queue item's noise takes over. Armed+ * by the queue coordinator when a backend item completes while more items are+ * still running; expires on its own timer (the timer lives here, not in a+ * component effect).+ */++export const REVEAL_HOLD_DURATION_MS = 2000;++const store = createExternalStore<{ holdUntil: number }>({ holdUntil: 0 });++let timer: ReturnType<typeof setTimeout> | null = null;++export const revealHoldStore = {+ arm(durationMs: number = REVEAL_HOLD_DURATION_MS): void {+ store.patchSnapshot({ holdUntil: Date.now() + durationMs });++ if (timer) {+ clearTimeout(timer);+ }++ timer = setTimeout(() => {+ timer = null;+ store.patchSnapshot({ holdUntil: 0 });+ }, durationMs);+ },+ clear(): void {+ if (timer) {+ clearTimeout(timer);+ timer = null;+ }++ store.patchSnapshot({ holdUntil: 0 });+ },+};++export type RevealHoldSink = Pick<typeof revealHoldStore, 'arm' | 'clear'>;++export const isRevealHolding = (): boolean => store.getSnapshot().holdUntil > Date.now();++/** Whether a reveal hold is currently active. Re-evaluates when the hold arms or expires. */+export const useRevealHold = (): boolean => store.useSelector((snapshot) => snapshot.holdUntil > Date.now());diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFooter.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFooter.tsxindex 1f8d5bc1dc..4ca8e72a92 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFooter.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFooter.tsx@@ -10,6 +10,7 @@ import { useTranslation } from 'react-i18next';import type { PreviewDensity } from './previewDensity';import { PreviewActionStrip } from './PreviewActionStrip';+import { PreviewLiveStatusLine } from './PreviewLiveReadout';/*** The preview's info card: board context ("N of M"), the action strip,@@ -25,6 +26,7 @@ export const PreviewFooter = ({image,isLive,isLoadingBoard,+ liveQueueItemId,onNext,onPrevious,selectedIndex,@@ -37,6 +39,8 @@ export const PreviewFooter = ({image: GeneratedImageContract;isLive: boolean;isLoadingBoard: boolean;+ /** The live run's local queue item id, when a progress readout should replace the dimensions row. */+ liveQueueItemId?: string | null;onNext: () => void;onPrevious: () => void;selectedIndex: number;@@ -92,9 +96,13 @@ export const PreviewFooter = ({<Text color="fg.subtle" fontSize="2xs">{t('widgets.preview.sourceRun', { id: image.sourceQueueItemId })}</Text>- <Text color="fg.subtle" flexShrink={0} fontSize="2xs">- {isLive ? t('common.generating') : `${image.width} x ${image.height}`}- </Text>+ {isLive && density === 'full' && typeof liveQueueItemId === 'string' ? (+ <PreviewLiveStatusLine queueItemId={liveQueueItemId} />+ ) : (+ <Text color="fg.subtle" flexShrink={0} fontSize="2xs">+ {isLive ? t('common.generating') : `${image.width} x ${image.height}`}+ </Text>+ )}</Stack></Stack>);diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrame.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrame.tsxindex 0759e9c91a..501c9fa906 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrame.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrame.tsx@@ -3,6 +3,8 @@ import type { StreamingImageSource } from '@workbench/images/streamingImageSourcimport { Badge, Box, Flex, type SystemStyleObject } from '@chakra-ui/react';import { useCallback, useMemo, type CSSProperties, type MouseEvent, type ReactNode } from 'react';+import { PreviewLiveOverlay } from './PreviewLiveReadout';+/*** The preview's image surface: a dot-grid backdrop with an aspect-fitted,* shadowed frame. Owns everything drawn over the image (live badge, and later@@ -31,6 +33,7 @@ export const PreviewFrame = ({frameWidth,isLive,liveBadgeLabel,+ liveQueueItemId,onContextMenu,padding,shouldAntialiasLiveImage,@@ -43,6 +46,8 @@ export const PreviewFrame = ({frameWidth: number;isLive: boolean;liveBadgeLabel: string;+ /** When set, the static live badge is replaced by the live progress readout for this run. */+ liveQueueItemId?: string | null;onContextMenu?: (x: number, y: number) => void;padding?: string;shouldAntialiasLiveImage: boolean;@@ -69,9 +74,13 @@ export const PreviewFrame = ({[isLive, shouldAntialiasLiveImage]);const liveBadge = isLive ? (- <Badge left="2" pointerEvents="none" position="absolute" size="xs" top="2" variant="solid">- {liveBadgeLabel}- </Badge>+ typeof liveQueueItemId === 'string' ? (+ <PreviewLiveOverlay queueItemId={liveQueueItemId} />+ ) : (+ <Badge left="2" pointerEvents="none" position="absolute" size="xs" top="2" variant="solid">+ {liveBadgeLabel}+ </Badge>+ )) : null;if (variant === 'inset') {diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewLiveReadout.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewLiveReadout.tsxnew file mode 100644index 0000000000..0048e3b11d--- /dev/null+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewLiveReadout.tsx@@ -0,0 +1,67 @@+import { Badge, Box, Text } from '@chakra-ui/react';+import { useQueueItemProgress, type QueueItemProgress } from '@workbench/backend/progressStore';+import { useMemo, type CSSProperties } from 'react';+import { useTranslation } from 'react-i18next';++/**+ * Leaf subscribers for live generation state, kept out of the frame/footer+ * components so per-step progress events only re-render these slivers.+ */++const formatPercent = (percentage: number): string => `${Math.round(percentage * 100)}%`;++const getStepMessage = (progress: QueueItemProgress | null, generatingLabel: string): string => {+ if (!progress) {+ return generatingLabel;+ }++ const message = progress.message || generatingLabel;++ if (progress.totalItemCount && progress.totalItemCount > 1 && progress.activeItemIndex) {+ return `${progress.activeItemIndex}/${progress.totalItemCount} · ${message}`;+ }++ return message;+};++/** Badge + 2px hairline progress bar drawn over the fitted frame while live. */+export const PreviewLiveOverlay = ({ queueItemId }: { queueItemId: string }) => {+ const { t } = useTranslation();+ const progress = useQueueItemProgress(queueItemId);+ const percentage = progress?.percentage ?? null;+ const fillStyle = useMemo<CSSProperties>(+ () => ({ width: percentage === null ? '100%' : `${percentage * 100}%` }),+ [percentage]+ );++ return (+ <>+ <Badge left="2" pointerEvents="none" position="absolute" size="xs" top="2" variant="solid">+ {percentage === null ? t('common.generating') : `${t('common.generating')} · ${formatPercent(percentage)}`}+ </Badge>+ <Box bottom="0" h="2px" left="0" pointerEvents="none" position="absolute" right="0">+ <Box+ bg="accent.solid"+ h="full"+ opacity={percentage === null ? 0.35 : 1}+ style={fillStyle}+ transitionDuration="var(--wb-motion-duration-fast)"+ transitionProperty="width"+ transitionTimingFunction="ease"+ />+ </Box>+ </>+ );+};++/** The footer's live status line ("2/4 · Denoising"), replacing the dimensions row while generating. */+export const PreviewLiveStatusLine = ({ queueItemId }: { queueItemId: string }) => {+ const { t } = useTranslation();+ const progress = useQueueItemProgress(queueItemId);++ return (+ <Text color="fg.subtle" flexShrink={0} fontSize="2xs">+ {getStepMessage(progress, t('common.generating'))}+ </Text>+ );+};diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsxindex 86e9b4ea2a..34f008d9cd 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx@@ -2,7 +2,8 @@import type { GeneratedImageContract, WidgetViewProps } from '@workbench/types';import { Box, Stack, Text } from '@chakra-ui/react';-import { useProgressImage, type ProgressImageSnapshot } from '@workbench/backend/progressImageStore';+import { useProgressImage, type LatestProgressImageSnapshot } from '@workbench/backend/progressImageStore';+import { useRevealHold } from '@workbench/backend/revealHoldStore';import {listGalleryBoards,listGalleryImages,@@ -337,7 +338,11 @@ export const PreviewWidgetView = ({ region, runtime }: WidgetViewProps) => {}, [boardImages, displayBoardId, selectedImage]);const isComparing =selectedImage !== null && compareImage !== null && compareImage.imageName !== selectedImage.imageName;- const shouldShowProgressImage = showProgressImagesInViewer && progressImage !== null && !isComparing;+ // The reveal window suppresses live frames briefly after a completion so the+ // finished result is seen before the next item's noise takes over.+ const isRevealHolding = useRevealHold();+ const shouldShowProgressImage =+ showProgressImagesInViewer && progressImage !== null && !isComparing && !isRevealHolding;const exitCompare = useCallback(() => dispatch({ image: null, type: 'setGalleryCompareImage' }), [dispatch]);const swapCompareImages = useCallback(() => {if (selectedImage && compareImage) {@@ -374,6 +379,19 @@ export const PreviewWidgetView = ({ region, runtime }: WidgetViewProps) => {}, [boardName, selectedImageName]);useEffect(() => () => previewHeaderStore.clear(), []);++ // Warm the browser cache for the board neighbors so arrow-key navigation+ // swaps without a decode flash.+ const previousNeighborUrl = boardImages[selectedIndex - 1]?.imageUrl ?? null;+ const nextNeighborUrl = boardImages[selectedIndex + 1]?.imageUrl ?? null;++ useEffect(() => {+ [previousNeighborUrl, nextNeighborUrl].forEach((url) => {+ if (url) {+ new Image().src = url;+ }+ });+ }, [nextNeighborUrl, previousNeighborUrl]);const executeViewerHotkey = useEffectEvent((commandId: string) => {if (commandId === 'viewer.toggleViewer') {runtime.workbench.closeWidgetInstance(runtime.instanceId);@@ -477,7 +495,7 @@ const SelectedImagePreview = ({density: PreviewDensity;image: GeneratedImageContract;isLoadingBoard: boolean;- progressImage: ProgressImageSnapshot | null;+ progressImage: LatestProgressImageSnapshot | null;selectedIndex: number;shouldAntialiasProgressImage: boolean;onContextMenu: (x: number, y: number) => void;@@ -498,6 +516,7 @@ const SelectedImagePreview = ({const isProgressImage = previewImage?.kind === 'live';const previewWidth = previewImage?.width ?? image.width;const previewHeight = previewImage?.height ?? image.height;+ const liveQueueItemId = progressImage?.target?.queueItemId ?? null;const handleKeyDown = useCallback((event: KeyboardEvent<HTMLDivElement>) => {if (event.key === 'ArrowLeft') {@@ -520,6 +539,7 @@ const SelectedImagePreview = ({frameWidth={previewWidth}isLive={isProgressImage}liveBadgeLabel={t('common.generating')}+ liveQueueItemId={liveQueueItemId}padding={density === 'full' ? '6' : '3'}shouldAntialiasLiveImage={shouldAntialiasProgressImage}source={previewImage}@@ -535,6 +555,7 @@ const SelectedImagePreview = ({image={image}isLive={isProgressImage}isLoadingBoard={isLoadingBoard}+ liveQueueItemId={liveQueueItemId}selectedIndex={selectedIndex}onNext={onNext}onPrevious={onPrevious}@@ -547,7 +568,7 @@ const EmptyPreview = ({progressImage,shouldAntialiasProgressImage,}: {- progressImage: ProgressImageSnapshot | null;+ progressImage: LatestProgressImageSnapshot | null;shouldAntialiasProgressImage: boolean;}) => {const { t } = useTranslation();@@ -561,6 +582,7 @@ const EmptyPreview = ({frameWidth={previewImage?.width ?? 1}isLiveliveBadgeLabel={t('common.generating')}+ liveQueueItemId={progressImage?.target?.queueItemId ?? null}shouldAntialiasLiveImage={shouldAntialiasProgressImage}source={previewImage}variant="inset"