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(preview): drop the compare memo when the item has left its board
Lincoln Stein4c9640dfe73b
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewNavigation.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewNavigation.browser.test.tsxindex 6e1d0ab747..289b30359a 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewNavigation.browser.test.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewNavigation.browser.test.tsx@@ -928,6 +928,46 @@ describe('preview keyboard navigation boundary', () => {expect(context?.getItemSelectionPage?.(deepC)).toBe(30);});+ it('does not restore a remembered page for an item since moved to another board', async () => {+ // Moving the compare image re-boards it in place and leaves the selection's+ // query alone, so the memo's key still matches. The page it remembers is a+ // window of the OLD board's listing, which the item is no longer in.+ setGalleryValues({+ compareImage: legacyImage('compare-top', '2026-07-24T00:00:00.000Z'),+ galleryPage: 0,+ recentImages: [],+ selectedImage: legacyImage('deep-newer', '2026-07-20T00:00:02.000Z'),+ selectedImageName: 'deep-newer',+ selectedImageQuery: deepQuery,+ });+ mocks.galleryItemPages = deepBoardPages([createImageItem('deep-newer', '2026-07-20T00:00:02.000Z')]);+ mocks.galleryItemPages[0] = { items: [createImageItem('compare-top', '2026-07-24T00:00:00.000Z')], total: 2 };++ await render();++ const swap = () =>+ act(async () => {+ registeredCommands.get('viewer.swapImages')?.();+ await Promise.resolve();+ });++ await swap();+ await commitLastSelection();+ // The deep image, now in the compare slot, is moved to another board.+ setGalleryValues({+ compareImage: { ...legacyImage('deep-newer', '2026-07-20T00:00:02.000Z'), boardId: 'board-b' },+ });+ await rerender();+ await swap();++ expect(mocks.commands.gallery.selectItem).toHaveBeenLastCalledWith(+ expect.objectContaining({ kind: 'image', name: 'deep-newer', boardId: 'board-b' }),+ undefined,+ 0,+ true+ );+ });+it('fetches the next infinite page before stepping past the loaded backend boundary', async () => {const newest: GalleryImage = {...mocks.recentImages[0],diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsxindex 18cd11092f..aa7e33cb8b 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx@@ -335,14 +335,18 @@ export const PreviewWidgetView = ({ region, runtime }: WidgetViewProps) => {// they were before the first swap. A page names a window of ONE query,// though: restored into a different board, view, order, mode or search it// would anchor that listing 1800 rows down around an image from another,- // so the memo is only honoured in the query it was recorded in.- const swappedOutRef = useRef<{ key: GalleryItemKey; page: number; queryKey: string } | null>(null);+ // so the memo is only honoured in the query it was recorded in — and only+ // while the item is still in that query's board. Moving the compare image+ // to another board re-boards it in place without touching the selection's+ // query, so the key alone would still match.+ const swappedOutRef = useRef<{ boardId: string; key: GalleryItemKey; page: number; queryKey: string } | null>(null);const swapCompareImages = useCallback(() => {if (selectedItem?.kind === 'image' && compareImage) {const compareItem = legacyGeneratedImageToGalleryItem(compareImage);const swappedOut = swappedOutRef.current;swappedOutRef.current = {+ boardId: selectedItem.boardId,key: toGalleryItemKey(selectedItem),page: selectedImageQuery.page,queryKey: navigationQueryKey,@@ -350,7 +354,8 @@ export const PreviewWidgetView = ({ region, runtime }: WidgetViewProps) => {if (swappedOut &&swappedOut.key === toGalleryItemKey(compareItem) &&- swappedOut.queryKey === navigationQueryKey+ swappedOut.queryKey === navigationQueryKey &&+ swappedOut.boardId === compareItem.boardId) {selectGalleryItemAtPage(compareItem, swappedOut.page);} else {