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): close the gaps the second review found in the floating-window fixes

Lincoln Stein490fb9f50f67
diff --git a/invokeai/frontend/webv2/src/workbench/floatingWidgets.test.ts b/invokeai/frontend/webv2/src/workbench/floatingWidgets.test.ts
index 0379fc3693..5ba495a441 100644
--- a/invokeai/frontend/webv2/src/workbench/floatingWidgets.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/floatingWidgets.test.ts
@@ -11,7 +11,7 @@ import {
nextStackOrder,
} from './floatingWindows';
import { doesProjectMatchLayoutPreset, resolveSavedLayoutPreset } from './layoutPresetSnapshots';
-import { normalizeWorkbenchProject } from './workbenchState';
+import { normalizeWorkbenchAccount, normalizeWorkbenchProject } from './workbenchState';
import { createInitialWorkbenchState, workbenchReducer } from './workbenchState.testing';
const getActiveProject = (state: WorkbenchState): Project => {
@@ -339,6 +339,50 @@ describe('interaction with presets and undo', () => {
expect(getRegionsHolding(project, 'gallery')).toEqual([]);
});
+ it('carries a saved preset’s floating window through account rehydration', () => {
+ // Account presets are rebuilt by `cloneLayoutPresetSnapshot` on every load;
+ // a field it forgets is a field the preset loses on the next reload.
+ let state = workbenchReducer(createInitialWorkbenchState(), { instanceId: 'gallery', type: 'floatWidget' });
+ state = workbenchReducer(state, { presetId: 'compose', type: 'saveLayoutPreset' });
+
+ const rehydrated = normalizeWorkbenchAccount(state.account);
+
+ expect(rehydrated.layoutPresetOverrides?.compose?.floatingWidgets?.gallery).toMatchObject({
+ mode: 'windowed',
+ returnRegion: 'right',
+ });
+ });
+
+ it('validates a preset’s floating windows the way a persisted project’s are', () => {
+ // Preset bodies come from account storage, which never passes through
+ // `normalizeWorkbenchProject`.
+ let state = workbenchReducer(createInitialWorkbenchState(), { instanceId: 'gallery', type: 'floatWidget' });
+ state = workbenchReducer(state, { presetId: 'compose', type: 'saveLayoutPreset' });
+
+ const saved = state.account.layoutPresetOverrides!.compose!;
+ const account = normalizeWorkbenchAccount({
+ ...state.account,
+ layoutPresetOverrides: {
+ compose: {
+ ...saved,
+ floatingWidgets: {
+ // Would throw in `dockFloatingWidget` on widgetRegions[returnRegion].
+ gallery: { ...saved.floatingWidgets!.gallery, returnRegion: 'nowhere' },
+ // Docked by the same preset, so honouring this would double-render.
+ queue: { ...saved.floatingWidgets!.gallery },
+ },
+ },
+ },
+ } as unknown);
+ state = { ...state, account };
+ state = workbenchReducer(state, { presetId: 'compose', type: 'applyPreset' });
+ const project = getActiveProject(state);
+
+ expect(project.floatingWidgets?.gallery).toBeUndefined();
+ expect(getRegionsHolding(project, 'queue')).toEqual([]);
+ expect(project.floatingWidgets?.queue).toBeDefined();
+ });
+
it('reads a floated window as unsaved layout drift until it is saved', () => {
const floated = workbenchReducer(createInitialWorkbenchState(), { instanceId: 'gallery', type: 'floatWidget' });
diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/FloatingWidgetWindow.tsx b/invokeai/frontend/webv2/src/workbench/widget-frame/FloatingWidgetWindow.tsx
index 87b305f83a..2e24c67e0d 100644
--- a/invokeai/frontend/webv2/src/workbench/widget-frame/FloatingWidgetWindow.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/FloatingWidgetWindow.tsx
@@ -2,6 +2,7 @@ import type { FloatingWidgetState } from '@workbench/layoutContracts';
import type { WidgetInstanceId } from '@workbench/widgetContracts';
import { Box, Flex, HStack, Icon, Text } from '@chakra-ui/react';
+import { flushWorkbenchDrafts } from '@platform/react/draftRegistry';
import { IconButton, Tooltip } from '@platform/ui';
import {
clampWindowToViewport,
@@ -13,7 +14,14 @@ import { WidgetIcon } from '@workbench/iconResolver';
import { resolveWidgetInstanceLabel } from '@workbench/widgetLabels';
import { useActiveProjectSelector, useWorkbenchCommands } from '@workbench/WorkbenchContext';
import { useWorkbenchWidgetRegistry } from '@workbench/WorkbenchWidgetRegistryContext';
-import { ChevronsDownUpIcon, ChevronsUpDownIcon, Maximize2Icon, Minimize2Icon, PanelRightIcon } from 'lucide-react';
+import {
+ ChevronsDownUpIcon,
+ ChevronsUpDownIcon,
+ Maximize2Icon,
+ Minimize2Icon,
+ PanelRightIcon,
+ TriangleAlertIcon,
+} from 'lucide-react';
import {
useCallback,
useState,
@@ -122,7 +130,13 @@ export const FloatingWidgetWindow = ({
);
const handleFocus = useCallback(() => widgets.focusFloating(instanceId), [instanceId, widgets]);
- const handleDock = useCallback(() => widgets.dockFloating(instanceId), [instanceId, widgets]);
+ // Docking remounts the widget in its rail. The draft registry's cleanup only
+ // deregisters the flusher, so an uncommitted edit needs committing first —
+ // the same reason `closeWidgetPlacement` flushes before it unmounts.
+ const handleDock = useCallback(() => {
+ flushWorkbenchDrafts();
+ widgets.dockFloating(instanceId);
+ }, [instanceId, widgets]);
const handleToggleShade = useCallback(
() => widgets.setFloatingMode(instanceId, state.mode === 'shaded' ? 'windowed' : 'shaded'),
[instanceId, state.mode, widgets]
@@ -142,10 +156,15 @@ export const FloatingWidgetWindow = ({
[handleToggleShade, state.mode]
);
- if (!instance || !widget || widget.status !== 'enabled') {
+ if (!instance || !widget) {
return null;
}
+ // A widget that fails registration while floated keeps its chrome. Rendering
+ // nothing would strand the instance: it is in no region, so the dock control
+ // in this title bar is the only way back to the rail — and to the docked
+ // failure card, which owns the retry.
+ const isEnabled = widget.status === 'enabled';
const label = resolveWidgetInstanceLabel(instance, widget.manifest, t);
const geometry = dragGeometry ?? state;
const isMaximized = state.mode === 'maximized';
@@ -185,6 +204,9 @@ export const FloatingWidgetWindow = ({
justify="space-between"
pe="2"
ps="3"
+ // `preventDefault` on pointerdown does not stop touch panning: without
+ // this the browser claims the gesture and cancels the drag.
+ touchAction="none"
userSelect="none"
onDoubleClick={handleTitleDoubleClick}
onPointerDown={handleTitlePointerDown}
@@ -233,7 +255,14 @@ export const FloatingWidgetWindow = ({
</HStack>
{isShaded ? null : (
<Flex direction="column" flex="1" minH="0" overflow="hidden">
- <WidgetRendererById instanceId={instance.id} region="floating" widget={widget} />
+ {isEnabled ? (
+ <WidgetRendererById instanceId={instance.id} region="floating" widget={widget} />
+ ) : (
+ <HStack color="fg.error" gap="1.5" p="3">
+ <Icon as={TriangleAlertIcon} boxSize="3.5" />
+ <Text fontSize="xs">{t('widgets.failure.title', { label })}</Text>
+ </HStack>
+ )}
</Flex>
)}
{isShaded || isMaximized ? null : (
@@ -244,6 +273,7 @@ export const FloatingWidgetWindow = ({
h="4"
position="absolute"
right="0"
+ touchAction="none"
w="4"
onPointerDown={handleResizePointerDown}
/>
diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetActionsMenu.tsx b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetActionsMenu.tsx
index 9b082d1b7b..1a1bad1c4f 100644
--- a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetActionsMenu.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetActionsMenu.tsx
@@ -14,7 +14,10 @@ import { flushWorkbenchDrafts } from '@platform/react/draftRegistry';
import { IconButton } from '@platform/ui';
import { createGraphBearingSurface } from '@workbench/graphSurfaces';
import { resolveWidgetLabel } from '@workbench/widgetLabels';
+import { getEnabledCenterViewCount } from '@workbench/widgetPlacementCommands';
+import { areWidgetPlacementProjectsEqual, getWidgetPlacementProject } from '@workbench/widgetPlacementMeta';
import { shallowEqual, useActiveProjectSelector, useWorkbenchCommands } from '@workbench/WorkbenchContext';
+import { useWorkbenchWidgetRegistry } from '@workbench/WorkbenchWidgetRegistryContext';
import { GitBranchIcon, MoreHorizontalIcon, PictureInPicture2Icon, TargetIcon } from 'lucide-react';
import { lazy, Suspense, useCallback, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
@@ -118,7 +121,8 @@ export const WidgetActionsMenu = ({
(project) => ({ projectGraph: project.projectGraph, widgetGraphs: project.widgetGraphs }),
shallowEqual
) as Project;
- const centerInstanceCount = useActiveProjectSelector((project) => project.widgetRegions.center.instanceIds.length);
+ const placementProject = useActiveProjectSelector(getWidgetPlacementProject, areWidgetPlacementProjectsEqual);
+ const { getWidgetById } = useWorkbenchWidgetRegistry();
const { widgets } = useWorkbenchCommands();
const [isPreviewOpen, setIsPreviewOpen] = useState(false);
const [previewGraph, setPreviewGraph] = useState<GraphContract | null>(null);
@@ -129,12 +133,19 @@ export const WidgetActionsMenu = ({
[label, manifest, region]
);
// Floating is offered only from dockable regions; the floating window's own
- // chrome carries the dock control. The last center view is not offered it
- // either — the reducer refuses to empty the work surface, so the item would
- // do nothing.
+ // chrome carries the dock control. The last center *view* is not offered it
+ // either — floating it out would leave the work surface with nothing to
+ // show, which is why `closeWidgetPlacement` refuses the same removal.
const canFloat =
- Boolean(manifest.allowFloating) && region !== 'floating' && !(region === 'center' && centerInstanceCount === 1);
- const handleFloat = useCallback(() => widgets.float(instance.id), [instance.id, widgets]);
+ Boolean(manifest.allowFloating) &&
+ region !== 'floating' &&
+ !(region === 'center' && getEnabledCenterViewCount(placementProject, getWidgetById) === 1);
+ // Floating unmounts the docked subtree; the draft registry's cleanup only
+ // deregisters the flusher, so an uncommitted edit is lost without this.
+ const handleFloat = useCallback(() => {
+ flushWorkbenchDrafts();
+ widgets.float(instance.id);
+ }, [instance.id, widgets]);
const surfaceSourceId = surface?.sourceId;
const handlePreview = useCallback(async () => {
flushWorkbenchDrafts();
diff --git a/invokeai/frontend/webv2/src/workbench/widgetPlacementCommands.ts b/invokeai/frontend/webv2/src/workbench/widgetPlacementCommands.ts
index 3efae431c6..279ffdbec3 100644
--- a/invokeai/frontend/webv2/src/workbench/widgetPlacementCommands.ts
+++ b/invokeai/frontend/webv2/src/workbench/widgetPlacementCommands.ts
@@ -99,7 +99,7 @@ export const openWidgetPlacement = ({
return { ok: true, region: target.region };
};
-const getEnabledCenterViewCount = (
+export const getEnabledCenterViewCount = (
project: WidgetPlacementProject,
getWidgetById: (typeId: WidgetTypeId) => RegisteredWidget | undefined
): number =>
diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.ts
index 1eb1a3cadb..57e1bb0a34 100644
--- a/invokeai/frontend/webv2/src/workbench/workbenchState.ts
+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.ts
@@ -1711,6 +1711,9 @@ const openPanelForRegion = (layout: ProjectLayoutState, region: WidgetRegion): P
});
const cloneLayoutPresetSnapshot = (snapshot: LayoutPresetSnapshot): LayoutPresetSnapshot => ({
+ // Every account preset is rebuilt through here on load, so a field missing
+ // from this clone is a field the preset silently loses on the next reload.
+ ...(snapshot.floatingWidgets ? { floatingWidgets: cloneFloatingWidgets(snapshot.floatingWidgets) } : {}),
layout: { ...snapshot.layout, panels: { ...snapshot.layout.panels } },
widgetInstances: Object.fromEntries(
Object.entries(snapshot.widgetInstances).map(([instanceId, instance]) => [instanceId, { ...instance }])
@@ -2003,21 +2006,28 @@ const applyLayoutPresetToProject = (project: Project, preset: LayoutPreset): Pro
: createWidgetInstance(instance.typeId, instance.id);
}
+ // A preset is a full placement reset, so the project's own floating windows
+ // go: keeping one would double-render whatever the preset docks. The
+ // preset's are restored in their place — a preset saved while a widget
+ // floated has it in no region, and dropping them both would leave the
+ // instance nowhere at all. Preset bodies reach us from account storage
+ // without passing through `normalizeWorkbenchProject`, so they are validated
+ // and reconciled here on the same terms as a persisted project.
+ const placement = reconcileFloatingWidgets(
+ cloneLayoutPresetWidgetRegions(snapshot.widgetRegions),
+ normalizeFloatingWidgets(snapshot.floatingWidgets, widgetInstances)
+ );
+
return {
...project,
- // A preset is a full placement reset, so the project's own floating
- // windows go: keeping one would double-render whatever the preset docks.
- // The preset's are restored in their place — a preset saved while a widget
- // floated has it in no region, and dropping them both would leave the
- // instance nowhere at all.
- floatingWidgets: snapshot.floatingWidgets ? cloneFloatingWidgets(snapshot.floatingWidgets) : undefined,
+ floatingWidgets: placement.floatingWidgets,
layout: {
...snapshot.layout,
panels: { ...snapshot.layout.panels },
presetId: preset.id,
},
widgetInstances,
- widgetRegions: cloneLayoutPresetWidgetRegions(snapshot.widgetRegions),
+ widgetRegions: placement.widgetRegions,
};
};