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(webv2): v6-parity large media previews in the workflow field widgets
Lincoln Steinad13081af795
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.browser.test.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.browser.test.tsxindex 9c717f2e5d..d34a8ebe67 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.browser.test.tsx@@ -14,9 +14,12 @@ import { WorkflowFieldInput } from './WorkflowFieldInput';const uploadImageMock = vi.fn();const uploadVideoMock = vi.fn();+const resolveItemMock = vi.fn();vi.mock('@features/gallery', () => ({+ formatGalleryVideoDuration: (seconds: number) => `${seconds}s`,galleryDestinations: { list: () => Promise.resolve([]) },+ galleryItems: { resolve: (...args: unknown[]) => resolveItemMock(...args) },galleryTransfers: {upload: (...args: unknown[]) => uploadImageMock(...args),uploadVideo: (...args: unknown[]) => uploadVideoMock(...args),@@ -69,6 +72,9 @@ beforeEach(() => {root = createRoot(host);uploadImageMock.mockReset();uploadVideoMock.mockReset();+ resolveItemMock.mockReset();+ resolveItemMock.mockResolvedValue(SELECTED_GALLERY_VIDEO);+ queryClient.clear();delete galleryValues.selectedImage;});@@ -126,7 +132,7 @@ describe('WorkflowFieldInput media inputs', () => {await renderField(VIDEO_TEMPLATE, undefined, vi.fn());expect(host.textContent).not.toContain('Connection only');- expect(host.textContent).toContain('No video set');+ expect(host.textContent).toContain('Drop a video here');expect(findButton('Use gallery selection').disabled).toBe(true);expect(findButton('Upload').disabled).toBe(false);expect(host.querySelector<HTMLInputElement>('input[type="file"]')?.accept).toBe('video/*');@@ -145,8 +151,11 @@ describe('WorkflowFieldInput media inputs', () => {expect(onChange).toHaveBeenCalledWith({ video_name: 'clip.mp4' });await renderField(VIDEO_TEMPLATE, { video_name: 'clip.mp4' }, onChange);- expect(host.textContent).toContain('clip.mp4');expect(host.querySelector('img')?.src).toContain('/api/v1/videos/i/clip.mp4/thumbnail');+ await vi.waitFor(() => {+ // Dimensions/duration badge from the resolved item details.+ expect(host.textContent).toContain('640x480 · 5s');+ });await act(() => findButton('Clear').click());expect(onChange).toHaveBeenCalledWith(undefined);diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.tsxindex 007e3facb3..bcb6395e82 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.tsx+++ b/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.tsx@@ -1,9 +1,15 @@import type { ModelConfig, ModelTaxonomyType } from '@features/models/react';import type { FieldInputTemplate } from '@features/workflow/contracts';-import { Box, createListCollection, HStack, Image, Input, Switch, Text } from '@chakra-ui/react';+import { Badge, Box, createListCollection, Flex, HStack, Icon, Image, Input, Switch, Text } from '@chakra-ui/react';import { useDndContext, useDndMonitor, useDroppable, type DragEndEvent } from '@dnd-kit/core';-import { galleryDestinations, galleryTransfers, type GalleryBoard } from '@features/gallery';+import {+ formatGalleryVideoDuration,+ galleryDestinations,+ galleryItems,+ galleryTransfers,+ type GalleryBoard,+} from '@features/gallery';import { getSelectedGalleryImageFromValues, getSelectedGalleryItemFromValues } from '@features/gallery/contracts';import { invalidateGallery } from '@features/gallery/queries';import { galleryImageUrls, galleryVideoUrls } from '@features/gallery/utility';@@ -32,7 +38,8 @@ import {Select,toaster,} from '@platform/ui';-import { useQueryClient } from '@tanstack/react-query';+import { useQuery, useQueryClient } from '@tanstack/react-query';+import { FilmIcon, ImageIcon } from 'lucide-react';import { lazy, Suspense, useCallback, useEffect, useId, useMemo, useRef, useState, type ChangeEvent } from 'react';const ModelSelect = lazy(() => import('@features/models/react').then((module) => ({ default: module.ModelSelect })));@@ -537,43 +544,116 @@ const MediaInput = ({ id, invalid, kind, onChange, value }: WorkflowFieldInputPrconst onClearClick = useCallback(() => onChange(undefined), [onChange]);// A stale value (media deleted since the workflow was saved) 404s the- // thumbnail; hide the broken-image glyph and keep showing the name. A new- // value retries.+ // thumbnail; degrade to a media icon rather than the broken-image glyph. A+ // new value retries.const [failedThumbnail, setFailedThumbnail] = useState<string | null>(null);const onThumbnailError = useCallback(() => setFailedThumbnail(mediaName), [mediaName]);+ // Resolve the item's details for the dimensions/duration badge (the legacy+ // editor's widget shows the same). Best-effort: the preview works from the+ // name alone, so a failed lookup just drops the badge.+ const { data: mediaItem } = useQuery({+ enabled: mediaName !== null,+ queryFn: ({ signal }) => galleryItems.resolve({ kind, name: mediaName ?? '' }, signal),+ queryKey: ['workflow-media-field-item', kind, mediaName],+ retry: false,+ staleTime: 60_000,+ });+ const badge =+ mediaItem && mediaItem.name === mediaName && mediaItem.width > 0+ ? `${mediaItem.width}x${mediaItem.height}${+ mediaItem.kind === 'video' ? ` · ${formatGalleryVideoDuration(mediaItem.durationSeconds)}` : ''+ }`+ : null;++ const FallbackIcon = kind === 'video' ? FilmIcon : ImageIcon;+return (- <Box ref={setNodeRef} position="relative" w="full">- <HStack+ <Box position="relative" w="full" {...invalidAriaProps}>+ {/* The whole preview area is the drop target, like the legacy editor's widget. */}+ <Box+ ref={setNodeRef}boxShadow={invalid ? '0 0 0 1px {colors.red.solid}' : undefined}- gap="1.5"- minW="0"+ className="nodrag"+ h="32"+ position="relative"rounded="sm"w="full"- {...invalidAriaProps}>{mediaName ? (<>- {failedThumbnail !== mediaName ? (- <Image- alt=""- boxSize="6"- flexShrink={0}- objectFit="cover"- rounded="xs"- src={config.getThumbnailUrl(mediaName)}- onError={onThumbnailError}- />+ <Flex+ alignItems="center"+ borderWidth="1px"+ h="full"+ justifyContent="center"+ overflow="hidden"+ rounded="sm"+ w="full"+ >+ {failedThumbnail !== mediaName ? (+ <Image+ alt=""+ maxH="full"+ maxW="full"+ objectFit="contain"+ src={config.getThumbnailUrl(mediaName)}+ title={mediaName}+ onError={onThumbnailError}+ />+ ) : (+ <Box title={mediaName}>+ <Icon as={FallbackIcon} boxSize="10" color="fg.subtle" />+ </Box>+ )}+ </Flex>+ {badge !== null ? (+ <Badge+ bottom="1"+ fontVariantNumeric="tabular-nums"+ insetInlineEnd="1"+ pointerEvents="none"+ position="absolute"+ size="xs"+ variant="solid"+ >+ {badge}+ </Badge>) : null}- <Text color="fg.muted" flex="1" fontSize="2xs" minW="0" title={mediaName} truncate>- {mediaName}- </Text></>) : (- <Text color="fg.subtle" flex="1" fontSize="2xs">- {`No ${config.noun} set`}- </Text>+ <Flex+ alignItems="center"+ borderStyle="dashed"+ borderWidth="1px"+ h="full"+ justifyContent="center"+ rounded="sm"+ w="full"+ >+ <Text color="fg.subtle" fontSize="xs">+ {`Drop a ${config.noun} here`}+ </Text>+ </Flex>)}+ {acceptsActiveDrag ? (+ <DropZone+ alignItems="center"+ display="flex"+ inset="0"+ isOver={isOver}+ justifyContent="center"+ pointerEvents="none"+ position="absolute"+ variant="overlay"+ >+ <Text fontSize="xs" fontWeight="700">+ {`Drop ${config.noun}`}+ </Text>+ </DropZone>+ ) : null}+ </Box>+ <HStack gap="1.5" mt="1" w="full"><ButtonclassName="nodrag"disabled={!gallerySelection}@@ -608,22 +688,6 @@ const MediaInput = ({ id, invalid, kind, onChange, value }: WorkflowFieldInputPronChange={onFileChange}/></HStack>- {acceptsActiveDrag ? (- <DropZone- alignItems="center"- display="flex"- inset="0"- isOver={isOver}- justifyContent="center"- pointerEvents="none"- position="absolute"- variant="overlay"- >- <Text fontSize="2xs" fontWeight="700">- {`Drop ${config.noun}`}- </Text>- </DropZone>- ) : null}</Box>);};diff --git a/invokeai/frontend/webv2/vite.config.mts b/invokeai/frontend/webv2/vite.config.mtsindex fb394b032d..1b3fa669de 100644--- a/invokeai/frontend/webv2/vite.config.mts+++ b/invokeai/frontend/webv2/vite.config.mts@@ -9,6 +9,12 @@ import { chunkSourceManifest } from './scripts/chunk-source-manifest.mjs';// backend dev server runs on a non-default port.const BACKEND_URL = process.env.INVOKEAI_DEV_BACKEND ?? 'http://127.0.0.1:9090';const BACKEND_WS_URL = BACKEND_URL.replace(/^http/, 'ws');++// Set e.g. INVOKEAI_DEV_HOSTS=my-box.local,10.0.0.5 when reaching the dev+// server by a hostname other than localhost.+const ALLOWED_HOSTS = process.env.INVOKEAI_DEV_HOSTS?.split(',')+ .map((host) => host.trim())+ .filter(Boolean);const PROJECT_ROOT = fileURLToPath(new URL('.', import.meta.url));const ROUTE_SHARED_MODULES = [@@ -27,10 +33,6 @@ const ROUTE_SHARED_MODULES = ['/workbench/components/WorkbenchSplashScreen.tsx','/workbench/hotkeys/catalog.ts','/workbench/launchpad/formatRelativeTime.ts',- // The Launchpad writes `?intent=` and the editor's session controller reads- // it. Without this the editor pulls the whole Launchpad chunk for a lookup- // table — a 66 KB, one-extra-request regression on the editor route.- '/workbench/launchpad/intents.ts','/workbench/palette/settingsEntryDeps.ts','/workbench/projects/ids.ts','/workbench/projects/library.ts',@@ -129,6 +131,13 @@ export default defineConfig({priority: 30,test: (id) => matchesAnySuffix(id, WORKBENCH_TOPBAR_MODULES),},+ {+ // Plotly is large (~1MB min) and only used by the lazy-loaded+ // Image Map plot; keep it out of the eager vendor chunk.+ name: 'plotly',+ priority: 30,+ test: (id) => id.includes('plotly') && id.includes('node_modules'),+ },{name: getLegacyChunkName,},@@ -157,6 +166,7 @@ export default defineConfig({},},server: {+ allowedHosts: ALLOWED_HOSTS,host: '0.0.0.0',port: 5174,proxy: {diff --git a/start_frontend.sh b/start_frontend.shnew file mode 100755index 0000000000..9f1296366b--- /dev/null+++ b/start_frontend.sh@@ -0,0 +1,4 @@+#!/bin/sh++cd /home/lstein/Projects/invokeai-v7-webv2-fields/invokeai/frontend/webv2+INVOKEAI_DEV_HOSTS=gorgon INVOKEAI_DEV_BACKEND=http://127.0.0.1:9090 pnpm run dev