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
refactor(webv2): drop the in-node output image preview
Josh Corbett5e0c79f8697f
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.jsonindex 27d2b3d615..68a3594b77 100644--- a/invokeai/frontend/webv2/public/locales/en.json+++ b/invokeai/frontend/webv2/public/locales/en.json@@ -1533,8 +1533,6 @@"executionCompleted": "Completed","executionFailed": "Failed","childWorkflowError": "Child workflow error: {{error}}",- "latestOutput": "Latest output",- "latestOutputImage": "Latest output of this node","forLoopBodyBoundary": "For loop body","imageCollectionCount_one": "{{count}} image","imageCollectionCount_other": "{{count}} images",diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/editor/InvocationFlowNode.browser.test.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/editor/InvocationFlowNode.browser.test.tsxindex 980dcc83da..5665166214 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/editor/InvocationFlowNode.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/workflow/ui/editor/InvocationFlowNode.browser.test.tsx@@ -18,7 +18,6 @@ import {} from '@features/workflow/data/savedWorkflowQueries';import { WorkflowImageExportProvider } from '@features/workflow/ui/nodeChrome';import { WorkflowUiProvider } from '@features/workflow/ui/WorkflowUiContext';-import { setNodePreviewCollapsed } from '@features/workflow/ui/workflowUiStore';import {buildCurrentImageNode,buildNotesNode,@@ -85,8 +84,6 @@ exportMocks.translate = (key, options) => i18n.t(key, options as never) as unknoconst queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } });const NODE_ID = 'preview-node';-/** The preview's fixed height (10rem) in CSS pixels, however the root font is sized. */-const previewHeightPx = () => parseFloat(getComputedStyle(document.documentElement).fontSize) * 10;const template: InvocationTemplate = {category: 'test',@@ -284,12 +281,11 @@ const createAdapter = (widgets: { open: vi.fn(), patchValues: vi.fn() },}) as unknown as WorkflowUiAdapter;-describe('InvocationFlowNode output preview', () => {+describe('InvocationFlowNode chrome and export', () => {let host: HTMLDivElement;let root: Root;beforeEach(() => {- setNodePreviewCollapsed(NODE_ID, false);queryClient.clear();host = document.createElement('div');host.style.cssText = 'width: 480px; height: 520px;';@@ -325,10 +321,6 @@ describe('InvocationFlowNode output preview', () => {));const image = () => host.querySelector<HTMLImageElement>('.react-flow__node img');- const disclosure = () =>- [...host.querySelectorAll<HTMLButtonElement>('.react-flow__node button[aria-expanded]')].find(- (button) => button.textContent === 'Latest output'- )!;const nodeHeight = () => host.querySelector<HTMLElement>('.react-flow__node')!.getBoundingClientRect().height;it('keeps field-description editing available in the workflow editor', async () => {@@ -1584,66 +1576,18 @@ describe('InvocationFlowNode output preview', () => {}});- it('keeps one preview height across differently shaped outputs and folds it away per node', async () => {+ // Outputs are inspected in the side panel; a result growing the node would push it over the nodes below.+ it('keeps its size and shows no image when a run completes with an image output', async () => {const execution = createExecutionPort();const adapter = createAdapter(execution.port);await render(adapter);- expect(image()).toBeNull();- expect(disclosure()).toBeUndefined();+ const idleHeight = nodeHeight();await act(() => execution.set(completed(outputImage(400, 100))));- await vi.waitFor(() => expect(image()!.getBoundingClientRect().height).toBeCloseTo(previewHeightPx(), 0));- const heightWithWideOutput = nodeHeight();-- await act(() => execution.set(completed(outputImage(100, 400))));- await vi.waitFor(() => expect(image()!.src).toBe(outputImage(100, 400)));- expect(image()!.getBoundingClientRect().height).toBeCloseTo(previewHeightPx(), 0);- expect(nodeHeight()).toBe(heightWithWideOutput);-- await act(() => disclosure().click());- expect(disclosure().getAttribute('aria-expanded')).toBe('false');- expect(image()).toBeNull();- expect(nodeHeight()).toBeLessThan(heightWithWideOutput - 100);-- // The fold outlives the node's mount: a remount (offscreen virtualization, a project switch back) keeps it.- await act(() => root.unmount());- root = createRoot(host);- await render(adapter);- expect(disclosure().getAttribute('aria-expanded')).toBe('false');- expect(image()).toBeNull();-- await act(() => disclosure().click());- expect(disclosure().getAttribute('aria-expanded')).toBe('true');- await vi.waitFor(() => expect(image()!.getBoundingClientRect().height).toBeCloseTo(previewHeightPx(), 0));- });-- it('stands in a same-height skeleton for the image when the viewport is zoomed out', async () => {- const execution = createExecutionPort();- const adapter = createAdapter(execution.port);- execution.set(completed(outputImage(400, 100)));-- await render(adapter);- await vi.waitFor(() => expect(image()).not.toBeNull());- const node = () => host.querySelector<HTMLElement>('.react-flow__node')!;- const layoutHeight = node().offsetHeight;-- await act(() => root.unmount());- root = createRoot(host);- await render(adapter, 0.3);-- await vi.waitFor(() => expect(image()).toBeNull());- expect(node().offsetHeight).toBe(layoutHeight);- });-- it('omits completed output previews from image exports when zoomed out', async () => {- const execution = createExecutionPort();- const adapter = createAdapter(execution.port);- execution.set(completed(outputImage(400, 100)));-- await render(adapter, 0.3, true);expect(image()).toBeNull();+ expect(nodeHeight()).toBe(idleHeight);});it('renders full fields for compact nodes during image export', async () => {diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/editor/InvocationFlowNode.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/editor/InvocationFlowNode.tsxindex 5d378254c4..2294447ab3 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/editor/InvocationFlowNode.tsx+++ b/invokeai/frontend/webv2/src/features/workflow/ui/editor/InvocationFlowNode.tsx@@ -2,20 +2,7 @@import type { FieldInputTemplate, FieldOutputTemplate, WorkflowInvocationNode } from '@features/workflow/contracts';import type { WorkflowNodeExecutionState as NodeExecutionState } from '@features/workflow/ui/contracts';-import {- Box,- chakra,- Checkbox,- Field,- Flex,- HStack,- Icon,- IconButton,- Image,- Input,- Stack,- Text,-} from '@chakra-ui/react';+import { Box, Checkbox, Field, Flex, HStack, Icon, IconButton, Input, Stack, Text } from '@chakra-ui/react';import { getWorkflowFieldSeedMode, isSeedInputField } from '@features/workflow/graph';import { FieldDescriptionPopover } from '@features/workflow/ui/fields/FieldDescriptionPopover';import { WorkflowFieldInput, WorkflowFieldSnapshot } from '@features/workflow/ui/fields/WorkflowFieldInput';@@ -25,7 +12,6 @@ import {getWorkflowNodeHeaderProps,getWorkflowNodeShellProps,WORKFLOW_NODE_DENSITY,- WORKFLOW_NODE_SURFACE_TOKEN,WorkflowNodeInfoIcon,WorkflowNodeOutcomeIcon,useIsWorkflowImageExport,@@ -33,7 +19,6 @@ import {} from '@features/workflow/ui/nodeChrome';import { useProjectGraphCommands } from '@features/workflow/ui/useProjectGraphCommands';import { useWorkflowNodeExecutionState } from '@features/workflow/ui/WorkflowUiContext';-import { setNodePreviewCollapsed, workflowUiStore } from '@features/workflow/ui/workflowUiStore';import {CALL_SAVED_WORKFLOW_DYNAMIC_FIELD_PREFIX,cloneWorkflowFieldDefault,@@ -50,12 +35,11 @@ import {isExposableField,isWorkflowFieldValueDefault,} from '@features/workflow/utility';-import { useExternalStoreSelector } from '@platform/state/selectors';import { Tooltip } from '@platform/ui';import { MiddleTruncate } from '@platform/ui/MiddleTruncate';import { Handle, Position, useStore, type NodeProps } from '@xyflow/react';import { ChevronDownIcon, ChevronRightIcon, PinIcon, PinOffIcon, RotateCcwIcon, TriangleAlertIcon } from 'lucide-react';-import { memo, useId, useRef, useState, type ChangeEvent, type KeyboardEvent } from 'react';+import { memo, useRef, useState, type ChangeEvent, type KeyboardEvent } from 'react';import { useTranslation } from 'react-i18next';import type { InvocationFlowNode as InvocationFlowNodeType, InvocationNodeTemplateView } from './flowAdapters';@@ -480,80 +464,6 @@ const NodeInfoIcon = ({/>);-/** Fixed so a run's differently shaped outputs do not resize the node and shove its neighbours around. */-const NODE_OUTPUT_PREVIEW_HEIGHT = '10rem';--/**- * The node's latest output image behind a disclosure. The fold is session-lived- * (`workflowUiStore`), matching the preview itself, so it is not a graph edit.- */-const NodeOutputPreview = ({- imageUrl,- isSkeleton,- nodeId,- roundedBottom,-}: {- imageUrl: string;- isSkeleton: boolean;- nodeId: string;- roundedBottom: boolean;-}) => {- const { t } = useTranslation();- const contentId = useId();- const collapsed = useExternalStoreSelector(workflowUiStore.subscribe, workflowUiStore.getSnapshot, (snapshot) =>- snapshot.collapsedPreviewNodeIds.has(nodeId)- );-- return (- <Box borderBottomRadius={roundedBottom ? 'lg' : 'none'} borderColor="border.subtle" borderTopWidth="1px">- <chakra.button- alignItems="center"- aria-controls={contentId}- aria-expanded={!collapsed}- className="nodrag"- display="flex"- focusVisibleRing="inside"- gap="1"- px={WORKFLOW_NODE_DENSITY.rowPaddingX}- py="1"- textAlign="start"- type="button"- w="full"- onClick={() => setNodePreviewCollapsed(nodeId, !collapsed)}- >- <Icon as={collapsed ? ChevronRightIcon : ChevronDownIcon} boxSize="3" color="fg.subtle" />- <Text- color="fg.subtle"- fontSize="2xs"- fontWeight="600"- letterSpacing="wide"- lineHeight="1"- textTransform="uppercase"- >- {t('nodes.latestOutput')}- </Text>- </chakra.button>- {/* The frame behind the image keeps a letterboxed output reading as a picture, not a gap. */}- <Box id={contentId} hidden={collapsed} pb="1.5" px={WORKFLOW_NODE_DENSITY.rowPaddingX}>- {collapsed ? null : isSkeleton ? (- <SkeletonBar h={NODE_OUTPUT_PREVIEW_HEIGHT} w="full" />- ) : (- <Image- alt={t('nodes.latestOutputImage')}- bg={WORKFLOW_NODE_SURFACE_TOKEN}- draggable={false}- h={NODE_OUTPUT_PREVIEW_HEIGHT}- objectFit="contain"- rounded="sm"- src={imageUrl}- w="full"- />- )}- </Box>- </Box>- );-};-const NodeFooter = ({ canUseCache, node }: { canUseCache: boolean; node: WorkflowInvocationNode }) => {const { editGraph } = useProjectGraphCommands();@@ -1088,7 +998,6 @@ const ExpandedInvocationNode = ({ data, selected }: NodeProps<InvocationFlowNodeconst isCompact = data.isCompact && !selected && !isWorkflowImageExport;const withFooter = !isWorkflowImageExport && !isZoomedOut && templateView.isExecutable && templateView.hasImageOutput;const resultExecution = isWorkflowImageExport ? null : execution;- const withOutputPreview = Boolean(resultExecution?.outputImageUrl);const latestResult = resultExecution?.latestOutput;return (@@ -1140,7 +1049,7 @@ const ExpandedInvocationNode = ({ data, selected }: NodeProps<InvocationFlowNode<HiddenHandles inputTemplates={inputTemplates} outputTemplates={outputTemplates} /></>) : isOpen ? (- <Box {...getWorkflowNodeBodyProps({ roundedBottom: !withFooter && !withOutputPreview })}>+ <Box {...getWorkflowNodeBodyProps({ roundedBottom: !withFooter })}>{outputRows.map((row) =>row.type === 'header' ? (<OutputScopeHeader key={`output-scope-${row.scope}`} scope={row.scope} />@@ -1176,14 +1085,6 @@ const ExpandedInvocationNode = ({ data, selected }: NodeProps<InvocationFlowNode) : (<HiddenHandles inputTemplates={inputTemplates} outputTemplates={outputTemplates} />)}- {isOpen && resultExecution?.outputImageUrl ? (- <NodeOutputPreview- imageUrl={resultExecution.outputImageUrl}- isSkeleton={isZoomedOut}- nodeId={node.id}- roundedBottom={!withFooter}- />- ) : null}{isOpen && withFooter ? <NodeFooter canUseCache={data.canUseCache} node={node} /> : null}</NodeShell>);diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/workflowUiStore.ts b/invokeai/frontend/webv2/src/features/workflow/ui/workflowUiStore.tsindex 6aae6bdfd7..a0c1b5e187 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/workflowUiStore.ts+++ b/invokeai/frontend/webv2/src/features/workflow/ui/workflowUiStore.ts@@ -30,8 +30,6 @@ export type WorkflowPublicationIntent =export interface WorkflowUiSnapshot {addNodeConnection: AddNodeConnectionFilter | null;addNodePosition: XYPosition | null;- /** Nodes whose latest-output preview is folded away. Session-lived, like the previews themselves. */- collapsedPreviewNodeIds: ReadonlySet<string>;isAddNodeOpen: boolean;isLibraryOpen: boolean;/** Which view the library dialog shows; remembered for the session. */@@ -63,7 +61,6 @@ let nextWorkflowLoadRequestId = 0;const INITIAL_WORKFLOW_UI_SNAPSHOT: WorkflowUiSnapshot = {addNodeConnection: null,addNodePosition: null,- collapsedPreviewNodeIds: new Set(),importRequestCount: 0,isAddNodeOpen: false,renameRequest: null,@@ -145,18 +142,6 @@ export const clearPendingWorkflowLoad = (requestId: number): void => {}};-export const setNodePreviewCollapsed = (nodeId: string, collapsed: boolean): void => {- const collapsedPreviewNodeIds = new Set(workflowUiStore.getSnapshot().collapsedPreviewNodeIds);-- if (collapsed) {- collapsedPreviewNodeIds.add(nodeId);- } else {- collapsedPreviewNodeIds.delete(nodeId);- }-- workflowUiStore.patchSnapshot({ collapsedPreviewNodeIds });-};-let nextRenameRequestId = 0;export const requestWorkflowRename = (workflowId: string): void => {