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(ui): keep the floated-center notice out of the editor's startup bundle
Josh Corbett3b6c55c351cd
diff --git a/invokeai/frontend/webv2/src/workbench/shell/CenterArea.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/shell/CenterArea.browser.test.tsxindex 50b07f0be5..389dc0fac1 100644--- a/invokeai/frontend/webv2/src/workbench/shell/CenterArea.browser.test.tsx+++ b/invokeai/frontend/webv2/src/workbench/shell/CenterArea.browser.test.tsx@@ -229,7 +229,8 @@ describe('CenterArea with its last view floating', () => {floatLastView();await render(<CenterArea />);- expect(host?.textContent).toContain('Preview is in a floating window');+ // The view loads lazily, once something floats.+ await vi.waitFor(() => expect(host?.textContent).toContain('Preview is in a floating window'));expect(host?.textContent).not.toContain('unavailable');await act(async () => {diff --git a/invokeai/frontend/webv2/src/workbench/shell/CenterArea.tsx b/invokeai/frontend/webv2/src/workbench/shell/CenterArea.tsxindex 51f49913b5..8fe8221392 100644--- a/invokeai/frontend/webv2/src/workbench/shell/CenterArea.tsx+++ b/invokeai/frontend/webv2/src/workbench/shell/CenterArea.tsx@@ -1,4 +1,3 @@-import type { WidgetRegion } from '@workbench/layoutContracts';import type { RegisteredWidget } from '@workbench/widgetContracts';import type {PlacedWidgetRegionItem,@@ -7,9 +6,8 @@ import type {} from '@workbench/widgetRegionViewModel';import { Box, Flex, HStack, Icon, Menu, Portal, Text } from '@chakra-ui/react';-import { flushWorkbenchDrafts } from '@platform/react/draftRegistry';-import { Button, IconButton, MenuContent } from '@platform/ui';-import { useFocusRegionProps, useWorkbenchFocus } from '@workbench/focusRegions';+import { IconButton, MenuContent } from '@platform/ui';+import { useFocusRegionProps } from '@workbench/focusRegions';import { WidgetIcon } from '@workbench/iconResolver';import {WidgetChromeSlotById,@@ -20,7 +18,7 @@ import {type WidgetEnableMenuItem,} from '@workbench/widget-frame';import { areWidgetRenderInstancesEqual } from '@workbench/widget-frame/widgetRenderInstance';-import { resolveDockLabel, resolveWidgetInstanceLabel, resolveWidgetLabel } from '@workbench/widgetLabels';+import { resolveDockLabel, resolveWidgetLabel } from '@workbench/widgetLabels';import { closeWidgetPlacement, openWidgetPlacement, revealWidgetPlacement } from '@workbench/widgetPlacementCommands';import { areWidgetPlacementProjectsEqual, getWidgetPlacementProject } from '@workbench/widgetPlacementMeta';import {@@ -31,7 +29,7 @@ import {import { getWidgetById, getWidgetsForRegion } from '@workbench/widgetRegistry';import { useActiveProjectId, useActiveProjectSelector, useWorkbenchCommands } from '@workbench/WorkbenchContext';import { CheckIcon, ChevronDownIcon, XIcon } from 'lucide-react';-import { Activity, Suspense, use, useCallback, useMemo, useRef, type ReactNode } from 'react';+import { Activity, lazy, Suspense, use, useCallback, useMemo, useRef, type ReactNode } from 'react';import { useTranslation } from 'react-i18next';import {@@ -50,6 +48,12 @@ const CENTER_CHROME_INSET_STYLE = { '--wb-center-chrome-inset': '3rem' } as Reac// Reserve a usable center width; side panels shrink to honor this floor.const CENTER_MIN_WIDTH = '20rem';+// Shown only while the center's last view floats, so it loads once something floats rather than at startup. Its+// labels are resolved here, so it shares no module with the startup chunks that would have to split out.+const FloatedCenterView = lazy(() =>+ import('./FloatedCenterView').then((module) => ({ default: module.FloatedCenterView }))+);+export const CenterArea = () => {const { t } = useTranslation();const placementProject = useActiveProjectSelector(getWidgetPlacementProject, areWidgetPlacementProjectsEqual);@@ -90,13 +94,10 @@ export const CenterArea = () => {: centerViewItems[0]?.id;const activeItem = centerViewItems.find((item) => item.id === activeCenterViewId);// The center emptied because its last view floated away: say so, rather than call the view unavailable.- const floatedView =- centerRegion.instanceIds.length === 0- ? {- instance: placementProject.widgetInstances[centerRegion.activeInstanceId],- placement: placementProject.floatingPlacements?.[centerRegion.activeInstanceId],- }- : null;+ const floatedInstance =+ centerRegion.instanceIds.length === 0 ? placementProject.widgetInstances[centerRegion.activeInstanceId] : undefined;+ const floatedPlacement = floatedInstance && placementProject.floatingPlacements?.[floatedInstance.id];+ const floatedWidget = floatedInstance && getWidgetById(floatedInstance.typeId);const projectId = useActiveProjectId();const activeIdsElsewhere = useActiveProjectSelector((project) => getActiveInstanceIdsOutside(project.widgetRegions, 'center', project.floatingWidgets),@@ -174,13 +175,17 @@ export const CenterArea = () => {<KeptCenterViewSlot instanceId={instanceId} /></Activity>))- ) : floatedView?.instance && floatedView.placement ? (- <FloatedCenterView- instanceId={floatedView.instance.id}- returnRegion={floatedView.placement.returnRegion}- title={floatedView.instance.title}- typeId={floatedView.instance.typeId}- />+ ) : floatedInstance && floatedPlacement ? (+ <Suspense fallback={null}>+ <FloatedCenterView+ dockLabel={resolveDockLabel(floatedPlacement.returnRegion, t)}+ instanceId={floatedInstance.id}+ label={+ floatedInstance.title ?? (floatedWidget ? getWidgetLabel(floatedWidget.manifest) : floatedInstance.id)+ }+ typeId={floatedInstance.typeId}+ />+ </Suspense>) : (<FallbackCenterView label="Center widget unavailable" />)}@@ -432,51 +437,6 @@ const KeptCenterViewSlot = ({ instanceId }: { instanceId: string }) => {return <WidgetRendererById instanceId={instance.id} widget={widget} region="center" />;};-/** The empty center while its last view is a floating window: where the view went, and the two ways back. */-const FloatedCenterView = ({- instanceId,- returnRegion,- title,- typeId,-}: {- instanceId: string;- returnRegion: WidgetRegion;- title?: string;- typeId: string;-}) => {- const { t } = useTranslation();- const { widgets } = useWorkbenchCommands();- const { focusFloating, focusRegion } = useWorkbenchFocus();- const widget = getWidgetById(typeId);- const label = widget ? resolveWidgetInstanceLabel({ title }, widget.manifest, t) : (title ?? instanceId);- const handleShow = useCallback(() => {- widgets.revealFloating(instanceId);- focusFloating(instanceId);- }, [focusFloating, instanceId, widgets]);- // Docking from here always gives the center its view back, so focus follows it.- const handleDock = useCallback(() => {- flushWorkbenchDrafts();- widgets.dockFloating(instanceId);- focusRegion('center', typeId);- }, [focusRegion, instanceId, typeId, widgets]);-- return (- <Flex align="center" direction="column" gap="3" h="full" justify="center" px="6" textAlign="center" w="full">- <Text color="fg.muted" fontSize="sm">- {t('widgets.floating.centerFloating', { label })}- </Text>- <HStack gap="2" wrap="wrap" justify="center">- <Button size="xs" variant="outline" onClick={handleShow}>- {t('widgets.floating.showWindow')}- </Button>- <Button size="xs" variant="outline" onClick={handleDock}>- {resolveDockLabel(returnRegion, t)}- </Button>- </HStack>- </Flex>- );-};-const FallbackCenterView = ({ label }: { label: string }) => (<Flex align="center" h="full" justify="center" w="full"><Text color="fg.subtle" fontSize="sm" textTransform="capitalize">diff --git a/invokeai/frontend/webv2/src/workbench/shell/FloatedCenterView.tsx b/invokeai/frontend/webv2/src/workbench/shell/FloatedCenterView.tsxnew file mode 100644index 0000000000..51c9b2ceb5--- /dev/null+++ b/invokeai/frontend/webv2/src/workbench/shell/FloatedCenterView.tsx@@ -0,0 +1,51 @@+import { Flex, HStack, Text } from '@chakra-ui/react';+import { flushWorkbenchDrafts } from '@platform/react/draftRegistry';+import { Button } from '@platform/ui';+import { useWorkbenchFocus } from '@workbench/focusRegions';+import { useWorkbenchCommands } from '@workbench/WorkbenchContext';+import { useCallback } from 'react';+import { useTranslation } from 'react-i18next';++/** The empty center while its last view is a floating window: where the view went, and the two ways back. */+export const FloatedCenterView = ({+ dockLabel,+ instanceId,+ label,+ typeId,+}: {+ /** The Dock button's label, naming where the window returns to. */+ dockLabel: string;+ instanceId: string;+ label: string;+ typeId: string;+}) => {+ const { t } = useTranslation();+ const { widgets } = useWorkbenchCommands();+ const { focusFloating, focusRegion } = useWorkbenchFocus();+ const handleShow = useCallback(() => {+ widgets.revealFloating(instanceId);+ focusFloating(instanceId);+ }, [focusFloating, instanceId, widgets]);+ // Docking from here always gives the center its view back, so focus follows it.+ const handleDock = useCallback(() => {+ flushWorkbenchDrafts();+ widgets.dockFloating(instanceId);+ focusRegion('center', typeId);+ }, [focusRegion, instanceId, typeId, widgets]);++ return (+ <Flex align="center" direction="column" gap="3" h="full" justify="center" px="6" textAlign="center" w="full">+ <Text color="fg.muted" fontSize="sm">+ {t('widgets.floating.centerFloating', { label })}+ </Text>+ <HStack gap="2" wrap="wrap" justify="center">+ <Button size="xs" variant="outline" onClick={handleShow}>+ {t('widgets.floating.showWindow')}+ </Button>+ <Button size="xs" variant="outline" onClick={handleDock}>+ {dockLabel}+ </Button>+ </HStack>+ </Flex>+ );+};diff --git a/invokeai/frontend/webv2/src/workbench/shell/WorkbenchShell.tsx b/invokeai/frontend/webv2/src/workbench/shell/WorkbenchShell.tsxindex 20d2458128..ce1a04792a 100644--- a/invokeai/frontend/webv2/src/workbench/shell/WorkbenchShell.tsx+++ b/invokeai/frontend/webv2/src/workbench/shell/WorkbenchShell.tsx@@ -241,45 +241,27 @@ export const WorkbenchShell = () => {[focusRegion, isLeftPanelShown, isRightPanelShown, placementProject, widgets]);// The enable menu stays open and keeps focus, so removing a window from it moves none.- const handleToggleLeft = useCallback(- (item: (typeof leftMenuItems)[number]) =>+ const toggleRailItem = useCallback(+ (region: WidgetBarGroup['region'], item: (typeof leftMenuItems)[number]) =>item.isEnabled && item.isFloating? removeFloatingPlacement({ instanceId: item.id, project: placementProject, widgets }): item.isEnabled- ? closeWidgetPlacement({- widgets,- getWidgetById,- instanceId: item.id,- project: placementProject,- region: 'left',- })+ ? closeWidgetPlacement({ widgets, getWidgetById, instanceId: item.id, project: placementProject, region }): openWidgetPlacement({widgets,getWidgetsForRegion,- options: { createNew: item.allowMultiple, preferredRegions: ['left'] },+ options: { createNew: item.allowMultiple, preferredRegions: [region] },typeId: item.typeId,}),[placementProject, widgets]);+ const handleToggleLeft = useCallback(+ (item: (typeof leftMenuItems)[number]) => toggleRailItem('left', item),+ [toggleRailItem]+ );const handleToggleRight = useCallback(- (item: (typeof rightMenuItems)[number]) =>- item.isEnabled && item.isFloating- ? removeFloatingPlacement({ instanceId: item.id, project: placementProject, widgets })- : item.isEnabled- ? closeWidgetPlacement({- widgets,- getWidgetById,- instanceId: item.id,- project: placementProject,- region: 'right',- })- : openWidgetPlacement({- widgets,- getWidgetsForRegion,- options: { createNew: item.allowMultiple, preferredRegions: ['right'] },- typeId: item.typeId,- }),- [placementProject, widgets]+ (item: (typeof rightMenuItems)[number]) => toggleRailItem('right', item),+ [toggleRailItem]);const leftRailGroups = useMemo(() => [