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): announce a floating window's displayed size on its resize control

Josh Corbett3f738360502b
diff --git a/invokeai/frontend/webv2/ARCHITECTURE.md b/invokeai/frontend/webv2/ARCHITECTURE.md
index ef73b7dc77..51a5e35b85 100644
--- a/invokeai/frontend/webv2/ARCHITECTURE.md
+++ b/invokeai/frontend/webv2/ARCHITECTURE.md
@@ -134,7 +134,7 @@ Workbench focus is transient and never persisted. `WorkbenchFocusProvider` (`wor
- **Geometry is stored once and adapted in CSS.** Every window shares one static rule set; the stored geometry and stacking rank arrive as inline custom properties (registered as non-inheriting, so a drag restyles the window and not the widget inside it), so a commit changes values rather than minting a class. The position keeps a 48px sliver reachable (`FLOATING_VIEWPORT_MARGIN_PX`, the same margin `clampWindowToViewport` applies to commits) and the displayed size is capped to the viewport. A viewport that shrinks therefore persists nothing; the stored geometry applies again when there is room.
- **Gestures start from the rendered rectangle**, not the stored geometry, so a window CSS is clamping or capping does not jump. A gesture commits only what it changed: a move keeps the stored size, and a resize keeps the stored values of any axis it did not change (`commitResizedAxes`), because what is on screen there may only be the viewport's clamp or cap. A press that never moves, or a drag against the minimum or the cap, commits nothing. Keyboard steps follow the same rules.
- **One commit per gesture.** Pointer moves are coalesced to animation frames and previewed as inline custom properties on the window element; the store is written once, when the gesture ends — on release, or when the pointer is taken away (`pointercancel`, a release the page never saw), which keeps what was dragged so far. Escape discards the preview. Each keyboard step is its own commit.
-- **Resize handles.** Eight pointer-only handles (four edges, four corners) straddle the border with matching cursors and non-overlapping hit areas, above an isolated content frame so widget stacking cannot cover them. Inside the bottom-right corner sits the `ResizeCorner`, the single labelled, keyboard-operable resize control; the pointer-only handle there is clipped to the band outside the border. `resizeFloatingGeometry` anchors the opposite side, holds the size between the minimum and the viewport, and stops the top edge at the viewport's top.
+- **Resize handles.** Eight pointer-only handles (four edges, four corners) straddle the border with matching cursors and non-overlapping hit areas, above an isolated content frame so widget stacking cannot cover them. Inside the bottom-right corner sits the `ResizeCorner`, the single labelled, keyboard-operable resize control; the pointer-only handle there is clipped to the band outside the border. That control announces the size on screen — the stored size as the viewport caps it — and follows the viewport, so its value and its keyboard steps agree. `resizeFloatingGeometry` anchors the opposite side, holds the size between the minimum and the viewport, and stops the top edge at the viewport's top.
- **One gesture path.** The title bar, the grip, and every handle start through the window's single pointer session, so a new gesture replaces the one before it and resize gestures all raise the platform's resize-drag signal. The preview names the mode the gesture began in and applies only while the window is still in that mode: a window that maximizes or collapses under a gesture shows its new frame at once, and the gesture ends itself — releasing the drag cursor and committing nothing — the next time it hears from the pointer. Docking, removing, or switching project unmounts the host (hosts are keyed by project and instance), which aborts the session.
- **Title bar.** Double-click maximizes or restores, and expands a collapsed window; Restore returns to the windowed geometry, which maximizing never touches. Collapse and Expand are explicit buttons. The label truncates first, down to its icon; contributed widget actions then give way in a strip that scrolls, without a scrollbar, by focus, wheel, or touch, so a focused action is always in view with its ring; the window's own controls never shrink.
- **Shaded bodies stay mounted.** A shaded body is hidden with React `Activity`, so its local state survives and no second copy mounts. Drafts are flushed before shading, docking, and removing, because hiding or unmounting an editor stops its flusher.
diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/FloatingWidgetWindow.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widget-frame/FloatingWidgetWindow.browser.test.tsx
index ec7cb56e97..c95511f468 100644
--- a/invokeai/frontend/webv2/src/workbench/widget-frame/FloatingWidgetWindow.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/FloatingWidgetWindow.browser.test.tsx
@@ -822,6 +822,31 @@ describe('FloatingWidgetWindow gestures', () => {
expect(Number(corner().getAttribute('aria-valuemax'))).toBeGreaterThanOrEqual(500);
});
+ it('announces the size on screen through the resize control, following the viewport that caps it', async () => {
+ await renderWindow({ ...state, heightPx: 700, widthPx: 900, x: 0, y: 0 });
+
+ expect(corner().getAttribute('aria-valuenow')).toBe('900');
+ expect(corner().getAttribute('aria-valuetext')).toBe('900 by 700 pixels');
+
+ // The browser window shrinks under a window that nothing else re-renders.
+ await act(() => page.viewport(600, 500));
+ await nextFrame();
+
+ expect(rect()).toMatchObject({ height: 500, width: 600 });
+ expect(corner().getAttribute('aria-valuenow')).toBe('600');
+ expect(corner().getAttribute('aria-valuemax')).toBe('600');
+ expect(corner().getAttribute('aria-valuetext')).toBe('600 by 500 pixels');
+ expect(windowMocks.setFloatingGeometry).not.toHaveBeenCalled();
+ });
+
+ it('never announces a minimum above the size a viewport narrower than it shows', async () => {
+ await page.viewport(240, 500);
+ await renderWindow({ ...state, x: 0, y: 0 });
+
+ expect(corner().getAttribute('aria-valuenow')).toBe('240');
+ expect(corner().getAttribute('aria-valuemin')).toBe('240');
+ });
+
it('has no resize handles while maximized or collapsed', async () => {
for (const mode of ['maximized', 'shaded'] as const) {
await renderWindow({ ...state, mode });
diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/FloatingWidgetWindow.tsx b/invokeai/frontend/webv2/src/workbench/widget-frame/FloatingWidgetWindow.tsx
index a2351dee46..ed92f69471 100644
--- a/invokeai/frontend/webv2/src/workbench/widget-frame/FloatingWidgetWindow.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/FloatingWidgetWindow.tsx
@@ -30,6 +30,7 @@ import {
useCallback,
useMemo,
useRef,
+ useSyncExternalStore,
type CSSProperties,
type KeyboardEvent as ReactKeyboardEvent,
type MouseEvent as ReactMouseEvent,
@@ -242,6 +243,50 @@ interface WindowGesture {
stored: FloatingGeometry;
}
+const subscribeToViewportSize = (onChange: () => void): (() => void) => {
+ window.addEventListener('resize', onChange);
+ return () => window.removeEventListener('resize', onChange);
+};
+const getViewportWidthPx = (): number => window.innerWidth;
+const getViewportHeightPx = (): number => window.innerHeight;
+
+/**
+ * The window's one labelled resize control. It announces the size on screen, which the viewport may cap below the
+ * stored one, and follows the viewport: a browser window that shrinks re-renders this grip and nothing else, so
+ * it never announces a size nobody sees.
+ */
+const FloatingResizeCorner = ({
+ heightPx,
+ onKeyDown,
+ onPointerDown,
+ widthPx,
+}: {
+ /** The stored size. */
+ heightPx: number;
+ widthPx: number;
+ onKeyDown: (event: ReactKeyboardEvent<HTMLDivElement>) => void;
+ onPointerDown: (event: ReactPointerEvent<HTMLDivElement>) => void;
+}) => {
+ const { t } = useTranslation();
+ const viewportWidthPx = useSyncExternalStore(subscribeToViewportSize, getViewportWidthPx);
+ const viewportHeightPx = useSyncExternalStore(subscribeToViewportSize, getViewportHeightPx);
+ const shownWidthPx = Math.min(widthPx, viewportWidthPx);
+ const shownHeightPx = Math.min(heightPx, viewportHeightPx);
+
+ return (
+ <ResizeCorner
+ label={t('widgets.floating.resize')}
+ valueMax={viewportWidthPx}
+ // A viewport narrower than the minimum shows the window narrower still.
+ valueMin={Math.min(FLOATING_MIN_WIDTH_PX, shownWidthPx)}
+ valueNow={shownWidthPx}
+ valueText={t('widgets.floating.resizeValue', { height: shownHeightPx, width: shownWidthPx })}
+ onKeyDown={onKeyDown}
+ onPointerDown={onPointerDown}
+ />
+ );
+};
+
/**
* Isolate arbitrary widget controls from title-bar drag and double-click maximize gestures; not every control is a
* button.
@@ -753,12 +798,9 @@ export const FloatingWidgetWindow = ({
{isShaded || isMaximized ? null : (
<>
<FloatingResizeHandles onResizeStart={startWindowDrag} />
- <ResizeCorner
- label={t('widgets.floating.resize')}
- valueMax={Math.max(widthPx, window.innerWidth)}
- valueMin={FLOATING_MIN_WIDTH_PX}
- valueNow={widthPx}
- valueText={t('widgets.floating.resizeValue', { height: heightPx, width: widthPx })}
+ <FloatingResizeCorner
+ heightPx={heightPx}
+ widthPx={widthPx}
onKeyDown={handleResizeKeyDown}
onPointerDown={handleCornerPointerDown}
/>