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(webv2): save a floated window in the order a reload reads it
Josh Corbettc01f9b0f222f
diff --git a/invokeai/frontend/webv2/src/workbench/floatingWidgets.test.ts b/invokeai/frontend/webv2/src/workbench/floatingWidgets.test.tsindex 03f14bc530..4dc33e9641 100644--- a/invokeai/frontend/webv2/src/workbench/floatingWidgets.test.ts+++ b/invokeai/frontend/webv2/src/workbench/floatingWidgets.test.ts@@ -818,7 +818,7 @@ describe('remembered window geometry', () => {expect(getActiveProject(state).lastFloatingGeometry).toEqual({ gallery: PLACED });});- it('always saves memory the way a reload would read it back', () => {+ it('always saves windows and their memory the way a reload would read them back', () => {// Persistence compares what it sent with the document as a reload reads it, as JSON. Anything a reload would// drop or reorder in these fields turns a lost response into a conflict.const placement = (project: Project): string => {@@ -847,6 +847,19 @@ describe('remembered window geometry', () => {savesCanonically(state);state = workbenchReducer(state, { type: 'redoProjectChange' });savesCanonically(state);++ // An open window, from the moment it floats and through everything that rewrites its state.+ state = workbenchReducer(createInitialWorkbenchState(), { instanceId: 'image-map', type: 'floatWidget' });+ savesCanonically(state);+ // Removing a member ahead of the marker re-indexes it; a second float re-indexes around both.+ state = workbenchReducer(state, { region: 'right', type: 'toggleRegionWidget', widgetId: 'gallery' });+ savesCanonically(state);+ state = workbenchReducer(state, { instanceId: 'queue', type: 'floatWidget' });+ savesCanonically(state);+ state = workbenchReducer(state, { instanceId: 'image-map', type: 'setFloatingWidgetGeometry', ...PLACED });+ state = workbenchReducer(state, { instanceId: 'image-map', mode: 'shaded', type: 'setFloatingWidgetMode' });+ state = workbenchReducer(state, { instanceId: 'image-map', type: 'raiseFloatingWidget' });+ savesCanonically(state);});it('is not layout: floating, moving, and docking back leaves the saved preset matching', () => {diff --git a/invokeai/frontend/webv2/src/workbench/floatingWindows.ts b/invokeai/frontend/webv2/src/workbench/floatingWindows.tsindex d3c0e28d71..a42bfe8c65 100644--- a/invokeai/frontend/webv2/src/workbench/floatingWindows.ts+++ b/invokeai/frontend/webv2/src/workbench/floatingWindows.ts@@ -187,6 +187,30 @@ export const getRegionOrder = (return slots;};+/**+ * The one shape a window's state is written in. Persistence compares documents as JSON, key order included, so a+ * window built by a reducer has to serialize exactly as the same window read back by a reload.+ */+export const toFloatingWidgetState = ({+ heightPx,+ mode,+ returnIndex,+ returnRegion,+ stackOrder,+ widthPx,+ x,+ y,+}: FloatingWidgetState): FloatingWidgetState => ({+ heightPx,+ widthPx,+ x,+ y,+ mode,+ returnIndex,+ returnRegion,+ stackOrder,+});+/** Write a complete order back as the region's docked members and its markers' return indices. */export const writeRegionOrder = (slots: readonly RegionOrderSlot[],@@ -198,7 +222,10 @@ export const writeRegionOrder = (const floating = nextFloatingWidgets?.[instanceId];if (isFloating && floating && floating.returnIndex !== index) {- nextFloatingWidgets = { ...nextFloatingWidgets, [instanceId]: { ...floating, returnIndex: index } };+ nextFloatingWidgets = {+ ...nextFloatingWidgets,+ [instanceId]: toFloatingWidgetState({ ...floating, returnIndex: index }),+ };}});@@ -254,13 +281,13 @@ const validateFloatingWidgets = (continue;}- floatingWidgets[instanceId] = {+ floatingWidgets[instanceId] = toFloatingWidgetState({...clampSizeToMinimum({ heightPx: state.heightPx, widthPx: state.widthPx, x: state.x, y: state.y }),mode: state.mode as FloatingWidgetMode,returnIndex: state.returnIndex,returnRegion,stackOrder: state.stackOrder,- };+ });}return floatingWidgets;diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.tsindex a166f4f6a1..7cebedb1eb 100644--- a/invokeai/frontend/webv2/src/workbench/workbenchState.ts+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.ts@@ -191,6 +191,7 @@ import {normalizeFloatingPlacement,normalizeLastFloatingGeometry,rememberClosedWindows,+ toFloatingWidgetState,withoutFloatedInstances,writeRegionOrder,type RegionOrderSlot,@@ -3948,7 +3949,7 @@ export const __workbenchReducerInternal = (const remembered = project.lastFloatingGeometry?.[action.instanceId];let floatingWidgets: Record<WidgetInstanceId, FloatingWidgetState> | undefined = {...project.floatingWidgets,- [action.instanceId]: {+ [action.instanceId]: toFloatingWidgetState({...(remembered? action.viewport? fitWindowIntoViewport(remembered, action.viewport)@@ -3957,7 +3958,7 @@ export const __workbenchReducerInternal = (mode: 'windowed',returnRegion,stackOrder: nextStackOrder(project.floatingWidgets),- },+ }),};const widgetRegions = { ...project.widgetRegions };