Skip to content

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.

fix(ui): render the floated-center notice with the center again

Josh Corbettcbcbd491fed1
diff --git a/invokeai/frontend/webv2/src/workbench/shell/CenterArea.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/shell/CenterArea.browser.test.tsx
index c28b13d1db..e2e9d956bc 100644
--- a/invokeai/frontend/webv2/src/workbench/shell/CenterArea.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/shell/CenterArea.browser.test.tsx
@@ -19,11 +19,6 @@ interface CenterAreaTestProject {
}
const centerAreaMocks = vi.hoisted(() => {
- let didRequestFloatedCenterModule = false;
- let resolveFloatedCenterModule!: () => void;
- const floatedCenterModulePending = new Promise<void>((resolve) => {
- resolveFloatedCenterModule = resolve;
- });
const icon = () => null;
// Use a settled resource so the center icon reads synchronously without suspending.
const loadedImplementation = () => {
@@ -64,16 +59,10 @@ const centerAreaMocks = vi.hoisted(() => {
return {
activeItem,
- didRequestFloatedCenterModule: () => didRequestFloatedCenterModule,
dockFloating: vi.fn(),
- floatedCenterModulePending,
focusFloating: vi.fn(),
focusRegion: vi.fn(),
project,
- requestFloatedCenterModule: () => {
- didRequestFloatedCenterModule = true;
- },
- resolveFloatedCenterModule: () => resolveFloatedCenterModule(),
revealFloating: vi.fn(),
};
});
@@ -136,11 +125,6 @@ vi.mock('@workbench/widget-frame', () => ({
WidgetSourceLockBadge: () => null,
useWidgetIntentPreloadProps: () => ({}),
}));
-vi.mock('./FloatedCenterView', async (importOriginal) => {
- centerAreaMocks.requestFloatedCenterModule();
- await centerAreaMocks.floatedCenterModulePending;
- return importOriginal();
-});
import { CenterArea } from './CenterArea';
@@ -241,28 +225,13 @@ describe('CenterArea with its last view floating', () => {
const button = (name: string) =>
[...host!.querySelectorAll<HTMLButtonElement>('button')].find((candidate) => candidate.textContent === name);
- it('keeps the center recovery controls available while their lazy chunk loads', async () => {
- floatLastView();
- await render(<CenterArea />);
-
- try {
- await vi.waitFor(() => expect(centerAreaMocks.didRequestFloatedCenterModule()).toBe(true));
- expect(host?.textContent).toContain('Preview is in a floating window');
- expect(button('Show window')).not.toBeUndefined();
- } finally {
- act(() => {
- centerAreaMocks.resolveFloatedCenterModule();
- });
- await vi.waitFor(() => expect(host?.textContent).toContain('Preview is in a floating window'));
- }
- });
-
it('says where the view went and offers both ways back, instead of calling it unavailable', async () => {
floatLastView();
await render(<CenterArea />);
- // The view loads lazily, once something floats.
- await vi.waitFor(() => expect(host?.textContent).toContain('Preview is in a floating window'));
+ // In the first render: the center never shows blank while its view floats.
+ expect(host?.textContent).toContain('Preview is in a floating window');
+ expect(button('Show window')).not.toBeUndefined();
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.tsx
index 8fe8221392..57fb312b38 100644
--- a/invokeai/frontend/webv2/src/workbench/shell/CenterArea.tsx
+++ b/invokeai/frontend/webv2/src/workbench/shell/CenterArea.tsx
@@ -6,8 +6,9 @@ import type {
} from '@workbench/widgetRegionViewModel';
import { Box, Flex, HStack, Icon, Menu, Portal, Text } from '@chakra-ui/react';
-import { IconButton, MenuContent } from '@platform/ui';
-import { useFocusRegionProps } from '@workbench/focusRegions';
+import { flushWorkbenchDrafts } from '@platform/react/draftRegistry';
+import { Button, IconButton, MenuContent } from '@platform/ui';
+import { useFocusRegionProps, useWorkbenchFocus } from '@workbench/focusRegions';
import { WidgetIcon } from '@workbench/iconResolver';
import {
WidgetChromeSlotById,
@@ -29,7 +30,7 @@ import {
import { getWidgetById, getWidgetsForRegion } from '@workbench/widgetRegistry';
import { useActiveProjectId, useActiveProjectSelector, useWorkbenchCommands } from '@workbench/WorkbenchContext';
import { CheckIcon, ChevronDownIcon, XIcon } from 'lucide-react';
-import { Activity, lazy, Suspense, use, useCallback, useMemo, useRef, type ReactNode } from 'react';
+import { Activity, Suspense, use, useCallback, useMemo, useRef, type ReactNode } from 'react';
import { useTranslation } from 'react-i18next';
import {
@@ -48,12 +49,6 @@ 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);
@@ -176,16 +171,14 @@ export const CenterArea = () => {
</Activity>
))
) : 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>
+ <FloatedCenterView
+ dockLabel={resolveDockLabel(floatedPlacement.returnRegion, t)}
+ instanceId={floatedInstance.id}
+ label={
+ floatedInstance.title ?? (floatedWidget ? getWidgetLabel(floatedWidget.manifest) : floatedInstance.id)
+ }
+ typeId={floatedInstance.typeId}
+ />
) : (
<FallbackCenterView label="Center widget unavailable" />
)}
@@ -437,6 +430,53 @@ 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 = ({
+ dockLabel,
+ instanceId,
+ label,
+ typeId,
+}: {
+ /** The Dock button's label, naming where the window returns to. */
+ dockLabel: string;
+ instanceId: string;
+ label: string;
+ typeId: string;
+}) => {
+ 'use no memo';
+ // A cold path that renders only while the center's last view floats: it needs no memo cache, and skipping one
+ // keeps it small in the editor's startup chunk, whose size budget guards it.
+ 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>
+ );
+};
+
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.tsx
deleted file mode 100644
index 51c9b2ceb5..0000000000
--- a/invokeai/frontend/webv2/src/workbench/shell/FloatedCenterView.tsx
+++ /dev/null
@@ -1,51 +0,0 @@
-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>
- );
-};