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(widgets): constrain panel widget bodies to panel width

joshistoast33becc1e8475
diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/PanelBodySlot.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widget-frame/PanelBodySlot.browser.test.tsx
new file mode 100644
index 0000000000..a1d9ef566a
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/PanelBodySlot.browser.test.tsx
@@ -0,0 +1,72 @@
+/* oxlint-disable react-perf/jsx-no-new-object-as-prop */
+import { ChakraProvider } from '@chakra-ui/react';
+import { system } from '@theme/system';
+import { act } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import { afterEach, describe, expect, it } from 'vitest';
+
+import { PanelBodySlot } from './WidgetRenderer';
+
+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 interact = (action: () => void): Promise<void> =>
+ act(async () => {
+ action();
+ await new Promise<void>((resolve) => {
+ globalThis.setTimeout(resolve, 50);
+ });
+ });
+
+afterEach(async () => {
+ await interact(() => root?.unmount());
+ host?.remove();
+ host = null;
+ root = null;
+});
+
+const PANEL_WIDTH = 300;
+const LONG_UNBREAKABLE = 'x'.repeat(600);
+
+describe('PanelBodySlot', () => {
+ it('never lets intrinsically wide widget content stretch past the panel width', async () => {
+ host = document.createElement('div');
+ host.style.cssText = `display:flex;flex-direction:column;height:400px;width:${PANEL_WIDTH}px;`;
+ document.body.append(host);
+ root = createRoot(host);
+
+ await interact(() => {
+ root?.render(
+ <ChakraProvider value={system}>
+ <PanelBodySlot>
+ <div data-testid="widget-root">
+ {/* A row like QueueItemRow: clips its own content when constrained. */}
+ <div data-testid="row" style={{ overflow: 'hidden' }}>
+ <span style={{ whiteSpace: 'nowrap' }}>{LONG_UNBREAKABLE}</span>
+ </div>
+ {/* An unconstrained wide flex row like a button group. */}
+ <div data-testid="strip" style={{ display: 'flex', flexWrap: 'wrap' }}>
+ {Array.from({ length: 8 }, (_, index) => (
+ <button key={index} style={{ whiteSpace: 'nowrap' }}>
+ Wide recall verb {index}
+ </button>
+ ))}
+ </div>
+ </div>
+ </PanelBodySlot>
+ </ChakraProvider>
+ );
+ });
+
+ const widgetRoot = document.querySelector<HTMLElement>('[data-testid="widget-root"]')!;
+ const row = document.querySelector<HTMLElement>('[data-testid="row"]')!;
+ const strip = document.querySelector<HTMLElement>('[data-testid="strip"]')!;
+
+ expect(widgetRoot.getBoundingClientRect().width).toBeLessThanOrEqual(PANEL_WIDTH);
+ expect(row.getBoundingClientRect().width).toBeLessThanOrEqual(PANEL_WIDTH);
+ expect(strip.getBoundingClientRect().width).toBeLessThanOrEqual(PANEL_WIDTH);
+ // The wrap actually engaged: eight buttons cannot fit one 300px line.
+ expect(strip.getBoundingClientRect().height).toBeGreaterThan(row.getBoundingClientRect().height * 1.5);
+ });
+});
diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetRenderer.tsx b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetRenderer.tsx
index 9c09bf9157..80a3dee0ec 100644
--- a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetRenderer.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetRenderer.tsx
@@ -239,9 +239,19 @@ const HeaderSlot = memo(function HeaderSlot({
// Grid content with minH="full" stretches fill-height widget views (gallery,
// layers, preview) to the viewport while letting flowing views grow and scroll.
-const panelBodyContentProps = { display: 'grid', minH: 'full' } as const;
+// The explicit minmax(0, 1fr) column is load-bearing: an implicit auto track
+// sizes to its item's max-content, so any long unbreakable text or wide row
+// inside a widget (prompt strings, UUIDs, button groups) silently stretches
+// the widget past its panel and clips. Panels only ever scroll vertically.
+// Covered by PanelBodySlot.browser.test.tsx.
+const panelBodyContentProps = {
+ display: 'grid',
+ gridTemplateColumns: 'minmax(0, 1fr)',
+ maxW: 'full',
+ minH: 'full',
+} as const;
-const PanelBodySlot = ({ children }: { children: React.ReactNode }) => (
+export const PanelBodySlot = ({ children }: { children: React.ReactNode }) => (
<Scrollable contentProps={panelBodyContentProps} flex="1" minH="0" minW="0" overflowX="hidden">
{children}
</Scrollable>
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/queue/QueueItemDetails.tsx b/invokeai/frontend/webv2/src/workbench/widgets/queue/QueueItemDetails.tsx
index a63fec4ab4..9b9ecec9ae 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/queue/QueueItemDetails.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/queue/QueueItemDetails.tsx
@@ -13,7 +13,9 @@ import { useLocalGenerateValues } from './useLocalGenerateValues';
const DetailRow = ({ label, children }: { label: string; children: ReactNode }) => (
<DataList.Item key={label} alignItems="start">
<DataList.ItemLabel>{label}</DataList.ItemLabel>
- <DataList.ItemValue fontFamily="mono" fontSize="2xs">
+ {/* minW=0 lets unbreakable values (batch UUIDs) truncate instead of
+ pushing the row's min-content past the panel. */}
+ <DataList.ItemValue fontFamily="mono" fontSize="2xs" minW="0">
{children}
</DataList.ItemValue>
</DataList.Item>