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): drop an infinite window anchor on adoption too

Lincoln Stein7424dc634904
diff --git a/invokeai/frontend/webv2/src/features/gallery/contracts.ts b/invokeai/frontend/webv2/src/features/gallery/contracts.ts
index 22a497ba6e..b90f251b46 100644
--- a/invokeai/frontend/webv2/src/features/gallery/contracts.ts
+++ b/invokeai/frontend/webv2/src/features/gallery/contracts.ts
@@ -38,6 +38,7 @@ export {
gallerySemanticReferenceKey,
getImageCluster,
parseGallerySemanticReference,
+ stripInfiniteWindowAnchor,
stripSessionScopedGallerySearch,
stripUnresolvableGallerySearch,
registerImageCluster,
diff --git a/invokeai/frontend/webv2/src/features/gallery/core/semanticImageQuery.ts b/invokeai/frontend/webv2/src/features/gallery/core/semanticImageQuery.ts
index 5a85576854..fcfc20a7ec 100644
--- a/invokeai/frontend/webv2/src/features/gallery/core/semanticImageQuery.ts
+++ b/invokeai/frontend/webv2/src/features/gallery/core/semanticImageQuery.ts
@@ -233,6 +233,23 @@ const stripGallerySearchPositions = (
return nextValues;
};
+/**
+ * The same values with an infinite window's mid-board anchor dropped, or null
+ * when there is none.
+ *
+ * In infinite mode `galleryPage` is not a page number but the anchor of a
+ * mid-board window, set by a reveal from the image map. That is a "you are
+ * here" for the session that made it: restored anywhere else it opens the
+ * gallery stranded in the middle of a board, with no page control (the
+ * footer's is paginated-only) and no way back to the top short of switching
+ * boards. Paginated pages stay — there the value really is the page the user
+ * was reading.
+ */
+export const stripInfiniteWindowAnchor = (values: Record<string, unknown>): Record<string, unknown> | null =>
+ values.paginationMode !== 'paginated' && typeof values.galleryPage === 'number' && values.galleryPage > 0
+ ? { ...values, galleryPage: 0 }
+ : null;
+
/**
* For the SAVE path: drop what the realm reading this back will not have.
*
diff --git a/invokeai/frontend/webv2/src/workbench/persistence.ts b/invokeai/frontend/webv2/src/workbench/persistence.ts
index 7454b73a6f..a58e8ae58e 100644
--- a/invokeai/frontend/webv2/src/workbench/persistence.ts
+++ b/invokeai/frontend/webv2/src/workbench/persistence.ts
@@ -1,7 +1,7 @@
import type { HydratedWorkbenchSnapshot, PersistedWorkbenchSnapshotV1 } from '@workbench/persistenceContracts';
import type { Project, WorkbenchState } from '@workbench/projectContracts';
-import { getGalleryPage, getGallerySettings, stripSessionScopedGallerySearch } from '@features/gallery/contracts';
+import { stripInfiniteWindowAnchor, stripSessionScopedGallerySearch } from '@features/gallery/contracts';
import { timeWorkbenchPerf } from './performanceMarks';
@@ -53,25 +53,16 @@ const stripSessionScopedGalleryState = (project: Project): Project => {
}
const strippedValues = stripSessionScopedGallerySearch(values);
- const hasWindowAnchor = getGallerySettings(values).paginationMode === 'infinite' && getGalleryPage(values) > 0;
+ const strippedAnchorValues = stripInfiniteWindowAnchor(strippedValues ?? values);
- if (strippedValues === null && !hasWindowAnchor) {
+ if (strippedValues === null && strippedAnchorValues === null) {
return [instanceId, instance];
}
didChange = true;
return [
instanceId,
- {
- ...instance,
- state: {
- ...instance.state,
- values: {
- ...(strippedValues ?? values),
- ...(hasWindowAnchor ? { galleryPage: 0 } : {}),
- },
- },
- },
+ { ...instance, state: { ...instance.state, values: strippedAnchorValues ?? strippedValues ?? values } },
];
})
);
diff --git a/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.test.ts b/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.test.ts
index c61acb6706..4d4883cbb7 100644
--- a/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.test.ts
@@ -834,6 +834,35 @@ describe('authoritative project boards', () => {
expect(api.__records.get(draft.id)?.revision).toBe(1);
});
+ it('does not push a project it only opened when the other session left a window anchor', async () => {
+ // The sync baseline is taken from the adopted document; the store is
+ // hydrated from the boot snapshot. Both drop an infinite window's
+ // mid-board anchor, so a project that has only been opened serializes to
+ // its baseline — dropped by one and not the other, the first autosave
+ // would push it unprompted and fork the tab that set it.
+ const draft = { ...createDraftProject([]), name: 'Revealed elsewhere' };
+ const document = persistence.serializeProjectDocument(draft);
+ const widgetInstances = document.widgetInstances as Record<string, { state: { values: Record<string, unknown> } }>;
+
+ widgetInstances.gallery!.state.values = {
+ ...widgetInstances.gallery!.state.values,
+ galleryPage: 5,
+ paginationMode: 'infinite',
+ };
+ api.__seed(document);
+ seedSessionBlob({ openProjectIds: [draft.id] });
+
+ const loaded = await service.loadWorkbench();
+ const opened = loaded!.state.projects.find((project) => project.id === draft.id)!;
+
+ expect(opened.widgetInstances.gallery!.state.values.galleryPage).toBe(0);
+
+ await service.saveWorkbench(stateWithProjects([opened]));
+
+ expect(api.updateProject).not.toHaveBeenCalled();
+ expect(api.__records.get(draft.id)?.revision).toBe(1);
+ });
+
it("retries rather than forks when only the other session's ranking moved", async () => {
// The other tab paged its ranking: the revision moved and the data changed
// only in the positions set against a search this realm cannot resolve.
diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
index eb6b1c86e5..8aae558fcf 100644
--- a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
@@ -858,6 +858,7 @@ describe('adopting a project from another realm', () => {
const values = galleryValuesOf(
galleryProject({
galleryPage: 3,
+ paginationMode: 'paginated',
semanticImageQuery: { clusterId, kind: 'cluster', label: 'beaches' },
})
);
@@ -866,9 +867,21 @@ describe('adopting a project from another realm', () => {
expect(values.galleryPage).toBe(3);
});
+ 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.
+ expect(galleryValuesOf(galleryProject({ galleryPage: 5, paginationMode: 'infinite' })).galleryPage).toBe(0);
+ expect(galleryValuesOf(galleryProject({ galleryPage: 5, paginationMode: 'paginated' })).galleryPage).toBe(5);
+ });
+
it('keeps a search the new realm can rebuild, and the page it was read on', () => {
const values = galleryValuesOf(
- galleryProject({ galleryPage: 3, semanticImageQuery: { kind: 'text', query: 'sunset' } })
+ galleryProject({
+ galleryPage: 3,
+ paginationMode: 'paginated',
+ semanticImageQuery: { kind: 'text', query: 'sunset' },
+ })
);
expect(values.semanticImageQuery).toEqual({ kind: 'text', query: 'sunset' });
diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.ts
index 335c092ecb..8673408524 100644
--- a/invokeai/frontend/webv2/src/workbench/workbenchState.ts
+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.ts
@@ -54,6 +54,7 @@ import {
getBoundedRecentImages,
getGalleryPage,
getPersistedSelectedGalleryItemKeys,
+ stripInfiniteWindowAnchor,
stripUnresolvableGallerySearch,
getGallerySettings,
getSelectedGalleryItemFromValues,
@@ -1747,7 +1748,15 @@ export const normalizeWorkbenchProject = (project: Project): Project => {
// rescues the LIVE copy. So the test is whether the reference resolves
// here, not what kind it is; the latter would delete the ranking the user
// is looking at.
- const strippedValues = stripUnresolvableGallerySearch(instance.state.values);
+ // An infinite window's mid-board anchor goes the same way, for the same
+ // reason the save path drops it: it is a "you are here" for the session
+ // that revealed it. Adoption and the boot snapshot have to agree on this,
+ // because the sync baseline is taken from the adopted document while the
+ // 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 hasRecentImages = 'recentImages' in instance.state.values;
if (strippedValues === null && !hasRecentImages) {