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): show the generation progress rail under the floating window's title bar
Lincoln Stein0f8059b5a8e4
diff --git a/invokeai/frontend/webv2/src/workbench/queue-integration/QueueProgressRail.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/queue-integration/QueueProgressRail.browser.test.tsxnew file mode 100644index 0000000000..56059e9a63--- /dev/null+++ b/invokeai/frontend/webv2/src/workbench/queue-integration/QueueProgressRail.browser.test.tsx@@ -0,0 +1,97 @@+/* oxlint-disable react-perf/jsx-no-new-object-as-prop */+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';++/**+ * The rail is shared between the top bar and the floating preview window, so+ * its show/hide rules are pinned here once: hidden with nothing in flight or+ * the backend away, a sweep while the running item has reported no step yet,+ * a determinate fill once it has.+ */++const state = vi.hoisted(() => ({+ activeItemIds: [] as number[],+ isConnected: true,+ percentage: null as number | null,+ queueItems: [] as { backendItemIds: number[]; id: string; status: string }[],+}));++vi.mock('@features/models', () => ({ useModelLoads: () => [] }));+vi.mock('@features/queue/react', () => ({+ useActiveProgressItemIds: () => state.activeItemIds,+ useItemProgress: (itemId: number | null) => (itemId === null ? null : { percentage: state.percentage }),+}));+vi.mock('@workbench/WorkbenchContext', () => ({+ useActiveProjectSelector: (select: (project: unknown) => unknown) => select({ queue: { items: state.queueItems } }),+ useWorkbenchSelector: (select: (snapshot: unknown) => unknown) =>+ select({ backendConnection: { status: state.isConnected ? 'connected' : 'disconnected' } }),+}));++import { QueueProgressRail } from './QueueProgressRail';++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 render = async () => {+ await act(async () => {+ root?.render(+ <ChakraProvider value={system}>+ <QueueProgressRail css={{ height: '3px', position: 'absolute', top: 0, insetInline: 0 }} />+ </ChakraProvider>+ );+ await Promise.resolve();+ });++ return host?.querySelector<HTMLElement>('[data-queue-progress-rail]') ?? null;+};++const runningItem = { backendItemIds: [7], id: 'item-7', status: 'running' };++beforeEach(() => {+ state.activeItemIds = [];+ state.isConnected = true;+ state.percentage = null;+ state.queueItems = [];+ host = document.createElement('div');+ document.body.append(host);+ root = createRoot(host);+});++afterEach(async () => {+ await act(() => root?.unmount());+ host?.remove();+ host = null;+ root = null;+});++describe('QueueProgressRail', () => {+ it('renders nothing while the queue is idle', async () => {+ expect(await render()).toBeNull();+ });++ it('renders nothing while the backend is away, even with open work', async () => {+ state.queueItems = [runningItem];+ state.activeItemIds = [7];+ state.isConnected = false;++ expect(await render()).toBeNull();+ });++ it('sweeps while the running item has not reported a step, then fills to its fraction', async () => {+ state.queueItems = [runningItem];+ state.activeItemIds = [7];++ const sweeping = await render();+ expect(sweeping).not.toBeNull();+ expect(sweeping?.querySelector('[style*="width"]')).toBeNull();++ state.percentage = 0.4;+ const filling = await render();+ const fill = filling?.querySelector<HTMLElement>('[style*="width"]');+ expect(fill?.style.width).toBe('40%');+ });+});diff --git a/invokeai/frontend/webv2/src/workbench/queue-integration/QueueProgressRail.tsx b/invokeai/frontend/webv2/src/workbench/queue-integration/QueueProgressRail.tsxnew file mode 100644index 0000000000..4e8c14eea1--- /dev/null+++ b/invokeai/frontend/webv2/src/workbench/queue-integration/QueueProgressRail.tsx@@ -0,0 +1,111 @@+import type { SystemStyleObject } from '@chakra-ui/react';+import type { CSSProperties } from 'react';++import { Box } from '@chakra-ui/react';+import { useModelLoads } from '@features/models';+import {+ getProgressRailModel,+ getProgressRailSegmentValue,+ getQueueSummary,+ selectProjectProgressItemIds,+} from '@features/queue/contracts';+import { useActiveProgressItemIds, useItemProgress } from '@features/queue/react';+import { useActiveProjectSelector, useWorkbenchSelector } from '@workbench/WorkbenchContext';+import { useMemo } from 'react';++/**+ * The generation progress rail: one accent-colored segment per running+ * session, sweeping while indeterminate, hidden while nothing is in flight or+ * the backend is away. The top bar pins it along its bottom edge+ * (`TopbarProgressRail`); the floating preview window pins it under its title+ * bar. Placement is the caller's — this component owns only the model and the+ * fills, so the two surfaces cannot drift on when they show or what they show.+ *+ * Sessions divide the width instead of stacking — a hairline cannot stack to+ * four GPUs without growing into the content or dropping below visibility.+ *+ * Not exposed to assistive tech: the queue cluster already owns a throttled+ * live region, and a second announcer would double the chatter.+ */+export const QueueProgressRail = ({ css }: { css: SystemStyleObject }) => {+ const queueItems = useActiveProjectSelector((project) => project.queue.items);+ const isConnected = useWorkbenchSelector((snapshot) => snapshot.backendConnection.status === 'connected');+ const isLoadingModels = useModelLoads().length > 0;+ const activeItemIds = useActiveProgressItemIds();++ const sessionItemIds = useMemo(+ () => selectProjectProgressItemIds(queueItems, activeItemIds),+ [activeItemIds, queueItems]+ );++ const model = getProgressRailModel({+ hasOpenWork: getQueueSummary(queueItems).total > 0,+ isConnected,+ sessionItemIds,+ });++ if (model.kind === 'hidden') {+ return null;+ }++ return (+ <Box aria-hidden="true" css={css} data-queue-progress-rail="">+ {model.kind === 'pending' ? (+ <RailSegment isLoadingModels={isLoadingModels} itemId={null} />+ ) : (+ model.itemIds.map((itemId) => <RailSegment isLoadingModels={isLoadingModels} itemId={itemId} key={itemId} />)+ )}+ </Box>+ );+};++const SEGMENT_SX: SystemStyleObject = {+ flex: '1 1 0',+ minWidth: 0,+ overflow: 'hidden',+ position: 'relative',+};++const DETERMINATE_SX: SystemStyleObject = {+ bg: 'accent.solid',+ height: 'full',+ transition: 'width var(--wb-motion-duration-fast) linear',+};++// Reuses Chakra's built-in `position` keyframe, the same one its own+// indeterminate Progress range animates on.+const INDETERMINATE_SX: SystemStyleObject = {+ '--animate-from-x': '-45%',+ '--animate-to-x': '100%',+ animation: 'position 1.1s ease infinite',+ backgroundImage: 'linear-gradient(to right, transparent, {colors.accent.solid}, transparent)',+ insetBlock: 0,+ minWidth: '45%',+ position: 'absolute',+ // With motion off there is no sweep to fall back on, so the segment becomes a+ // quiet static fill: still "something is running", minus the movement. Spelled+ // as a raw selector because the `_reduceMotion` condition this repo defines is+ // only typed inside token values, not in style objects.+ ':root[data-reduce-motion=true] &': {+ animation: 'none',+ backgroundImage: 'none',+ bg: 'accent.solid/40',+ insetInline: 0,+ },+};++/**+ * One session's fill. Each segment subscribes to its own item so a step event+ * on one GPU does not re-render the other GPUs' segments — or the top bar.+ */+const RailSegment = ({ isLoadingModels, itemId }: { isLoadingModels: boolean; itemId: number | null }) => {+ const progress = useItemProgress(itemId);+ const value = getProgressRailSegmentValue({ isLoadingModels, percentage: progress?.percentage });+ const fillStyle = useMemo<CSSProperties>(() => ({ width: value === null ? undefined : `${value * 100}%` }), [value]);++ return (+ <Box css={SEGMENT_SX}>+ {value === null ? <Box css={INDETERMINATE_SX} /> : <Box css={DETERMINATE_SX} style={fillStyle} />}+ </Box>+ );+};diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/TopbarProgressRail.tsx b/invokeai/frontend/webv2/src/workbench/shell/topbar/TopbarProgressRail.tsxindex 68872e3b20..7c9459b301 100644--- a/invokeai/frontend/webv2/src/workbench/shell/topbar/TopbarProgressRail.tsx+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/TopbarProgressRail.tsx@@ -1,17 +1,6 @@import type { SystemStyleObject } from '@chakra-ui/react';-import type { CSSProperties } from 'react';-import { Box } from '@chakra-ui/react';-import { useModelLoads } from '@features/models';-import {- getProgressRailModel,- getProgressRailSegmentValue,- getQueueSummary,- selectProjectProgressItemIds,-} from '@features/queue/contracts';-import { useActiveProgressItemIds, useItemProgress } from '@features/queue/react';-import { useActiveProjectSelector, useWorkbenchSelector } from '@workbench/WorkbenchContext';-import { useMemo } from 'react';+import { QueueProgressRail } from '@workbench/queue-integration/QueueProgressRail';/*** The primary generation indicator: a hairline lighting up along the top bar's@@ -22,13 +11,9 @@ import { useMemo } from 'react';* at, and it is present in every layout.** It sits *over* the 1px divider rather than below it, so appearing costs no- * reflow and reads as the existing line lighting up.- *- * Sessions divide the width instead of stacking — 2px cannot stack to four GPUs- * without growing into the workspace or dropping below visibility.- *- * Not exposed to assistive tech: the queue cluster already owns a throttled- * live region, and a second announcer would double the chatter.+ * reflow and reads as the existing line lighting up. The rail itself is+ * shared with the floating preview window (`QueueProgressRail`); only this+ * placement is the top bar's.*/const RAIL_SX: SystemStyleObject = {@@ -42,85 +27,4 @@ const RAIL_SX: SystemStyleObject = {zIndex: 3,};-export const TopbarProgressRail = () => {- const queueItems = useActiveProjectSelector((project) => project.queue.items);- const isConnected = useWorkbenchSelector((snapshot) => snapshot.backendConnection.status === 'connected');- const isLoadingModels = useModelLoads().length > 0;- const activeItemIds = useActiveProgressItemIds();-- const sessionItemIds = useMemo(- () => selectProjectProgressItemIds(queueItems, activeItemIds),- [activeItemIds, queueItems]- );-- const model = getProgressRailModel({- hasOpenWork: getQueueSummary(queueItems).total > 0,- isConnected,- sessionItemIds,- });-- if (model.kind === 'hidden') {- return null;- }-- return (- <Box aria-hidden="true" css={RAIL_SX}>- {model.kind === 'pending' ? (- <RailSegment isLoadingModels={isLoadingModels} itemId={null} />- ) : (- model.itemIds.map((itemId) => <RailSegment isLoadingModels={isLoadingModels} itemId={itemId} key={itemId} />)- )}- </Box>- );-};--const SEGMENT_SX: SystemStyleObject = {- flex: '1 1 0',- minWidth: 0,- overflow: 'hidden',- position: 'relative',-};--const DETERMINATE_SX: SystemStyleObject = {- bg: 'accent.solid',- height: 'full',- transition: 'width var(--wb-motion-duration-fast) linear',-};--// Reuses Chakra's built-in `position` keyframe, the same one its own-// indeterminate Progress range animates on.-const INDETERMINATE_SX: SystemStyleObject = {- '--animate-from-x': '-45%',- '--animate-to-x': '100%',- animation: 'position 1.1s ease infinite',- backgroundImage: 'linear-gradient(to right, transparent, {colors.accent.solid}, transparent)',- insetBlock: 0,- minWidth: '45%',- position: 'absolute',- // With motion off there is no sweep to fall back on, so the segment becomes a- // quiet static fill: still "something is running", minus the movement. Spelled- // as a raw selector because the `_reduceMotion` condition this repo defines is- // only typed inside token values, not in style objects.- ':root[data-reduce-motion=true] &': {- animation: 'none',- backgroundImage: 'none',- bg: 'accent.solid/40',- insetInline: 0,- },-};--/**- * One session's fill. Each segment subscribes to its own item so a step event- * on one GPU does not re-render the other GPUs' segments — or the top bar.- */-const RailSegment = ({ isLoadingModels, itemId }: { isLoadingModels: boolean; itemId: number | null }) => {- const progress = useItemProgress(itemId);- const value = getProgressRailSegmentValue({ isLoadingModels, percentage: progress?.percentage });- const fillStyle = useMemo<CSSProperties>(() => ({ width: value === null ? undefined : `${value * 100}%` }), [value]);-- return (- <Box css={SEGMENT_SX}>- {value === null ? <Box css={INDETERMINATE_SX} /> : <Box css={DETERMINATE_SX} style={fillStyle} />}- </Box>- );-};+export const TopbarProgressRail = () => <QueueProgressRail css={RAIL_SX} />;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.tsxindex cfaaf0f469..ca01049e0d 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@@ -58,6 +58,7 @@ vi.mock('@features/queue/react', () => ({useQueueItemProgressImage: () => mocks.progressImage,useActiveProgressTargets: () => [],useActiveProgressTarget: () => null,+ useActiveProgressItemIds: () => [],useProgressImage: () => null,}));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.tsxindex 1f4baaffa6..c68ce6e63a 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@@ -128,6 +128,8 @@ vi.mock('@workbench/WorkbenchContext', () => ({useWidgetValuesSelector: () => ({}),useWorkbenchCommands: () => mocks.commands,useWorkbenchQueries: () => ({ getSnapshot: () => ({ activeProject: mocks.project }) }),+ useWorkbenchSelector: (selector: (snapshot: unknown) => unknown) =>+ selector({ backendConnection: { status: 'connected' } }),}));vi.mock('@features/queue/react', async (importOriginal) => ({diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsxindex 74df494db8..e5fdf0704b 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx@@ -1,3 +1,4 @@+import type { SystemStyleObject } from '@chakra-ui/react';import type { QueueItem } from '@features/queue/contracts';import type { WidgetViewProps } from '@workbench/widgetContracts';@@ -55,6 +56,7 @@ import {type ImageActions,type ImageContextMenuTarget,} from '@workbench/image-actions';+import { QueueProgressRail } from '@workbench/queue-integration/QueueProgressRail';import { getProjectWidgetValues } from '@workbench/widgetState';import {useActiveProjectId,@@ -184,6 +186,18 @@ const PREVIEW_OVERLAY_RESERVE = '5.5rem';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',+ gap: '1px',+ height: '3px',+ insetInline: 0,+ pointerEvents: 'none',+ position: 'absolute',+ top: 0,+ zIndex: 3,+};+export const PreviewWidgetView = ({ region, runtime }: WidgetViewProps) => {const galleryValues = useActiveProjectSelector((project) => getProjectWidgetValues(project, 'gallery'));const queueItems = useActiveProjectSelector((project) => project.queue.items);@@ -544,6 +558,13 @@ export const PreviewWidgetView = ({ region, runtime }: WidgetViewProps) => {// and runs to every edge. `containerType` anchors the details panel's// `cqh` cap to the widget rather than the viewport.<Box ref={rootRef} containerType="size" h="full" position="relative" w="full">+ {/* Floated, the window is usually parked over a maximized work surface+ or on another display, where the top bar's rail is out of view — so+ the window that shows the result also shows that it is coming. It+ overlays the body's top edge, directly under the title bar's divider,+ so appearing costs no reflow. Docked, the top bar's rail is in view+ and a second one would only be noise. */}+ {region === 'floating' ? <QueueProgressRail css={FLOATING_RAIL_SX} /> : null}{/* Single always-mounted keyboard boundary: DOM focus survives swapsbetween the live, selected, and compare branches, so arrownavigation keeps working across them. */}