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(sync): give a fork a baseline it will serialize to

Lincoln Steinb60aee3ddf7f
diff --git a/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.test.ts b/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.test.ts
index 4d4883cbb7..9047849b47 100644
--- a/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.test.ts
@@ -898,6 +898,43 @@ describe('authoritative project boards', () => {
expect(api.__records.get(draft.id)?.revision).toBe(3);
});
+ it('gives a fork a baseline it will serialize to, so it is not pushed unprompted', async () => {
+ // The fork's store copy is hydrated from the recovered document, which
+ // drops an infinite window anchor. A baseline taken from the wire bytes
+ // would still carry it, and the fork's first autosave would read the drop
+ // as an edit.
+ const project = seedServerProject('Deleted elsewhere');
+ const opened = await service.hydrateProjectFromServer(project.id);
+ const galleryEntry = Object.entries(opened!.widgetInstances).find(([, instance]) => instance.typeId === 'gallery')!;
+ const [galleryInstanceId, galleryInstance] = galleryEntry;
+ const edited = {
+ ...opened!,
+ name: 'Edited locally',
+ widgetInstances: {
+ ...opened!.widgetInstances,
+ [galleryInstanceId]: {
+ ...galleryInstance,
+ state: {
+ ...galleryInstance.state,
+ values: { ...galleryInstance.state.values, galleryPage: 7, paginationMode: 'infinite' },
+ },
+ },
+ },
+ };
+
+ api.__records.delete(project.id);
+
+ const result = await service.saveWorkbench(stateWithProjects([edited]));
+ const [fork] = result.deletedProjectForks;
+
+ expect(fork!.recoveredProject.widgetInstances[galleryInstanceId]?.state.values.galleryPage).toBe(0);
+ api.updateProject.mockClear();
+
+ await service.saveWorkbench(stateWithProjects([fork!.recoveredProject]));
+
+ expect(api.updateProject).not.toHaveBeenCalled();
+ });
+
it('forks rather than resurrects a project deleted on another device', async () => {
const project = seedServerProject('Deleted elsewhere');
const opened = await service.hydrateProjectFromServer(project.id);
diff --git a/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.ts b/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.ts
index be3f439807..1e17679bb2 100644
--- a/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.ts
+++ b/invokeai/frontend/webv2/src/workbench/projects/syncedPersistence.ts
@@ -424,7 +424,10 @@ const recoverConflictingProject = async (
assertOwner(syncState);
syncState.syncEntries.set(recoveredIdentity.id, {
- pushedDoc: JSON.stringify(recoveredDocument),
+ // As this realm holds it, not the wire bytes: the fork's store copy is
+ // hydrated from this document, and a fork whose tab is already closed
+ // is a document arriving like any other.
+ pushedDoc: JSON.stringify(serializeProjectDocument(recoveredProject)),
revision: created.revision,
});
// Recorded for the same reason the deletion fork records it: the fork is a project the server
@@ -495,7 +498,10 @@ const forkDeletedProject = async (
}
syncState.syncEntries.set(recoveredIdentity.id, {
- pushedDoc: JSON.stringify(recoveredDocument),
+ // As this realm holds it, not the wire bytes: the fork's store copy is
+ // hydrated from this document, and a fork whose tab is already closed
+ // is a document arriving like any other.
+ pushedDoc: JSON.stringify(serializeProjectDocument(recoveredProject)),
revision: created.revision,
});
syncState.pendingBoardAssignments.push({ boardId: created.board_id, projectId: recoveredIdentity.id });