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
fix(webv2): give the graph preview landscape proportions, an exit animation, and honest summary rows
joshistoast7674de22885a
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewDialog.browser.test.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewDialog.browser.test.tsxindex 4f3530c7df..ec0217abcb 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewDialog.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewDialog.browser.test.tsx@@ -234,6 +234,16 @@ const FIXTURE_SOURCE: GraphPreviewSourceState = {],};+/** A library entry: previewed before it has been opened into a project, so nothing has routed it anywhere. */+const NO_DESTINATION_SOURCE: GraphPreviewSourceState = {+ destinationLabel: null,+ graph: FIXTURE_GRAPH,+ invalidReasons: [],+ isLive: false,+ notices: [],+ summaryRows: [],+};+const INVALID_SOURCE: GraphPreviewSourceState = {destinationLabel: 'Gallery',graph: null,@@ -351,9 +361,36 @@ describe('GraphPreviewDialog', () => {let host: HTMLDivElement;let root: Root;let onOpenChange: (isOpen: boolean) => void;+ let onExitComplete: () => void;let graphPreviewPort: WorkflowGraphPreviewPort;let workflowUiAdapter: WorkflowUiAdapter;+ const dialogTree = (+ source: GraphPreviewSourceState,+ isOpen: boolean,+ sourceId: WorkflowInvocationSourceId,+ hideInvoke: boolean+ ) => (+ <StrictMode>+ <ChakraProvider value={system}>+ <WorkflowUiProvider adapter={workflowUiAdapter}>+ <WorkflowGraphPreviewProvider adapter={graphPreviewPort}>+ <GraphPreviewDialog+ graphId="preview-graph-id"+ hideInvoke={hideInvoke}+ isOpen={isOpen}+ source={source}+ sourceId={sourceId}+ sourceLabel="Generate"+ onExitComplete={onExitComplete}+ onOpenChange={onOpenChange}+ />+ </WorkflowGraphPreviewProvider>+ </WorkflowUiProvider>+ </ChakraProvider>+ </StrictMode>+ );+const renderDialog = async (source: GraphPreviewSourceState,isOpen = true,@@ -361,25 +398,7 @@ describe('GraphPreviewDialog', () => {hideInvoke = false) => {await act(() => {- root.render(- <StrictMode>- <ChakraProvider value={system}>- <WorkflowUiProvider adapter={workflowUiAdapter}>- <WorkflowGraphPreviewProvider adapter={graphPreviewPort}>- <GraphPreviewDialog- graphId="preview-graph-id"- hideInvoke={hideInvoke}- isOpen={isOpen}- source={source}- sourceId={sourceId}- sourceLabel="Generate"- onOpenChange={onOpenChange}- />- </WorkflowGraphPreviewProvider>- </WorkflowUiProvider>- </ChakraProvider>- </StrictMode>- );+ root.render(dialogTree(source, isOpen, sourceId, hideInvoke));});};@@ -388,6 +407,7 @@ describe('GraphPreviewDialog', () => {document.body.append(host);root = createRoot(host);onOpenChange = vi.fn((_isOpen: boolean) => {});+ onExitComplete = vi.fn();graphPreviewPort = createGraphPreviewPort();workflowUiAdapter = createWorkflowUiAdapter();downloads.downloadBlob.mockReset();@@ -476,6 +496,42 @@ describe('GraphPreviewDialog', () => {expect(text).toContain('Updates as you change settings.');});+ it('omits the destination row when the source was never routed anywhere', async () => {+ await renderDialog(NO_DESTINATION_SOURCE);++ const panel = document.querySelector('[role="region"][aria-label="This graph"]');+ // A "Destination —" row states nothing; the node count still shows.+ expect(panel?.textContent ?? '').not.toContain('Destination');+ expect(panel?.textContent ?? '').toContain('Nodes');+ });++ it('reports when its close transition has finished, so hosts can drop the mount', async () => {+ await renderDialog(FIXTURE_SOURCE);++ expect(onExitComplete).not.toHaveBeenCalled();++ await renderDialog(FIXTURE_SOURCE, false);++ // The exit animation runs in real time; polling inside `act` keeps its+ // final commit inside an open act scope.+ await act(async () => {+ await vi.waitFor(() => {+ expect(onExitComplete).toHaveBeenCalled();+ });+ });+ });++ it('caps its height so a tall display gets a landscape dialog, not a full-height column', async () => {+ await renderDialog(FIXTURE_SOURCE);++ const content = document.querySelector<HTMLElement>('[data-scope="dialog"][data-part="content"]');+ expect(content).not.toBeNull();++ // 46rem — the ceiling that makes the dialog wider than tall wherever the+ // viewport is tall enough for the old vh-driven height to overshoot it.+ expect(content?.getBoundingClientRect().height ?? 0).toBeLessThanOrEqual(46 * 16 + 1);+ });+it('shows the seed notice inline in the summary panel', async () => {await renderDialog(FIXTURE_SOURCE);diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewDialog.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewDialog.tsxindex 25a24a9191..2a370d5f35 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewDialog.tsx+++ b/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewDialog.tsx@@ -24,6 +24,12 @@ interface GraphPreviewDialogProps {/** Hides the footer Invoke button only — Copy JSON and the Open-as menu stay. For sources with no invocation route (e.g. a library entry, previewed before it's ever opened into a project). */hideInvoke?: boolean;onOpenChange: (isOpen: boolean) => void;+ /**+ * Fires once the close transition has finished playing. Hosts that mount this+ * dialog conditionally must drop the mount here rather than the moment+ * `isOpen` goes false, or the exit animation never gets to run.+ */+ onExitComplete?: () => void;}type PreviewMode = 'graph' | 'list' | 'json';@@ -74,6 +80,7 @@ export const GraphPreviewDialog = ({sourceLabel,hideInvoke = false,onOpenChange,+ onExitComplete,}: GraphPreviewDialogProps) => {const { t } = useTranslation();const graphPreview = useWorkflowGraphPreview();@@ -194,11 +201,21 @@ export const GraphPreviewDialog = ({}, [t, sourceLabel, source.isLive]);return (- <Dialog.Root open={isOpen} placement="center" size="xl" onOpenChange={handleOpenChange}>+ <Dialog.Root+ open={isOpen}+ placement="center"+ size="xl"+ onExitComplete={onExitComplete}+ onOpenChange={handleOpenChange}+ ><Portal><Dialog.Backdrop /><Dialog.Positioner>- <Dialog.Content h="80vh" maxH="80vh" maxW="min(72rem, calc(100vw - 4rem))">+ {/* A graph reads left-to-right, so the dialog is landscape: it takes+ the width it can get and only as much height as that shape wants,+ instead of the near-full-height column an 80vh-first sizing gave+ it on tall displays. */}+ <Dialog.Content h="min(46rem, 85vh)" maxH="85vh" maxW="min(72rem, calc(100vw - 4rem))"><Dialog.Header alignItems="center" flexDirection="row" justifyContent="space-between"><Stack gap="0.5" minW="0"><Dialog.Title>{t('graphPreview.title')}</Dialog.Title>diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewSidePanel.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewSidePanel.tsxindex f8f8257e18..ac62bdfdf9 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewSidePanel.tsx+++ b/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewSidePanel.tsx@@ -117,12 +117,18 @@ const GraphSummary = ({{nodeCount !== undefined ? String(nodeCount) : '—'}</DataList.ItemValue></DataList.Item>- <DataList.Item>- <DataList.ItemLabel fontSize="2xs">{t('graphPreview.destination')}</DataList.ItemLabel>- <DataList.ItemValue fontSize="2xs" minW="0">- {source.destinationLabel ?? '—'}- </DataList.ItemValue>- </DataList.Item>+ {/* A source with no destination has not been routed anywhere yet (a+ library entry previewed before it is opened into a project). A row+ reading "Destination —" states nothing; omitting it says the same+ thing without the noise. */}+ {source.destinationLabel === null ? null : (+ <DataList.Item>+ <DataList.ItemLabel fontSize="2xs">{t('graphPreview.destination')}</DataList.ItemLabel>+ <DataList.ItemValue fontSize="2xs" minW="0">+ {source.destinationLabel}+ </DataList.ItemValue>+ </DataList.Item>+ )}{source.summaryRows.map((row) => (<DataList.Item key={row.id}><DataList.ItemLabel fontSize="2xs">{row.label}</DataList.ItemLabel>diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/library/libraryPreviewSource.test.ts b/invokeai/frontend/webv2/src/features/workflow/ui/library/libraryPreviewSource.test.tsindex 857060b9af..8c642b015d 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/library/libraryPreviewSource.test.ts+++ b/invokeai/frontend/webv2/src/features/workflow/ui/library/libraryPreviewSource.test.ts@@ -1,13 +1,10 @@import type { FieldInputTemplate, InvocationTemplate, ProjectGraphState } from '@features/workflow/contracts';-import type { TFunction } from 'i18next';import { buildInvocationNode, createProjectGraph, projectGraphReducer } from '@features/workflow/utility';import { describe, expect, it } from 'vitest';import { buildLibraryGraphPreviewSource } from './libraryPreviewSource';-const translate = ((key: string) => (key === 'graphPreview.nodes' ? 'Nodes' : key)) as TFunction;-const input = (name: string, overrides: Partial<FieldInputTemplate> = {}): FieldInputTemplate => ({default: undefined,description: '',@@ -85,7 +82,7 @@ describe('buildLibraryGraphPreviewSource', () => {it('compiles the document into a graph with its nodes and edges', () => {const { doc, sinkId, sourceId } = buildDocument();- const result = buildLibraryGraphPreviewSource(doc, templates, translate);+ const result = buildLibraryGraphPreviewSource(doc, templates);expect(result.invalidReasons).toEqual([]);expect(result.graph?.nodes.map((node) => node.id).sort()).toEqual([sinkId, sourceId].sort());@@ -96,25 +93,26 @@ describe('buildLibraryGraphPreviewSource', () => {it('is never live and carries no destination or notices', () => {const { doc } = buildDocument();- const result = buildLibraryGraphPreviewSource(doc, templates, translate);+ const result = buildLibraryGraphPreviewSource(doc, templates);expect(result.isLive).toBe(false);expect(result.destinationLabel).toBeNull();expect(result.notices).toEqual([]);});- it('summarizes the compiled node count', () => {+ it('adds no summary rows of its own — the side panel already counts the nodes', () => {const { doc } = buildDocument();- const result = buildLibraryGraphPreviewSource(doc, templates, translate);+ const result = buildLibraryGraphPreviewSource(doc, templates);- expect(result.summaryRows).toEqual([{ id: 'nodes', label: 'Nodes', value: '2' }]);+ // A 'nodes' row here rendered a second "Nodes" line under the panel's own.+ expect(result.summaryRows).toEqual([]);});it('maps position hints from the document node positions', () => {const { doc, sinkId, sourceId } = buildDocument();- const result = buildLibraryGraphPreviewSource(doc, templates, translate);+ const result = buildLibraryGraphPreviewSource(doc, templates);expect(result.positionHints?.[sourceId]).toEqual({ x: 0, y: 0 });expect(result.positionHints?.[sinkId]).toEqual({ x: 240, y: 80 });@@ -127,7 +125,7 @@ describe('buildLibraryGraphPreviewSource', () => {// silently producing an empty graph.const corrupt = { ...doc, nodes: null } as unknown as ProjectGraphState;- const result = buildLibraryGraphPreviewSource(corrupt, templates, translate);+ const result = buildLibraryGraphPreviewSource(corrupt, templates);expect(result.graph).toBeNull();expect(result.invalidReasons).toHaveLength(1);diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/library/libraryPreviewSource.ts b/invokeai/frontend/webv2/src/features/workflow/ui/library/libraryPreviewSource.tsindex d821317ac6..795a1f6138 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/library/libraryPreviewSource.ts+++ b/invokeai/frontend/webv2/src/features/workflow/ui/library/libraryPreviewSource.ts@@ -1,5 +1,4 @@import type { GraphPreviewSourceState, InvocationTemplates, ProjectGraphState } from '@features/workflow/contracts';-import type { TFunction } from 'i18next';import { compileProjectGraph } from '@features/workflow/graph';@@ -16,8 +15,7 @@ import { compileProjectGraph } from '@features/workflow/graph';*/export const buildLibraryGraphPreviewSource = (document: ProjectGraphState,- templates: InvocationTemplates,- t: TFunction+ templates: InvocationTemplates): GraphPreviewSourceState => {try {const graph = compileProjectGraph(document, templates);@@ -30,7 +28,9 @@ export const buildLibraryGraphPreviewSource = (isLive: false,notices: [],positionHints,- summaryRows: [{ id: 'nodes', label: t('graphPreview.nodes'), value: String(graph.nodes.length) }],+ // No node-count row: the side panel's summary already opens with one, and+ // adding it here rendered "Nodes" twice.+ summaryRows: [],};} catch (error) {return {diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/GraphPreviewHost.tsx b/invokeai/frontend/webv2/src/workbench/widget-frame/GraphPreviewHost.tsxindex 8f1a228360..5c594d6e90 100644--- a/invokeai/frontend/webv2/src/workbench/widget-frame/GraphPreviewHost.tsx+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/GraphPreviewHost.tsx@@ -17,10 +17,13 @@ import { buildGraphPreviewSource } from './graphPreviewSource';export const GraphPreviewHost = ({isOpen,surface,+ onExitComplete,onOpenChange,}: {isOpen: boolean;surface: GraphBearingSurfaceContract;+ /** Fires when the close transition has played out — the menu drops the mount here. */+ onExitComplete: () => void;onOpenChange: (isOpen: boolean) => void;}) => {const { t } = useTranslation();@@ -46,6 +49,7 @@ export const GraphPreviewHost = ({source={source}sourceId={surface.sourceId}sourceLabel={surface.label}+ onExitComplete={onExitComplete}onOpenChange={onOpenChange}/>);diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetActionsMenu.tsx b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetActionsMenu.tsxindex c00868aeac..f200df8519 100644--- a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetActionsMenu.tsx+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetActionsMenu.tsx@@ -90,6 +90,10 @@ export const WidgetActionsMenu = ({const { getWidgetById } = useWorkbenchWidgetRegistry();const { widgets } = useWorkbenchCommands();const [isPreviewOpen, setIsPreviewOpen] = useState(false);+ // Mount outlives `isPreviewOpen`: dropping the host the moment the dialog+ // closes cancels its exit transition, so the preview blinked out of+ // existence. The host reports when the transition is done instead.+ const [isPreviewMounted, setIsPreviewMounted] = useState(false);const label = resolveWidgetLabel(manifest, t);const surface = useMemo(() =>@@ -112,8 +116,16 @@ export const WidgetActionsMenu = ({}, [instance.id, widgets]);const handlePreview = useCallback(() => {flushWorkbenchDrafts();+ setIsPreviewMounted(true);setIsPreviewOpen(true);}, []);+ // Guarded on `isPreviewOpen`: re-opening the preview while it is still+ // animating out must not have the late exit report drop its mount.+ const handlePreviewExitComplete = useCallback(() => {+ if (!isPreviewOpen) {+ setIsPreviewMounted(false);+ }+ }, [isPreviewOpen]);if (!surface && !HeaderMenu && !canFloat) {return null;@@ -146,9 +158,14 @@ export const WidgetActionsMenu = ({</Menu.Positioner></Portal></Menu.Root>- {surface && isPreviewOpen ? (+ {surface && isPreviewMounted ? (<Suspense fallback={null}>- <GraphPreviewHost isOpen={isPreviewOpen} surface={surface} onOpenChange={setIsPreviewOpen} />+ <GraphPreviewHost+ isOpen={isPreviewOpen}+ surface={surface}+ onExitComplete={handlePreviewExitComplete}+ onOpenChange={setIsPreviewOpen}+ /></Suspense>) : null}</>