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(gallery): keep the window anchor through a conflict fork

Lincoln Steineac536356d54
diff --git a/invokeai/frontend/webv2/src/workbench/persistence.test.ts b/invokeai/frontend/webv2/src/workbench/persistence.test.ts
index c9e2bf3e9d..36eab829cd 100644
--- a/invokeai/frontend/webv2/src/workbench/persistence.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/persistence.test.ts
@@ -205,6 +205,36 @@ describe('workbench persistence migration', () => {
expect(persistedValues?.galleryPage).toBe(0);
});
+ it('drops an infinite window anchor from the local cache on its own', async () => {
+ // The cache is what an offline boot restores from. It has not been
+ // through adoption, so the strip here is the only thing between a
+ // persisted anchor and a gallery reopened stranded mid-board.
+ const state = createInitialWorkbenchState();
+ const project = state.projects[0];
+ const galleryEntry = Object.entries(project?.widgetInstances ?? {}).find(
+ ([, instance]) => instance.typeId === 'gallery'
+ );
+ const [galleryInstanceId, galleryInstance] = galleryEntry!;
+ const snapshot = await localStorageWorkbenchPersistence.saveWorkbench({
+ ...state,
+ projects: [
+ {
+ ...project!,
+ widgetInstances: {
+ ...project!.widgetInstances,
+ [galleryInstanceId]: {
+ ...galleryInstance,
+ state: { ...galleryInstance.state, values: { ...galleryInstance.state.values, galleryPage: 5 } },
+ },
+ },
+ },
+ ],
+ });
+ const persistedValues = snapshot.state.projects[0]?.widgetInstances[galleryInstanceId]?.state.values;
+
+ expect(persistedValues?.galleryPage).toBe(0);
+ });
+
it('keeps a paginated page whose search survives the reload', async () => {
// A text search is rebuilt from the persisted value, so the page the user
// was reading is still a page of the same list.
diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
index 8aae558fcf..50b173c149 100644
--- a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
@@ -870,11 +870,67 @@ describe('adopting a project from another realm', () => {
it('drops an infinite window anchor on adoption, and keeps a paginated page', () => {
// A reveal anchors the infinite window mid-board for the session that
// made it; adopted anywhere else it strands the gallery there. A
- // paginated page is the page the user was reading and survives.
+ // paginated page is the page the user was reading and survives. A
+ // gallery that never touched the setting has no paginationMode at all,
+ // and the default is infinite — that is the common shape.
expect(galleryValuesOf(galleryProject({ galleryPage: 5, paginationMode: 'infinite' })).galleryPage).toBe(0);
+ expect(galleryValuesOf(galleryProject({ galleryPage: 5 })).galleryPage).toBe(0);
expect(galleryValuesOf(galleryProject({ galleryPage: 5, paginationMode: 'paginated' })).galleryPage).toBe(5);
});
+ it('drops the anchor and an unresolvable search together on adoption', () => {
+ const values = galleryValuesOf(
+ galleryProject({
+ galleryPage: 5,
+ paginationMode: 'infinite',
+ semanticImageQuery: { clusterId: 'evicted', kind: 'cluster', label: 'beaches' },
+ })
+ );
+
+ expect(values.semanticImageQuery).toBeNull();
+ expect(values.galleryPage).toBe(0);
+ });
+
+ it('keeps the window anchor when a conflict fork rescues the live copy', () => {
+ // The fork keeps the user's edits AND their position: they were deep in
+ // a board when the conflict hit, and the recovered project is the one
+ // they keep working in.
+ const clusterId = registerImageCluster(['a.png', 'b.png'], 'beaches');
+ let state = createInitialWorkbenchState();
+ const project = getActiveProject(state);
+ const serverCopy = { ...project, name: 'Renamed elsewhere' };
+
+ state = workbenchReducer(state, {
+ projectId: project.id,
+ type: 'patchWidgetValues',
+ values: {
+ galleryPage: 7,
+ paginationMode: 'infinite',
+ semanticImageQuery: { clusterId, kind: 'cluster', label: 'beaches' },
+ },
+ widgetId: 'gallery',
+ });
+ state = workbenchReducer(state, {
+ projectId: project.id,
+ recoveredIdentity: {
+ id: `${project.id}-recovered-1`,
+ name: `${project.name} (recovered)`,
+ recoveredAt: '2026-08-29T00:00:00.000Z',
+ recoveryOf: project.id,
+ },
+ recoveredProject: serverCopy,
+ serverProject: serverCopy,
+ type: 'reconcileProjectConflict',
+ });
+
+ const fork = getActiveProject(state);
+ const values = getProjectWidgetValues(fork, 'gallery');
+
+ expect(fork.id).toBe(`${project.id}-recovered-1`);
+ expect(values.galleryPage).toBe(7);
+ expect(values.semanticImageQuery).toEqual({ clusterId, kind: 'cluster', label: 'beaches' });
+ });
+
it('keeps a search the new realm can rebuild, and the page it was read on', () => {
const values = galleryValuesOf(
galleryProject({
diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.ts
index 8673408524..e8b1bfd0ee 100644
--- a/invokeai/frontend/webv2/src/workbench/workbenchState.ts
+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.ts
@@ -1690,7 +1690,20 @@ const normalizePromptHistory = (value: unknown): PromptHistoryItem[] => {
}, []);
};
-export const normalizeWorkbenchProject = (project: Project): Project => {
+export const normalizeWorkbenchProject = (
+ project: Project,
+ options: {
+ /**
+ * Whether the document is arriving from another realm (a server record,
+ * an import) rather than being kept by this one (the conflict fork that
+ * rescues the live copy). An infinite window's mid-board anchor is a
+ * "you are here" for the session that revealed it: it is dropped from a
+ * document that arrives, and kept for one that stays.
+ */
+ isArriving?: boolean;
+ } = {}
+): Project => {
+ const { isArriving = true } = options;
const legacyWidgetRegions = project.widgetRegions as
| Partial<Record<WidgetRegion | 'left-panel' | 'right-panel' | 'status-bar', WidgetRegionState>>
| undefined;
@@ -1755,8 +1768,9 @@ export const normalizeWorkbenchProject = (project: Project): Project => {
// store is hydrated from the snapshot — a project that has only been
// opened must serialize to its baseline, or the next autosave pushes it.
const strippedSearchValues = stripUnresolvableGallerySearch(instance.state.values);
- const strippedValues =
- stripInfiniteWindowAnchor(strippedSearchValues ?? instance.state.values) ?? strippedSearchValues;
+ const strippedValues = isArriving
+ ? (stripInfiniteWindowAnchor(strippedSearchValues ?? instance.state.values) ?? strippedSearchValues)
+ : strippedSearchValues;
const hasRecentImages = 'recentImages' in instance.state.values;
if (strippedValues === null && !hasRecentImages) {
@@ -1842,17 +1856,20 @@ const recoverProjectUnderNewIdentity = (
snapshotProject: Project,
identity: ProjectRecoveredIdentity
): Project =>
- normalizeWorkbenchProject(
- localProject
- ? {
+ // The fork rescues the LIVE copy, edits and position included; only a
+ // fallback to the snapshot is a document arriving from elsewhere.
+ localProject
+ ? normalizeWorkbenchProject(
+ {
...localProject,
id: identity.id,
name: identity.name,
recoveredAt: identity.recoveredAt,
recoveryOf: identity.recoveryOf,
- }
- : snapshotProject
- );
+ },
+ { isArriving: false }
+ )
+ : normalizeWorkbenchProject(snapshotProject);
export const clampPanelSize = (region: WidgetRegion, sizePx: number): number => {
const { max, min } = getPanelSizeBounds(region);
@@ -2215,7 +2232,7 @@ const normalizeWorkbenchState = (state: WorkbenchState): WorkbenchState => ({
// (they live in the settings store now) and must not resurface here.
account: normalizeWorkbenchAccount(state.account),
notifications: [],
- projects: state.projects.map(normalizeWorkbenchProject),
+ projects: state.projects.map((project) => normalizeWorkbenchProject(project)),
});
const updateActiveLayout = (