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(preview): hand back the top of the board listing after a ranked pick

Lincoln Stein5fa69c06a392
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.tsx
index 52dec9da86..1f4baaffa6 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
@@ -320,6 +320,8 @@ beforeEach(() => {
delete (mocks.project.widgetInstances.gallery.state.values as Record<string, unknown>).galleryPage;
delete (mocks.project.widgetInstances.gallery.state.values as Record<string, unknown>).imageOrderDir;
delete (mocks.project.widgetInstances.gallery.state.values as Record<string, unknown>).paginationMode;
+ delete (mocks.project.widgetInstances.gallery.state.values as Record<string, unknown>).semanticImageQuery;
+ delete (mocks.project.widgetInstances.gallery.state.values as Record<string, unknown>).selectedImageQuery;
mocks.project.widgetInstances.gallery.state.values.recentImages = mocks.recentImages;
mocks.project.widgetInstances.gallery.state.values.selectedImage = {
...mocks.recentImages[0],
@@ -581,6 +583,146 @@ describe('preview keyboard navigation boundary', () => {
);
});
+ it('does not carry the page the preview opened on onto a ranked pick', async () => {
+ const selected = {
+ ...mocks.recentImages[0],
+ boardId: 'none',
+ imageCategory: 'general' as const,
+ imageName: 'ranked-selected',
+ starred: false,
+ };
+ const neighbor = {
+ ...mocks.recentImages[1],
+ boardId: 'none',
+ imageCategory: 'general' as const,
+ imageName: 'ranked-neighbor',
+ starred: false,
+ };
+ const galleryValues = mocks.project.widgetInstances.gallery.state.values as Record<string, unknown>;
+
+ // A deep reveal from the image map stamped board page 30 onto the
+ // selection; starting the similarity search reset the grid to page 0.
+ // Carrying that stale page onto a ranked pick strands it: the item picked
+ // out of a ranking is nowhere near board page 30, so clearing the chip
+ // would anchor navigation ~1800 rows from both the selection and the grid.
+ galleryValues.galleryPage = 0;
+ galleryValues.paginationMode = 'infinite';
+ galleryValues.recentImages = [];
+ galleryValues.semanticImageQuery = { kind: 'text', query: 'sunset' };
+ galleryValues.selectedImage = selected;
+ galleryValues.selectedImageName = selected.imageName;
+ galleryValues.selectedImageQuery = {
+ boardId: 'none',
+ galleryView: 'images',
+ imageOrderDir: 'DESC',
+ page: 30,
+ paginationMode: 'infinite',
+ searchTerm: '',
+ };
+ mocks.galleryItemPages = [
+ {
+ items: [selected, neighbor].map((image) => ({
+ boardId: image.boardId,
+ category: image.imageCategory,
+ createdAt: image.queuedAt,
+ fullUrl: image.imageUrl,
+ height: image.height,
+ isIntermediate: false,
+ kind: 'image' as const,
+ name: image.imageName,
+ sourceQueueItemId: image.sourceQueueItemId,
+ starred: image.starred,
+ thumbnailUrl: image.thumbnailUrl,
+ width: image.width,
+ })),
+ total: 2,
+ },
+ ];
+
+ await render();
+ await pressArrow('ArrowRight');
+
+ expect(mocks.commands.gallery.selectItem).toHaveBeenCalledWith(
+ expect.objectContaining({ kind: 'image', name: neighbor.imageName }),
+ undefined,
+ 0,
+ true
+ );
+ });
+
+ it('stamps the top of the board listing for a ranked pick even when the footer paginates the ranking', async () => {
+ const filler = {
+ ...mocks.recentImages[0],
+ boardId: 'none',
+ imageCategory: 'general' as const,
+ imageName: 'ranked-page-zero',
+ starred: false,
+ };
+ const selected = {
+ ...mocks.recentImages[0],
+ boardId: 'none',
+ imageCategory: 'general' as const,
+ imageName: 'ranked-page-one-selected',
+ starred: false,
+ };
+ const neighbor = {
+ ...mocks.recentImages[1],
+ boardId: 'none',
+ imageCategory: 'general' as const,
+ imageName: 'ranked-page-one-neighbor',
+ starred: false,
+ };
+ const galleryValues = mocks.project.widgetInstances.gallery.state.values as Record<string, unknown>;
+ const toItem = (image: typeof filler) => ({
+ boardId: image.boardId,
+ category: image.imageCategory,
+ createdAt: image.queuedAt,
+ fullUrl: image.imageUrl,
+ height: image.height,
+ isIntermediate: false,
+ kind: 'image' as const,
+ name: image.imageName,
+ sourceQueueItemId: image.sourceQueueItemId,
+ starred: image.starred,
+ thumbnailUrl: image.thumbnailUrl,
+ width: image.width,
+ });
+
+ // In paginated mode the footer paginates the RANKING, so the grid's page
+ // is a rank page, not a board page — stamping it would send navigation to
+ // an unrelated board slice once the chip is cleared. Clearing resets the
+ // grid to board page 0, so that is what a ranked pick hands back: neither
+ // the grid's 1 nor the stale 30.
+ galleryValues.galleryPage = 1;
+ galleryValues.paginationMode = 'paginated';
+ galleryValues.recentImages = [];
+ galleryValues.semanticImageQuery = { kind: 'text', query: 'sunset' };
+ galleryValues.selectedImage = selected;
+ galleryValues.selectedImageName = selected.imageName;
+ galleryValues.selectedImageQuery = {
+ boardId: 'none',
+ galleryView: 'images',
+ imageOrderDir: 'DESC',
+ page: 30,
+ paginationMode: 'paginated',
+ searchTerm: '',
+ };
+ mocks.galleryItemPages = [
+ { items: [filler].map(toItem), total: 3 },
+ { items: [selected, neighbor].map(toItem), total: 3 },
+ ];
+
+ await render();
+ await pressArrow('ArrowRight');
+
+ expect(mocks.commands.gallery.selectItem).toHaveBeenCalledWith(
+ expect.objectContaining({ kind: 'image', name: neighbor.imageName }),
+ undefined,
+ 0,
+ true
+ );
+ });
+
it('enables live-follow when stepping onto the active placeholder', async () => {
mocks.project.queue.items = [queueItem];
mocks.useActiveProgressTarget.mockReturnValue({ itemIndex: 1, queueItemId: 'queue-item-live' });
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/usePreviewNavigation.ts b/invokeai/frontend/webv2/src/workbench/widgets/preview/usePreviewNavigation.ts
index e655927a90..083ac4249b 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/usePreviewNavigation.ts
+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/usePreviewNavigation.ts
@@ -282,12 +282,17 @@ export const usePreviewNavigation = ({
const pageParam = pageIndex === undefined || pageIndex < 0 ? undefined : boardItemsData?.pageParams[pageIndex];
// `page` is stamped as a BOARD page and read as one everywhere else, so
// a ranked window's page params — offsets into the ranking — must not be
- // written into it. Stepping through a ranked list therefore leaves the
- // board context it was opened from untouched, ready for the moment the
- // search is cleared.
+ // written into it. Neither may the grid's own page: in paginated mode
+ // the footer paginates the RANKING, so that number is a rank page too.
+ // Carrying the page the preview opened on is no better — the item
+ // picked out of a ranking is nowhere near the board slice it names, and
+ // a deep one strands navigation there once the chip is cleared. What
+ // holds in both modes is the top of the listing: setting a search and
+ // clearing it both reset the grid to page 0, so that is the board
+ // context a ranked session hands back.
const selectionPage =
navigationSemanticQuery !== null
- ? selectedImageQuery.page
+ ? 0
: typeof pageParam === 'number'
? Math.floor(pageParam / GALLERY_PAGE_SIZE)
: selectedImageQuery.page;