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.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
fix(workbench): honour an emptied center across reloads, presets, and re-selects
Lincoln Steincf75825612de
diff --git a/invokeai/frontend/webv2/src/workbench/floatingWidgets.test.ts b/invokeai/frontend/webv2/src/workbench/floatingWidgets.test.tsindex 24e93e72ac..3921580050 100644--- a/invokeai/frontend/webv2/src/workbench/floatingWidgets.test.ts+++ b/invokeai/frontend/webv2/src/workbench/floatingWidgets.test.ts@@ -284,6 +284,19 @@ describe('interaction with region placement', () => {expect(project.floatingWidgets?.gallery).toBeUndefined();expect(project.widgetRegions.right.instanceIds).toContain('gallery');});++ it('selectRegionWidget docks a floating instance instead of double-rendering it', () => {+ // The preview is still a member of the right rail while it floats in a+ // window docked back to the center; selecting its rail slot would+ // otherwise make the rail show it alongside the window.+ let state = workbenchReducer(createInitialWorkbenchState(), { presetId: 'edit', type: 'applyPreset' });+ state = workbenchReducer(state, { instanceId: 'preview', region: 'center', type: 'floatWidget' });+ state = workbenchReducer(state, { region: 'right', type: 'selectRegionWidget', widgetId: 'preview' });+ const project = getActiveProject(state);++ expect(project.floatingWidgets?.preview).toBeUndefined();+ expect(project.widgetRegions.right.activeInstanceId).toBe('preview');+ });});describe('pure helpers', () => {@@ -384,32 +397,30 @@ describe('normalization of persisted floating windows', () => {it('lets a sole center view keep floating across a reload', () => {// Floating the last center view empties the work surface into its fallback- // view, and the window's dock control is one click from restoring it — so- // normalization honours the float instead of re-docking it, exactly as it- // does for a floated rail widget.- const project = getActiveProject(createInitialWorkbenchState());- const [onlyCenterInstanceId] = project.widgetRegions.center.instanceIds;- const normalized = normalizeWorkbenchProject({- ...project,- floatingWidgets: {- [onlyCenterInstanceId]: {- heightPx: 300,- mode: 'windowed',- returnRegion: 'center',- stackOrder: 1,- widthPx: 400,- x: 10,- y: 10,- },- },- widgetRegions: {- ...project.widgetRegions,- center: { ...project.widgetRegions.center, instanceIds: [onlyCenterInstanceId] },- },- });+ // view, and the window's dock control is one click from restoring it. The+ // persisted shape is an EMPTY center whose active pointer names the floated+ // instance — normalization must honour it, not read it as missing center+ // data and refill the default arrangement (which would inject views the+ // project never placed).+ let state = workbenchReducer(createInitialWorkbenchState(), { presetId: 'video', type: 'applyPreset' });+ state = workbenchReducer(state, { instanceId: 'preview', region: 'center', type: 'floatWidget' });+ const project = getActiveProject(state);+ expect(project.widgetRegions.center.instanceIds).toEqual([]);++ // The reducer output is exactly what autosave persists.+ const normalized = normalizeWorkbenchProject(JSON.parse(JSON.stringify(project)));- expect(normalized.floatingWidgets?.[onlyCenterInstanceId]).toMatchObject({ returnRegion: 'center' });+ expect(normalized.floatingWidgets?.preview).toMatchObject({ returnRegion: 'center' });expect(normalized.widgetRegions.center.instanceIds).toEqual([]);+ expect(normalized.widgetRegions.center.activeInstanceId).toBe('preview');++ // Docking after the reload restores the view.+ const docked = workbenchReducer(+ { ...state, projects: state.projects.map((p) => (p.id === normalized.id ? normalized : p)) },+ { instanceId: 'preview', type: 'dockFloatingWidget' }+ );++ expect(getActiveProject(docked).widgetRegions.center.instanceIds).toEqual(['preview']);});});@@ -442,6 +453,22 @@ describe('interaction with presets and undo', () => {expect(getRegionsHolding(project, 'gallery')).toEqual([]);});+ it('a preset saved with the sole center view floating restores the emptied surface, not a phantom view', () => {+ // Normalizing before the snapshot must not refill the emptied center with+ // the default arrangement — the saved preset would otherwise carry center+ // views the project never placed.+ let state = workbenchReducer(createInitialWorkbenchState(), { presetId: 'video', type: 'applyPreset' });+ state = workbenchReducer(state, { instanceId: 'preview', region: 'center', type: 'floatWidget' });+ state = workbenchReducer(state, { presetId: 'video', type: 'saveLayoutPreset' });+ // Dock it, then revert to the preset that was saved with it floating.+ state = workbenchReducer(state, { instanceId: 'preview', type: 'dockFloatingWidget' });+ state = workbenchReducer(state, { presetId: 'video', type: 'applyPreset' });+ const project = getActiveProject(state);++ expect(project.floatingWidgets?.preview).toBeDefined();+ expect(project.widgetRegions.center.instanceIds).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.diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.tsindex 7fb1f47bae..54682e6107 100644--- a/invokeai/frontend/webv2/src/workbench/workbenchState.ts+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.ts@@ -1562,9 +1562,18 @@ const ensureCenterRegion = (fallbackCenterViewId: CenterViewId): WidgetRegionState => {const defaultCenterRegion = createWidgetRegions().center;+ // A center with no region data at all adopts the default arrangement, but an+ // explicitly emptied one is authoritative: the last view may be floating in a+ // window (the surface falls back until its dock control returns it), and+ // refilling it would inject views the project never placed.+ const instanceIds = centerRegion ? centerRegion.instanceIds : defaultCenterRegion.instanceIds;const activeInstanceId = centerRegion?.activeInstanceId ?? getCenterWidgetIdFromViewId(fallbackCenterViewId);- const instanceIds = centerRegion?.instanceIds.length ? centerRegion.instanceIds : defaultCenterRegion.instanceIds;- const normalizedActiveInstanceId = instanceIds.includes(activeInstanceId) ? activeInstanceId : instanceIds[0];+ // A pointer that names none of the members is clamped — but an emptied+ // center keeps its pointer, which names the instance now floating in a+ // window; the boot preload reads it to have that window's chunk ready.+ const normalizedActiveInstanceId = instanceIds.includes(activeInstanceId)+ ? activeInstanceId+ : (instanceIds[0] ?? activeInstanceId);return {...defaultCenterRegion,@@ -3801,10 +3810,16 @@ export const __workbenchReducerInternal = (return updateProjectById(state, action.projectId ?? state.activeProjectId, (project) => {const region = project.widgetRegions[action.region];+ // Selecting a slot names the instance as the region's shown surface, so+ // it docks: an instance must never render in a panel and a floating+ // window at once — the same rule `openRegionWidget` enforces.+ const { [action.widgetId]: _floated, ...floatingWidgets } = project.floatingWidgets ?? {};+if (action.region === 'center') {return applyAutoRouteForRevealedInstance({...project,+ floatingWidgets,widgetRegions: {...project.widgetRegions,center: { ...region, activeInstanceId: action.widgetId, isCollapsed: false },@@ -3822,6 +3837,7 @@ export const __workbenchReducerInternal = (if (region.activeInstanceId === action.widgetId) {const disclosed = {...project,+ floatingWidgets,layout: openPanelForRegion(project.layout, action.region),widgetRegions: {...project.widgetRegions,@@ -3837,6 +3853,7 @@ export const __workbenchReducerInternal = (return applyAutoRouteForRevealedInstance({...project,+ floatingWidgets,layout: openPanelForRegion(project.layout, action.region),widgetRegions: {...project.widgetRegions,