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
perf(gallery): keep the picker off the boot path
Josh Corbettdbf7d2f03533
diff --git a/invokeai/frontend/webv2/src/architecture/featureInterfaces.ts b/invokeai/frontend/webv2/src/architecture/featureInterfaces.tsindex cf8d089f21..e4b6508f40 100644--- a/invokeai/frontend/webv2/src/architecture/featureInterfaces.ts+++ b/invokeai/frontend/webv2/src/architecture/featureInterfaces.ts@@ -5,7 +5,7 @@* To publish a new entry module, add it here and cover it in dependencyPolicy.test.ts.*/export const FEATURE_PUBLIC_INTERFACES: Readonly<Record<string, readonly string[]>> = {- gallery: ['contracts', 'launchpad', 'paletteSearch', 'picker', 'queries', 'react', 'utility', 'widget'],+ gallery: ['contracts', 'launchpad', 'mediaSlot', 'paletteSearch', 'picker', 'queries', 'react', 'utility', 'widget'],generation: ['canvasGraph','components',diff --git a/invokeai/frontend/webv2/src/features/gallery/mediaSlot.ts b/invokeai/frontend/webv2/src/features/gallery/mediaSlot.tsnew file mode 100644index 0000000000..643efd6530--- /dev/null+++ b/invokeai/frontend/webv2/src/features/gallery/mediaSlot.ts@@ -0,0 +1,5 @@+export {+ GalleryMediaSlot,+ type GalleryMediaSlotLabels,+ type GalleryMediaSlotValue,+} from './ui/picker/GalleryMediaSlot';diff --git a/invokeai/frontend/webv2/src/features/gallery/picker.ts b/invokeai/frontend/webv2/src/features/gallery/picker.tsindex 2e36419b7b..29f9c4caf8 100644--- a/invokeai/frontend/webv2/src/features/gallery/picker.ts+++ b/invokeai/frontend/webv2/src/features/gallery/picker.ts@@ -4,8 +4,3 @@ export {type GalleryPickerTileState,} from './ui/picker/galleryPicker';export { GalleryPickerPopover, type GalleryPickerPopoverProps } from './ui/picker/GalleryPickerPopover';-export {- GalleryMediaSlot,- type GalleryMediaSlotLabels,- type GalleryMediaSlotValue,-} from './ui/picker/GalleryMediaSlot';diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/picker/GalleryMediaSlot.browser.test.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/picker/GalleryMediaSlot.browser.test.tsxindex 455e116d01..bbbb5f0379 100644--- a/invokeai/frontend/webv2/src/features/gallery/ui/picker/GalleryMediaSlot.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/gallery/ui/picker/GalleryMediaSlot.browser.test.tsx@@ -235,6 +235,9 @@ describe('GalleryMediaSlot', () => {const dialog = document.querySelector<HTMLElement>('[role="dialog"][data-state="open"]');expect(dialog?.getAttribute('aria-label')).toBe('widgets.gallery.picker.chooseImage');+ await vi.waitFor(() => expect(dialog?.querySelector('input:not([type="file"])')).not.toBeNull(), {+ timeout: 10_000,+ });await vi.waitFor(() => expect(dialog?.querySelector('[data-item-key="image:a.png"]')).not.toBeNull());await interact(() => dialog?.querySelector<HTMLElement>('[data-item-key="image:a.png"]')?.click());diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/picker/GalleryPickerPopover.browser.test.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/picker/GalleryPickerPopover.browser.test.tsxindex 3a3b5edf36..44ab6d585a 100644--- a/invokeai/frontend/webv2/src/features/gallery/ui/picker/GalleryPickerPopover.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/gallery/ui/picker/GalleryPickerPopover.browser.test.tsx@@ -195,6 +195,10 @@ const openPicker = async (picker?: React.ReactElement) => {throw new Error('picker did not open');}+ // The view is lazy-loaded on first open.+ await vi.waitFor(() => expect(dialog.querySelector('input:not([type="file"])')).not.toBeNull(), { timeout: 10_000 });+ await settle();+return { dialog, trigger };};diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/picker/GalleryPickerPopover.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/picker/GalleryPickerPopover.tsxindex 3826dab81c..a7d55a635d 100644--- a/invokeai/frontend/webv2/src/features/gallery/ui/picker/GalleryPickerPopover.tsx+++ b/invokeai/frontend/webv2/src/features/gallery/ui/picker/GalleryPickerPopover.tsx@@ -1,15 +1,28 @@import type { GalleryItem } from '@features/gallery/core/items';import type { ReactElement } from 'react';-import { Popover, Portal } from '@chakra-ui/react';+import { Popover, Portal, Skeleton, Stack } from '@chakra-ui/react';import { PopoverContent } from '@platform/ui/Popover';-import { useCallback, useRef, useState } from 'react';+import { lazy, Suspense, useCallback, useRef, useState } from 'react';import type { GalleryPickerAccept, GalleryPickerSelection } from './galleryPicker';-import { GalleryPickerView } from './GalleryPickerView';+// Loaded on first open: every widget with an image slot mounts a trigger at+// boot, and the view is most of the picker's weight.+const GalleryPickerView = lazy(() =>+ import('./GalleryPickerView').then((module) => ({ default: module.GalleryPickerView }))+);const POSITIONING = { placement: 'bottom-start' } as const;++/** Same header and search footprint as the view, so the popover does not jump when it lands. */+const PICKER_FALLBACK = (+ <Stack aria-busy="true" gap="2" p="2">+ <Skeleton h="7" rounded="control" />+ <Skeleton h="7" rounded="control" />+ <Skeleton h="10rem" rounded="md" />+ </Stack>+);const SINGLE_SELECTION: GalleryPickerSelection = { mode: 'single' };export interface GalleryPickerPopoverProps {@@ -38,6 +51,7 @@ export const GalleryPickerPopover = ({const handleOpenChange = useCallback(({ open }: { open: boolean }) => setIsOpen(open), []);const close = useCallback(() => setIsOpen(false), []);+ // Null until the lazy view has mounted; the view then focuses the field itself.const getInitialFocusEl = useCallback(() => searchInputRef.current, []);return (@@ -60,13 +74,15 @@ export const GalleryPickerPopover = ({p="0"w="clamp(18rem, var(--reference-width), 28rem)">- <GalleryPickerView- accept={accept}- searchInputRef={searchInputRef}- selection={selection}- onClose={close}- onPick={onPick}- />+ <Suspense fallback={PICKER_FALLBACK}>+ <GalleryPickerView+ accept={accept}+ searchInputRef={searchInputRef}+ selection={selection}+ onClose={close}+ onPick={onPick}+ />+ </Suspense></PopoverContent></Popover.Positioner></Portal>diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/picker/GalleryPickerView.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/picker/GalleryPickerView.tsxindex efc075f6ed..bab1a21233 100644--- a/invokeai/frontend/webv2/src/features/gallery/ui/picker/GalleryPickerView.tsx+++ b/invokeai/frontend/webv2/src/features/gallery/ui/picker/GalleryPickerView.tsx@@ -203,6 +203,15 @@ export const GalleryPickerView = ({const visibleBoardCount = boardGroups.reduce((count, group) => count + group.boards.length, 0);const focusSearch = useCallback(() => searchInputRef.current?.focus(), [searchInputRef]);+ // The view is lazy-loaded, so it arrives after the popover's own initial+ // focus pass; the field takes focus itself as it mounts.+ const attachSearchInput = useCallback(+ (node: HTMLInputElement | null) => {+ searchInputRef.current = node;+ node?.focus();+ },+ [searchInputRef]+ );// The clicked row unmounts with the pane; without this, focus falls to the// body and the next keystrokes reach the workbench hotkeys.const handleSelectBoard = useCallback(@@ -389,7 +398,7 @@ export const GalleryPickerView = ({</HStack><Box pt="1.5" px="2"><GallerySearchField- ref={searchInputRef}+ ref={attachSearchInput}ariaLabel={searchLabel}endElement={searchEndElement}inputProps={searchInputProps}diff --git a/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleImageField.tsx b/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleImageField.tsxindex 2d5d5ec7ec..7fb9d2d45b 100644--- a/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleImageField.tsx+++ b/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleImageField.tsx@@ -1,8 +1,8 @@import type { GalleryItem } from '@features/gallery';-import type { GalleryMediaSlotValue } from '@features/gallery/picker';+import type { GalleryMediaSlotValue } from '@features/gallery/mediaSlot';import type { UpscaleWidgetValues } from '@features/upscale/core/types';-import { GalleryMediaSlot } from '@features/gallery/picker';+import { GalleryMediaSlot } from '@features/gallery/mediaSlot';import { memo, useCallback, useMemo } from 'react';import { areInputImagesEquivalent } from './upscaleComparators';diff --git a/invokeai/frontend/webv2/src/features/video/ui/VideoFrameImageField.tsx b/invokeai/frontend/webv2/src/features/video/ui/VideoFrameImageField.tsxindex 05fad5e90a..6a63583072 100644--- a/invokeai/frontend/webv2/src/features/video/ui/VideoFrameImageField.tsx+++ b/invokeai/frontend/webv2/src/features/video/ui/VideoFrameImageField.tsx@@ -1,8 +1,8 @@import type { GalleryItem } from '@features/gallery';-import type { GalleryMediaSlotLabels, GalleryMediaSlotValue } from '@features/gallery/picker';+import type { GalleryMediaSlotLabels, GalleryMediaSlotValue } from '@features/gallery/mediaSlot';import type { ImageWithDims } from '@features/generation/contracts';-import { GalleryMediaSlot } from '@features/gallery/picker';+import { GalleryMediaSlot } from '@features/gallery/mediaSlot';import { memo, useCallback, useMemo } from 'react';import { useVideoUiActions } from './VideoUiContext';diff --git a/invokeai/frontend/webv2/vite.config.mts b/invokeai/frontend/webv2/vite.config.mtsindex 4a3f5df23a..73784aa495 100644--- a/invokeai/frontend/webv2/vite.config.mts+++ b/invokeai/frontend/webv2/vite.config.mts@@ -97,6 +97,25 @@ const ROUTE_SHARED_MODULES = [// both routes above, scoped here to the editor alone because none of this// is reachable from the Launchpad.const EDITOR_BOOT_SHARED_MODULES = [+ // The gallery picker's trigger shell (every boot widget with an image slot+ // mounts one) plus the Gallery widget UI its lazy view shares; the widget+ // boots every editor route, so this moves bytes rather than adding requests.+ '/features/gallery/picker.ts',+ '/features/gallery/ui/GalleryBoardCover.tsx',+ '/features/gallery/ui/GalleryBoardRowShell.tsx',+ '/features/gallery/ui/GalleryItemSearch.tsx',+ '/features/gallery/ui/GallerySearchField.tsx',+ '/features/gallery/ui/GalleryTileFrame.tsx',+ '/features/gallery/ui/GalleryUploadButton.tsx',+ '/features/gallery/ui/GalleryViewTabs.tsx',+ '/features/gallery/ui/GalleryWidgetContext.tsx',+ '/features/gallery/ui/galleryBoardGroups.ts',+ '/features/gallery/ui/galleryBoardLabels.ts',+ '/features/gallery/ui/galleryGridLayout.ts',+ '/features/gallery/ui/picker/GalleryPickerPopover.tsx',+ '/features/gallery/ui/useGalleryData.ts',+ '/features/gallery/ui/useGalleryUploadAction.ts',+ '/features/gallery/ui/useGalleryUploadInput.ts','/workbench/shell/topbar/LayoutPresetAdminDialogs.tsx','/workbench/shell/topbar/LayoutPresetStrip.tsx','/workbench/shell/topbar/ProjectSwitcher.tsx',