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): keep crashed widgets inside their region

joshistoast21f59ddc0461
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.json
index f5aff2b376..d71f18ce0a 100644
--- a/invokeai/frontend/webv2/public/locales/en.json
+++ b/invokeai/frontend/webv2/public/locales/en.json
@@ -784,6 +784,12 @@
},
"widgets": {
"actionsLabel": "{{label}} actions",
+ "failure": {
+ "compactLabel": "{{label}} failed — select to retry",
+ "copyError": "Copy Error",
+ "retry": "Retry",
+ "title": "{{label}} failed"
+ },
"loadingLabel": "Loading {{label}}",
"removeWidget": "Remove {{label}}",
"panelLabel": "{{region}} widget panel",
diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFailureBoundary.tsx b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFailureBoundary.tsx
index ccaa469371..8430ece9f9 100644
--- a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFailureBoundary.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFailureBoundary.tsx
@@ -1,13 +1,33 @@
-import type { WidgetId } from '@workbench/widgetContracts';
+import type {
+ RegisteredWidget,
+ WidgetId,
+ WidgetInstanceRuntimeMeta,
+ WidgetViewProps,
+} from '@workbench/widgetContracts';
-import { Code, ScrollArea, Stack, Text } from '@chakra-ui/react';
+import { Box, Code, Flex, HStack, ScrollArea, Stack, Text, useRecipe } from '@chakra-ui/react';
import { Button } from '@platform/ui';
+import { chipRecipe } from '@theme/recipes';
+import { resolveWidgetInstanceLabel } from '@workbench/widgetLabels';
+import { TriangleAlertIcon } from 'lucide-react';
import { Component, type ErrorInfo, type ReactNode } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { WidgetPanelFrame, WidgetTooltipFrame } from './WidgetFrames';
interface WidgetFailureBoundaryProps {
- widgetId: WidgetId;
- resetKey: string;
children: ReactNode;
+ /**
+ * Presentation context, mirroring what `WidgetLoadingFallback` receives. When
+ * supplied, the fallback keeps the widget's own frame — panel width, overflow
+ * clamp and resize handle survive the crash. Headless hosts omit it.
+ */
+ instance?: WidgetInstanceRuntimeMeta;
+ presentation?: WidgetViewProps['presentation'];
+ region?: WidgetViewProps['region'];
+ resetKey: string;
+ widget?: RegisteredWidget;
+ widgetId: WidgetId;
onRetry?: () => void;
}
@@ -17,6 +37,167 @@ interface WidgetFailureBoundaryState {
resetKey: string;
}
+interface WidgetFailureFallbackProps extends Omit<WidgetFailureBoundaryProps, 'children' | 'resetKey' | 'onRetry'> {
+ details: string;
+ onCopy: () => void;
+ onRetry: () => void;
+}
+
+/** The error card itself: title, expanded detail, and the two recovery verbs. */
+const WidgetFailureCard = ({
+ details,
+ label,
+ onCopy,
+ onRetry,
+}: {
+ details: string;
+ label: string;
+ onCopy: () => void;
+ onRetry: () => void;
+}) => {
+ const { t } = useTranslation();
+
+ return (
+ <Stack bg="bg.muted" borderColor="border.error" borderWidth="1px" gap="2" p="3" rounded="md">
+ <Text color="fg.error" fontSize="xs" fontWeight="700">
+ {t('widgets.failure.title', { label })}
+ </Text>
+ <ScrollArea.Root maxH="8rem" size="xs" variant="hover">
+ <ScrollArea.Viewport maxH="8rem">
+ <ScrollArea.Content>
+ <Code display="block" p="2" whiteSpace="pre-wrap">
+ {details}
+ </Code>
+ </ScrollArea.Content>
+ </ScrollArea.Viewport>
+ <ScrollArea.Scrollbar>
+ <ScrollArea.Thumb />
+ </ScrollArea.Scrollbar>
+ <ScrollArea.Scrollbar orientation="horizontal">
+ <ScrollArea.Thumb />
+ </ScrollArea.Scrollbar>
+ <ScrollArea.Corner />
+ </ScrollArea.Root>
+ <Stack direction="row" gap="2">
+ <Button alignSelf="start" size="2xs" variant="outline" onClick={onRetry}>
+ {t('widgets.failure.retry')}
+ </Button>
+ <Button alignSelf="start" size="2xs" variant="outline" onClick={onCopy}>
+ {t('widgets.failure.copyError')}
+ </Button>
+ </Stack>
+ </Stack>
+ );
+};
+
+/** Status-bar scale: the strip is 24px tall, so the detail rides in the title tooltip. */
+const CompactWidgetFailure = ({ details, label, onRetry }: { details: string; label: string; onRetry: () => void }) => {
+ const { t } = useTranslation();
+ const recipe = useRecipe({ recipe: chipRecipe });
+
+ return (
+ <HStack
+ aria-label={t('widgets.failure.compactLabel', { label })}
+ color="fg.error"
+ css={recipe()}
+ role="status"
+ title={details}
+ onClick={onRetry}
+ >
+ <TriangleAlertIcon size={12} />
+ <Text data-widget-identity-label="" whiteSpace="nowrap">
+ {label}
+ </Text>
+ </HStack>
+ );
+};
+
+const WidgetFailureHeader = ({ label, region }: { label: string; region: WidgetViewProps['region'] }) => (
+ <Box bg={region === 'center' ? 'bg' : 'bg.subtle'} flexShrink="0">
+ <HStack borderBottomWidth="1px" h="10" justify="space-between" pe="2" ps="3">
+ <HStack color="fg.error" flex="1" gap="1.5" minW="0">
+ <TriangleAlertIcon size={14} />
+ <Text data-widget-identity-label="" fontSize="xs" fontWeight="700">
+ {label}
+ </Text>
+ </HStack>
+ </HStack>
+ </Box>
+);
+
+/**
+ * Presentation- and region-aware failure UI, the twin of `WidgetLoadingFallback`.
+ * Rendering the bare card everywhere used to blow a crashed widget out of its
+ * region: in the status bar it overflowed a 24px strip, and in a side panel it
+ * destroyed the frame that carries the panel width and the resize handle.
+ */
+const WidgetFailureFallback = ({
+ details,
+ instance,
+ presentation,
+ region,
+ widget,
+ widgetId,
+ onCopy,
+ onRetry,
+}: WidgetFailureFallbackProps) => {
+ const { t } = useTranslation();
+ const label = widget ? resolveWidgetInstanceLabel(instance ?? {}, widget.manifest, t) : widgetId;
+
+ if (presentation === 'compact') {
+ return <CompactWidgetFailure details={details} label={label} onRetry={onRetry} />;
+ }
+
+ if (presentation === 'tooltip' && widget) {
+ return (
+ <WidgetTooltipFrame icon={widget.manifest.icon}>
+ <Text color="fg.error" fontSize="xs" fontWeight="700">
+ {t('widgets.failure.title', { label })}
+ </Text>
+ <Text color="fg.muted" fontSize="2xs">
+ {details}
+ </Text>
+ </WidgetTooltipFrame>
+ );
+ }
+
+ const isPanel = region === 'left' || region === 'right' || region === 'bottom';
+
+ if (!isPanel && region !== 'center') {
+ return <WidgetFailureCard details={details} label={label} onCopy={onCopy} onRetry={onRetry} />;
+ }
+
+ const framed = (
+ <>
+ {widget?.manifest.chrome?.header === 'hidden' ? null : <WidgetFailureHeader label={label} region={region} />}
+ <Box flex="1" minH="0" overflow="auto" p="2">
+ <WidgetFailureCard details={details} label={label} onCopy={onCopy} onRetry={onRetry} />
+ </Box>
+ </>
+ );
+
+ // Keeping the widget's own frame is the whole point: the panel frame carries
+ // the region width, the overflow clamp and the resize handle.
+ return isPanel ? (
+ <WidgetPanelFrame instanceId={instance?.id} region={region} typeId={instance?.typeId}>
+ {framed}
+ </WidgetPanelFrame>
+ ) : (
+ <Flex
+ bg="bg.inset"
+ data-hotkey-widget-instance-id={instance?.id}
+ data-hotkey-widget-region={region}
+ data-hotkey-widget-type-id={instance?.typeId}
+ direction="column"
+ h="full"
+ minH="0"
+ w="full"
+ >
+ {framed}
+ </Flex>
+ );
+};
+
export class WidgetFailureBoundary extends Component<WidgetFailureBoundaryProps, WidgetFailureBoundaryState> {
state: WidgetFailureBoundaryState = { resetKey: this.props.resetKey };
@@ -53,45 +234,26 @@ export class WidgetFailureBoundary extends Component<WidgetFailureBoundaryProps,
}
render() {
- const { children, widgetId } = this.props;
+ const { children, instance, presentation, region, widget, widgetId } = this.props;
const { details, error } = this.state;
if (!error) {
return children;
}
- const copyableDetails = details ?? error.message;
-
return (
- <Stack bg="bg.muted" borderColor="border.error" borderWidth="1px" gap="2" p="3" rounded="md">
- <Text color="fg.error" fontSize="xs" fontWeight="700">
- Widget failed: {widgetId}
- </Text>
- <ScrollArea.Root maxH="8rem" size="xs" variant="hover">
- <ScrollArea.Viewport maxH="8rem">
- <ScrollArea.Content>
- <Code display="block" p="2" whiteSpace="pre-wrap">
- {copyableDetails}
- </Code>
- </ScrollArea.Content>
- </ScrollArea.Viewport>
- <ScrollArea.Scrollbar>
- <ScrollArea.Thumb />
- </ScrollArea.Scrollbar>
- <ScrollArea.Scrollbar orientation="horizontal">
- <ScrollArea.Thumb />
- </ScrollArea.Scrollbar>
- <ScrollArea.Corner />
- </ScrollArea.Root>
- <Stack direction="row" gap="2">
- <Button alignSelf="start" size="2xs" variant="outline" onClick={this.handleRetry}>
- Retry
- </Button>
- <Button alignSelf="start" size="2xs" variant="outline" onClick={this.handleCopyError}>
- Copy Error
- </Button>
- </Stack>
- </Stack>
+ <Box data-testid="widget-failure" display="contents">
+ <WidgetFailureFallback
+ details={details ?? error.message}
+ instance={instance}
+ presentation={presentation}
+ region={region}
+ widget={widget}
+ widgetId={widgetId}
+ onCopy={this.handleCopyError}
+ onRetry={this.handleRetry}
+ />
+ </Box>
);
}
}
diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetHosts.tsx b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetHosts.tsx
index 104dda0544..37a37f45d9 100644
--- a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetHosts.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetHosts.tsx
@@ -19,6 +19,7 @@ const WidgetHostBoundary = ({ widget }: { widget: ReturnType<typeof getWidgetHos
return widget.manifest.failurePolicy.isolateRenderFailure ? (
<WidgetFailureBoundary
resetKey={widget.manifest.id}
+ widget={widget}
widgetId={widget.manifest.id}
onRetry={widget.implementation.retry}
>
diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetRenderer.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetRenderer.browser.test.tsx
index 7d2d9df087..9d2df19a6f 100644
--- a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetRenderer.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetRenderer.browser.test.tsx
@@ -9,6 +9,7 @@ import type {
import { ChakraProvider, Stack, Text } from '@chakra-ui/react';
import { StatusWidgetChip } from '@platform/ui';
import { system } from '@theme/system';
+import { FocusRegionProvider } from '@workbench/focusRegions';
import { createWidgetImplementationResource } from '@workbench/widgetImplementationResource';
import i18next from 'i18next';
import { CircleIcon } from 'lucide-react';
@@ -25,10 +26,10 @@ const workbenchMocks = vi.hoisted(() => ({
widgetGraphs: {},
widgetInstances: {},
widgetRegions: {
- bottom: { activeInstanceId: 'test-instance', instanceIds: ['test-instance'], isCollapsed: false },
- center: { activeInstanceId: 'test-instance', instanceIds: ['test-instance'], isCollapsed: false },
- left: { activeInstanceId: 'test-instance', instanceIds: ['test-instance'], isCollapsed: false },
- right: { activeInstanceId: 'test-instance', instanceIds: ['test-instance'], isCollapsed: false },
+ bottom: { activeInstanceId: 'test-instance', instanceIds: ['test-instance'], isCollapsed: false, sizePx: 240 },
+ center: { activeInstanceId: 'test-instance', instanceIds: ['test-instance'], isCollapsed: false, sizePx: 240 },
+ left: { activeInstanceId: 'test-instance', instanceIds: ['test-instance'], isCollapsed: false, sizePx: 240 },
+ right: { activeInstanceId: 'test-instance', instanceIds: ['test-instance'], isCollapsed: false, sizePx: 240 },
},
},
runtime: {},
@@ -38,7 +39,7 @@ vi.mock('@workbench/WorkbenchContext', () => ({
shallowEqual: Object.is,
useActiveProjectSelector: (selector: (project: typeof workbenchMocks.project) => unknown) =>
selector(workbenchMocks.project),
- useWorkbenchCommands: () => ({}),
+ useWorkbenchCommands: () => ({ layout: { setRegionSize: () => {} } }),
}));
vi.mock('@workbench/WorkbenchWidgetRegistryContext', () => ({
@@ -63,7 +64,14 @@ await i18n.use(initReactI18next).init({
translation: {
widgets: {
actionsLabel: '{{label}} actions',
+ failure: {
+ compactLabel: '{{label}} failed — select to retry',
+ copyError: 'Copy Error',
+ retry: 'Retry',
+ title: '{{label}} failed',
+ },
loadingLabel: 'Loading {{label}}',
+ panelLabel: '{{region}} widget panel',
},
},
},
@@ -93,6 +101,10 @@ const CustomHeaderLabel = () => (
</Text>
);
+const ThrowingView = () => {
+ throw new Error('widget exploded');
+};
+
const createDeferredWidget = () => {
let resolveLoad: ((implementation: WidgetImplementation) => void) | undefined;
const loader = vi.fn(
@@ -103,7 +115,7 @@ const createDeferredWidget = () => {
);
const manifest: NormalizedWidgetManifest = {
allowMultiple: false,
- allowedRegions: ['bottom', 'center'],
+ allowedRegions: ['bottom', 'center', 'right'],
apiVersion: 1,
failurePolicy: { isolateRenderFailure: true, onRegistrationFailure: 'disable' },
icon: TestIcon,
@@ -151,7 +163,9 @@ const render = async (children: ReactNode) => {
await act(async () => {
root?.render(
<I18nextProvider i18n={i18n}>
- <ChakraProvider value={system}>{children}</ChakraProvider>
+ <ChakraProvider value={system}>
+ <FocusRegionProvider>{children}</FocusRegionProvider>
+ </ChakraProvider>
</I18nextProvider>
);
await Promise.resolve();
@@ -243,3 +257,49 @@ describe('WidgetRenderer loading identity transitions', () => {
expect(host?.querySelector('.chakra-spinner')).toBeNull();
});
});
+
+describe('WidgetRenderer failure containment', () => {
+ it('keeps a crashed compact widget inside the status bar strip', async () => {
+ const { resolve, widget } = createDeferredWidget();
+ // The status bar is a 24px-tall strip; a crashed widget must not outgrow it.
+ host = document.createElement('div');
+ host.style.cssText = 'align-items:center;display:flex;height:24px;width:480px;';
+ document.body.append(host);
+ root = createRoot(host);
+
+ await act(async () => {
+ root?.render(
+ <I18nextProvider i18n={i18n}>
+ <ChakraProvider value={system}>
+ <WidgetRenderer instance={createInstance()} presentation="compact" region="bottom" widget={widget} />
+ </ChakraProvider>
+ </I18nextProvider>
+ );
+ await Promise.resolve();
+ });
+
+ await resolve({ view: ThrowingView });
+ await expect.poll(() => host?.querySelector('[data-testid="widget-failure"]')).not.toBeNull();
+
+ const failure = host?.querySelector<HTMLElement>('[role="status"]');
+ expect(failure).not.toBeNull();
+ expect(failure?.getBoundingClientRect().height).toBeLessThanOrEqual(24);
+ // The label still identifies which widget died.
+ expect(host?.textContent).toContain('Test widget');
+ });
+
+ it('keeps a crashed panel widget framed and resizable', async () => {
+ const { resolve, widget } = createDeferredWidget();
+ await render(<WidgetRenderer instance={createInstance()} region="right" widget={widget} />);
+
+ await resolve({ view: ThrowingView });
+ await expect.poll(() => host?.querySelector('[data-testid="widget-failure"]')).not.toBeNull();
+
+ const panel = host?.querySelector<HTMLElement>('aside');
+ expect(panel).not.toBeNull();
+ // Panel width survives the crash, so the region does not collapse or overflow.
+ expect(panel?.getBoundingClientRect().width).toBe(240);
+ // And the drag handle is still there to resize with.
+ expect(panel?.querySelector('[role="separator"]')).not.toBeNull();
+ });
+});
diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetRenderer.tsx b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetRenderer.tsx
index a883f8d07b..c67b3b2b14 100644
--- a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetRenderer.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetRenderer.tsx
@@ -57,7 +57,15 @@ export const WidgetRenderer = ({ instance, presentation, region, widget }: Widge
}
return (
- <WidgetFailureBoundary resetKey={instance.id} widgetId={widget.manifest.id} onRetry={widget.implementation.retry}>
+ <WidgetFailureBoundary
+ instance={instance}
+ presentation={presentation}
+ region={region}
+ resetKey={instance.id}
+ widget={widget}
+ widgetId={widget.manifest.id}
+ onRetry={widget.implementation.retry}
+ >
{content}
</WidgetFailureBoundary>
);
diff --git a/invokeai/frontend/webv2/src/workbench/widgetImplementationResource.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widgetImplementationResource.browser.test.tsx
index 7d0447b8ff..06c83e9ce5 100644
--- a/invokeai/frontend/webv2/src/workbench/widgetImplementationResource.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgetImplementationResource.browser.test.tsx
@@ -73,9 +73,14 @@ describe('widget implementation resource rendering', () => {
const resource = createWidgetImplementationResource('test', loader);
await renderResource(resource);
- await expect.poll(() => host?.textContent).toContain('Widget failed: test');
+ // i18n is not initialized under test, so `t()` returns raw keys — assert on
+ // the fallback's structure rather than its copy.
+ await expect.poll(() => host?.querySelector('[data-testid="widget-failure"]')).not.toBeNull();
+ expect(host?.textContent).toContain('test');
- const retry = [...(host?.querySelectorAll('button') ?? [])].find((button) => button.textContent === 'Retry');
+ const retry = [...(host?.querySelectorAll('button') ?? [])].find((button) =>
+ button.textContent?.includes('widgets.failure.retry')
+ );
expect(retry).toBeDefined();
await act(() => retry?.click());