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(webv2): match gallery binary ordering
joshistoasta86b7cba257a
diff --git a/.superpowers/sdd/mixed-media-gallery-parity/task-4-report.md b/.superpowers/sdd/mixed-media-gallery-parity/task-4-report.mdindex e15753100a..0efe37cb64 100644--- a/.superpowers/sdd/mixed-media-gallery-parity/task-4-report.md+++ b/.superpowers/sdd/mixed-media-gallery-parity/task-4-report.md@@ -168,3 +168,91 @@ Tests 72 passed (72)- Confirmed cancellation and identity checks surround both names and page hydration.- Confirmed no `useEffect` was added.- No unresolved implementation concern. The listed Task 5/7 removals are deliberate branch-compatibility debt, not mixed-contract ambiguity.++## Fix Round 1++### Review issues addressed++1. Replaced locale-sensitive Gallery item ordering with a deterministic SQLite-BINARY-compatible text comparator. The same comparator now handles `createdAt`, `kind`, and `name`; the ASC/DESC multiplier is applied exactly once to each non-zero comparison result.+2. Added explicit `TODO(Task 5/7)` blocks above the legacy query/cache exports in `features/gallery/queries.ts` and directly above `patchGalleryImageCaches`.++### RED evidence++Command from `invokeai/frontend/webv2`:++```sh+pnpm test src/features/gallery/ui/useGalleryData.test.ts+```++Result before the production fix:++```text+Test Files 1 failed (1)+Tests 1 failed | 10 passed (11)+```++The new mixed-case/punctuation regression expected SQLite binary ascending order:++```text+!bang.png, A.png, Z.png, _draft.png, a.png+```++The locale-sensitive comparator instead produced:++```text+_draft.png, !bang.png, a.png, A.png, Z.png+```++### GREEN evidence++The same focused command after replacing `localeCompare`:++```text+Test Files 1 passed (1)+Tests 11 passed (11)+```++Focused overlay/query/cache regression command:++```sh+pnpm test src/features/gallery/ui/useGalleryData.test.ts src/features/gallery/data/mixedQueries.test.ts src/features/gallery/data/queries.test.ts src/features/gallery/data/itemQueryCache.test.ts src/features/gallery/data/queryCache.test.ts+```++Result:++```text+Test Files 5 passed (5)+Tests 30 passed (30)+```++Static verification:++```sh+pnpm run lint:tsc+pnpm run lint:oxc+pnpm run format:check+```++Results:++```text+tsc --noEmit: passed+oxlint --deny-warnings: passed+oxfmt --check: all matched files correctly formatted+```++### Files changed++- `invokeai/frontend/webv2/src/features/gallery/ui/useGalleryData.ts`+- `invokeai/frontend/webv2/src/features/gallery/ui/useGalleryData.test.ts`+- `invokeai/frontend/webv2/src/features/gallery/queries.ts`+- `invokeai/frontend/webv2/src/features/gallery/data/queryCache.ts`+- `.superpowers/sdd/mixed-media-gallery-parity/task-4-report.md`++### Fix self-review++- The comparator uses direct deterministic string ordering, which matches SQLite BINARY for the ASCII ISO timestamps, item kinds, and regression names in this path.+- Both ascending and descending punctuation/mixed-case expectations are pinned; direction is not inverted or multiplied twice.+- The earlier starred-first and kind tie-break tests remain green.+- The public legacy facade and implementation-level cache wrapper now carry explicit removal obligations.+- No new compatibility surface or `useEffect` was introduced.diff --git a/invokeai/frontend/webv2/src/features/gallery/data/queryCache.ts b/invokeai/frontend/webv2/src/features/gallery/data/queryCache.tsindex 8fa751339e..077c8c15ab 100644--- a/invokeai/frontend/webv2/src/features/gallery/data/queryCache.ts+++ b/invokeai/frontend/webv2/src/features/gallery/data/queryCache.ts@@ -331,6 +331,9 @@ const patchInfiniteData = (* Applies a small mutation to every currently cached page for this account.* The returned rollback is concurrency-safe: it only restores an entry while* the optimistic value is still the current cache value.+ *+ * TODO(Task 5/7): Remove after image actions use confirmed mixed mutation+ * results with `patchGalleryItemCaches`.*/export const patchGalleryImageCaches = (client: QueryClient, patch: GalleryImageCachePatch): (() => void) => {if (patch.imageNames.length === 0) {diff --git a/invokeai/frontend/webv2/src/features/gallery/queries.ts b/invokeai/frontend/webv2/src/features/gallery/queries.tsindex c7783454ac..f1d83b3d8c 100644--- a/invokeai/frontend/webv2/src/features/gallery/queries.ts+++ b/invokeai/frontend/webv2/src/features/gallery/queries.ts@@ -1,33 +1,43 @@export {canonicalizeGalleryItemsFilter,- canonicalizeGalleryImagesFilter,flattenGalleryItemsData,- flattenGalleryImagesData,GALLERY_MAX_INFINITE_PAGES,GALLERY_MAX_ROWS,GALLERY_PAGE_SIZE,galleryBoardsOptions,galleryItemNamesOptions,galleryItemsInfiniteOptions,- galleryImagesInfiniteOptions,galleryKeys,} from './data/queries';export type {CanonicalGalleryItemsFilter,- CanonicalGalleryImagesFilter,GalleryBoardsQuery,GalleryItemsFilter,GalleryItemsListQueryKey,GalleryItemsWindow,+} from './data/queries';++/**+ * TODO(Task 5/7): Remove these legacy image-query facade exports after Gallery+ * state/projection and Preview consume the mixed item query API.+ */+export {+ canonicalizeGalleryImagesFilter,+ flattenGalleryImagesData,+ galleryImagesInfiniteOptions,+} from './data/queries';+export type {+ CanonicalGalleryImagesFilter,GalleryImagesFilter,GalleryImagesListQueryKey,GalleryImagesWindow,} from './data/queries';-export {- invalidateGallery,- invalidateGalleryImages,- invalidateGalleryItems,- patchGalleryImageCaches,- patchGalleryItemCaches,-} from './data/queryCache';-export type { GalleryImageCachePatch, GalleryItemCachePatch } from './data/queryCache';+export { invalidateGallery, invalidateGalleryItems, patchGalleryItemCaches } from './data/queryCache';+export type { GalleryItemCachePatch } from './data/queryCache';++/**+ * TODO(Task 5/7): Remove these legacy image-cache facade exports after image+ * actions and remaining image-only consumers use confirmed mixed item results.+ */+export { invalidateGalleryImages, patchGalleryImageCaches } from './data/queryCache';+export type { GalleryImageCachePatch } from './data/queryCache';diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryData.test.ts b/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryData.test.tsindex b6f0db0827..b0817fd996 100644--- a/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryData.test.ts+++ b/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryData.test.ts@@ -137,6 +137,41 @@ describe('mergeGalleryItemWindow', () => {}).map(({ kind, name }) => `${kind}:${name}`)).toEqual(['image:shared', 'video:shared']);});++ it('uses SQLite binary ordering for mixed-case and punctuation name ties in both directions', () => {+ const createTiedItem = (name: string): GalleryItem => ({+ boardId: 'none',+ category: 'general',+ createdAt: '2026-07-30T12:00:00.000Z',+ fullUrl: `/images/${name}`,+ height: 64,+ isIntermediate: false,+ kind: 'image',+ name,+ starred: false,+ thumbnailUrl: `/thumbnails/${name}`,+ width: 64,+ });+ const items = ['a.png', 'Z.png', '_draft.png', 'A.png', '!bang.png'].map(createTiedItem);++ expect(+ mergeGalleryItemWindow({+ backendItems: items,+ filter: { ...filter, orderDir: 'ASC' },+ maxRows: 60,+ recentImages: [],+ }).map((item) => item.name)+ ).toEqual(['!bang.png', 'A.png', 'Z.png', '_draft.png', 'a.png']);++ expect(+ mergeGalleryItemWindow({+ backendItems: items,+ filter: { ...filter, orderDir: 'DESC' },+ maxRows: 60,+ recentImages: [],+ }).map((item) => item.name)+ ).toEqual(['a.png', '_draft.png', 'Z.png', 'A.png', '!bang.png']);+ });});describe('isGalleryWindowTruncated', () => {diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryData.ts b/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryData.tsindex 5cd6b0a7ed..eb016104da 100644--- a/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryData.ts+++ b/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryData.ts@@ -98,6 +98,8 @@ const isRecentItemVisible = (item: GalleryItem, filter: GalleryImagesFilter): boreturn hasMatchingBoard && hasMatchingCategory;};+const compareSqliteBinaryText = (a: string, b: string): number => (a === b ? 0 : a < b ? -1 : 1);+const compareGalleryItems = (a: GalleryItem,b: GalleryItem,@@ -108,19 +110,19 @@ const compareGalleryItems = (}const direction = orderDir === 'ASC' ? 1 : -1;- const chronologicalOrder = a.createdAt.localeCompare(b.createdAt);+ const chronologicalOrder = compareSqliteBinaryText(a.createdAt, b.createdAt);if (chronologicalOrder !== 0) {return direction * chronologicalOrder;}- const kindOrder = a.kind.localeCompare(b.kind);+ const kindOrder = compareSqliteBinaryText(a.kind, b.kind);if (kindOrder !== 0) {return direction * kindOrder;}- return direction * a.name.localeCompare(b.name);+ return direction * compareSqliteBinaryText(a.name, b.name);};export const mergeGalleryItemWindow = ({