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(webv2): contain center header actions

joshistoast218dddc3a305
diff --git a/invokeai/frontend/webv2/src/workbench/shell/CenterArea.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/shell/CenterArea.browser.test.tsx
new file mode 100644
index 0000000000..075e98da39
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/shell/CenterArea.browser.test.tsx
@@ -0,0 +1,146 @@
+/* oxlint-disable react-perf/jsx-no-new-object-as-prop */
+import { Box, ChakraProvider, HStack, Text } from '@chakra-ui/react';
+import { system } from '@theme/system';
+import { createInstance } from 'i18next';
+import { act, type ReactNode } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import { I18nextProvider, initReactI18next } from 'react-i18next';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+
+const centerAreaMocks = vi.hoisted(() => {
+ const icon = () => null;
+ const activeItem = {
+ icon,
+ id: 'preview-instance',
+ instance: { id: 'preview-instance' },
+ label: 'Preview',
+ status: 'enabled',
+ typeId: 'preview',
+ widget: {
+ manifest: {
+ centerPlacement: 'view',
+ chrome: { header: 'visible' },
+ icon,
+ },
+ status: 'enabled',
+ },
+ };
+
+ return {
+ activeItem,
+ project: {
+ id: 'test-project',
+ invocation: { sourceId: 'generate' },
+ queue: { items: [] },
+ widgetInstances: {},
+ widgetRegions: {
+ center: { activeInstanceId: activeItem.id, instanceIds: [activeItem.id], isCollapsed: false, sizePx: 0 },
+ },
+ },
+ };
+});
+
+vi.mock('@features/models', () => ({ useModelLoads: () => [] }));
+vi.mock('@features/queue/contracts', () => ({
+ getProjectQueueIndicatorState: () => ({ hasOpenQueueWork: false, progressState: null, runningQueueItemId: null }),
+}));
+vi.mock('@features/queue/react', () => ({ useQueueItemProgress: () => null }));
+vi.mock('@workbench/focusRegions', () => ({ useFocusRegionProps: () => ({}) }));
+vi.mock('@workbench/widgetRegionViewModel', () => ({
+ createWidgetRegionViewModelFromState: () => ({ placedItems: [centerAreaMocks.activeItem] }),
+ getWidgetRegionItems: () => [],
+ isRequiredCenterView: () => true,
+}));
+vi.mock('@workbench/widgetRegistry', () => ({ getWidgetById: () => undefined, getWidgetsForRegion: () => [] }));
+vi.mock('@workbench/WorkbenchContext', () => ({
+ useActiveProjectSelector: (selector: (project: typeof centerAreaMocks.project) => unknown) =>
+ selector(centerAreaMocks.project),
+ useWorkbenchCommands: () => ({ widgets: {} }),
+ useWorkbenchSelector: (selector: (snapshot: { backendConnection: { status: string } }) => unknown) =>
+ selector({ backendConnection: { status: 'connected' } }),
+}));
+vi.mock('@workbench/widget-frame', () => ({
+ WidgetChromeSlotById: ({ slot }: { slot: 'actions' | 'label' }) => {
+ if (slot === 'actions') {
+ return <Box data-testid="trailing-actions" flexShrink={0} w="189px" />;
+ }
+
+ return (
+ <HStack flex="1" minW="0" w="300px">
+ <Text flexShrink={0}>Panther and the Flask</Text>
+ <Text truncate>a423880b-184a-4910-977e-fe7d7fa9f732.png</Text>
+ </HStack>
+ );
+ },
+ WidgetRendererById: () => <Box h="full" w="full" />,
+ WidgetSourceLockBadge: () => null,
+ useWidgetIntentPreloadProps: () => ({}),
+}));
+
+import { CenterArea } from './CenterArea';
+
+const i18n = createInstance();
+void i18n.use(initReactI18next).init({
+ fallbackLng: 'en',
+ initAsync: false,
+ lng: 'en',
+ resources: {
+ en: {
+ translation: {
+ widgets: {
+ centerRegion: 'Center view',
+ centerViewLabel: 'Center view: {{label}}',
+ },
+ },
+ },
+ },
+});
+
+let host: HTMLDivElement | null = null;
+let root: Root | null = null;
+(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
+
+const render = async (children: ReactNode) => {
+ host = document.createElement('div');
+ host.style.cssText = 'display:flex;height:320px;width:571px;';
+ document.body.append(host);
+ root = createRoot(host);
+
+ await act(async () => {
+ root?.render(
+ <I18nextProvider i18n={i18n}>
+ <ChakraProvider value={system}>{children}</ChakraProvider>
+ </I18nextProvider>
+ );
+ await Promise.resolve();
+ });
+};
+
+afterEach(async () => {
+ await act(async () => {
+ root?.unmount();
+ await Promise.resolve();
+ });
+ host?.remove();
+ host = null;
+ root = null;
+});
+
+describe('CenterArea chrome layout', () => {
+ it('keeps non-shrinking trailing actions inside the center region', async () => {
+ await render(<CenterArea />);
+
+ const centerRegion = host?.querySelector<HTMLElement>('section');
+ const trailingActions = host?.querySelector<HTMLElement>('[data-testid="trailing-actions"]');
+
+ expect(centerRegion).not.toBeNull();
+ expect(trailingActions).not.toBeNull();
+ if (!centerRegion || !trailingActions) {
+ throw new Error('Expected center chrome geometry.');
+ }
+
+ expect(trailingActions.getBoundingClientRect().right).toBeLessThanOrEqual(
+ centerRegion.getBoundingClientRect().right
+ );
+ });
+});
diff --git a/invokeai/frontend/webv2/src/workbench/shell/CenterArea.tsx b/invokeai/frontend/webv2/src/workbench/shell/CenterArea.tsx
index fef7ce516d..e29ac16813 100644
--- a/invokeai/frontend/webv2/src/workbench/shell/CenterArea.tsx
+++ b/invokeai/frontend/webv2/src/workbench/shell/CenterArea.tsx
@@ -199,7 +199,7 @@ export const CenterArea = () => {
</ChromeIsland>
{activeItem && activeItem.widget.manifest.chrome?.header !== 'hidden' ? (
- <ChromeIsland>
+ <ChromeIsland flexShrink={0}>
{centerToolbarItems.map((toolbarItem) => (
<WidgetRendererById
key={toolbarItem.id}
@@ -220,11 +220,12 @@ export const CenterArea = () => {
);
};
-const ChromeIsland = ({ children }: { children: ReactNode }) => (
+const ChromeIsland = ({ children, flexShrink = 1 }: { children: ReactNode; flexShrink?: 0 | 1 }) => (
<HStack
bg="bg.subtle"
borderColor="border.subtle"
borderWidth="1px"
+ flexShrink={flexShrink}
gap="0.5"
h="8"
minW="0"