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): filmstrip explicit ScrollArea height, local-first compare drop resolution

joshistoast91d13a0735da
diff --git a/invokeai/frontend/webv2/.vitest-attachments/438c29a9fe00d98bbe895e15797a9cfc3d6198c6.png b/invokeai/frontend/webv2/.vitest-attachments/438c29a9fe00d98bbe895e15797a9cfc3d6198c6.png
new file mode 100644
index 0000000000..47767d2f3d
Binary files /dev/null and b/invokeai/frontend/webv2/.vitest-attachments/438c29a9fe00d98bbe895e15797a9cfc3d6198c6.png differ
diff --git a/invokeai/frontend/webv2/.vitest-attachments/fc08c3270e1ea430af33a61dfa84b70133928be5.png b/invokeai/frontend/webv2/.vitest-attachments/fc08c3270e1ea430af33a61dfa84b70133928be5.png
new file mode 100644
index 0000000000..47767d2f3d
Binary files /dev/null and b/invokeai/frontend/webv2/.vitest-attachments/fc08c3270e1ea430af33a61dfa84b70133928be5.png differ
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewCompareDropZone.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewCompareDropZone.browser.test.tsx
new file mode 100644
index 0000000000..81cb62bcbe
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewCompareDropZone.browser.test.tsx
@@ -0,0 +1,147 @@
+import { ChakraProvider } from '@chakra-ui/react';
+/* oxlint-disable react-perf/jsx-no-new-function-as-prop, react-perf/jsx-no-new-object-as-prop */
+import {
+ DndContext,
+ PointerSensor,
+ useDndMonitor,
+ useDraggable,
+ useSensor,
+ useSensors,
+ type DragEndEvent,
+} from '@dnd-kit/core';
+import { system } from '@theme/system';
+import { widgetCollisionDetection } from '@workbench/widgetDnd';
+import { getGalleryImageDragData, getGalleryImageDragId } from '@workbench/widgets/gallery/galleryDnd';
+import { createInstance } from 'i18next';
+import { act } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import { I18nextProvider, initReactI18next } from 'react-i18next';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+
+import { resolvePreviewCompareDrop } from './previewCompareDnd';
+import { PreviewCompareDropZone } from './PreviewCompareDropZone';
+
+const i18n = createInstance();
+void i18n.use(initReactI18next).init({
+ fallbackLng: 'en',
+ initImmediate: false,
+ lng: 'en',
+ resources: {
+ en: { translation: { widgets: { preview: { dropToCompare: 'Drop to compare' } } } },
+ },
+});
+
+let host: HTMLDivElement | null = null;
+let root: Root | null = null;
+(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
+
+const interact = (action: () => void): Promise<void> =>
+ act(async () => {
+ action();
+ await new Promise<void>((resolve) => {
+ globalThis.setTimeout(resolve, 50);
+ });
+ });
+
+const DraggableThumb = () => {
+ const { listeners, setNodeRef } = useDraggable({
+ data: getGalleryImageDragData([{ boardId: 'none', imageName: 'dragged.png' }]),
+ id: getGalleryImageDragId('dragged.png'),
+ });
+
+ return (
+ <div
+ ref={setNodeRef}
+ {...listeners}
+ data-testid="thumb"
+ style={{ background: '#888', height: 40, left: 10, position: 'fixed', top: 10, touchAction: 'none', width: 40 }}
+ />
+ );
+};
+
+const DropMonitor = ({ onDrop }: { onDrop: (resolution: { imageName: string } | null) => void }) => {
+ useDndMonitor({
+ onDragEnd: (event: DragEndEvent) =>
+ onDrop(resolvePreviewCompareDrop(event.active.data.current, event.over?.data.current ?? null)),
+ });
+
+ return null;
+};
+
+const renderHarness = async () => {
+ const onDrop = vi.fn();
+ const Harness = () => {
+ const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 6 } }));
+
+ return (
+ <DndContext collisionDetection={widgetCollisionDetection} sensors={sensors}>
+ <DropMonitor onDrop={onDrop} />
+ <DraggableThumb />
+ <div data-testid="frame" style={{ height: 300, left: 200, position: 'fixed', top: 100, width: 300 }}>
+ <PreviewCompareDropZone />
+ </div>
+ </DndContext>
+ );
+ };
+
+ host = document.createElement('div');
+ document.body.append(host);
+ root = createRoot(host);
+ await interact(() => {
+ root?.render(
+ <I18nextProvider i18n={i18n}>
+ <ChakraProvider value={system}>
+ <Harness />
+ </ChakraProvider>
+ </I18nextProvider>
+ );
+ });
+
+ return { onDrop };
+};
+
+afterEach(async () => {
+ await interact(() => root?.unmount());
+ host?.remove();
+ host = null;
+ root = null;
+});
+
+const pointer = (type: string, target: EventTarget, clientX: number, clientY: number): void => {
+ target.dispatchEvent(
+ new PointerEvent(type, { bubbles: true, button: 0, clientX, clientY, isPrimary: true, pointerId: 1 })
+ );
+};
+
+describe('PreviewCompareDropZone', () => {
+ it('shows the drop ring during a gallery-image drag and resolves the drop', async () => {
+ const { onDrop } = await renderHarness();
+ const thumb = document.querySelector<HTMLElement>('[data-testid="thumb"]')!;
+
+ expect(document.body.textContent).not.toContain('Drop to compare');
+
+ // Start the drag (activation distance is 6px) and move over the frame.
+ await interact(() => pointer('pointerdown', thumb, 30, 30));
+ await interact(() => pointer('pointermove', thumb.ownerDocument, 60, 60));
+
+ expect(document.body.textContent).toContain('Drop to compare');
+
+ await interact(() => pointer('pointermove', thumb.ownerDocument, 350, 250));
+ await interact(() => pointer('pointerup', thumb.ownerDocument, 350, 250));
+
+ expect(onDrop).toHaveBeenCalledWith({ imageName: 'dragged.png' });
+ expect(document.body.textContent).not.toContain('Drop to compare');
+ });
+
+ it('resolves null when the drop lands outside the zone', async () => {
+ const { onDrop } = await renderHarness();
+ const thumb = document.querySelector<HTMLElement>('[data-testid="thumb"]')!;
+
+ await interact(() => pointer('pointerdown', thumb, 30, 30));
+ await interact(() => pointer('pointermove', thumb.ownerDocument, 60, 60));
+ await interact(() => pointer('pointermove', thumb.ownerDocument, 120, 400));
+ await interact(() => pointer('pointerup', thumb.ownerDocument, 120, 400));
+
+ expect(onDrop).toHaveBeenCalledWith(null);
+ });
+});
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFilmstrip.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFilmstrip.tsx
index 14f1889ba5..fb19e5190f 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFilmstrip.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFilmstrip.tsx
@@ -35,10 +35,20 @@ export const PreviewFilmstrip = ({
}
return (
- <ScrollArea.Root flexShrink={0} minW="0" size="xs" variant="hover" w="full">
- <ScrollArea.Viewport w="full">
+ // The ScrollArea root's recipe defaults to `height: 100%`, so the strip
+ // MUST get an explicit height or it swallows the widget (the frame's
+ // flex-1 collapses). Height = thumb size + scrollbar allowance.
+ <ScrollArea.Root
+ flexShrink={0}
+ h={density === 'full' ? '3.75rem' : '2.75rem'}
+ minW="0"
+ size="xs"
+ variant="hover"
+ w="full"
+ >
+ <ScrollArea.Viewport h="full" w="full">
<ScrollArea.Content asChild>
- <HStack gap="1" pb="1">
+ <HStack align="center" gap="1" h="full">
{images.map((image) => (
<FilmstripThumb
key={image.imageName}
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx
index 7516ea00d1..9d0d0ac112 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx
@@ -388,6 +388,17 @@ export const PreviewWidgetView = ({ region, runtime }: WidgetViewProps) => {
return;
}
+ // Prefer images we already hold (board context includes fresh local
+ // generations that would 404 on a backend by-name fetch).
+ const localImage =
+ boardImagesRef.current.find((image) => image.imageName === resolution.imageName) ??
+ (selectedImageRef.current?.imageName === resolution.imageName ? selectedImageRef.current : null);
+
+ if (localImage) {
+ dispatch({ image: localImage, type: 'setGalleryCompareImage' });
+ return;
+ }
+
getGalleryImageByName(resolution.imageName)
.then((image) => dispatch({ image, type: 'setGalleryCompareImage' }))
.catch((error: unknown) => {
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/__screenshots__/PreviewCompareDropZone.browser.test.tsx/PreviewCompareDropZone-resolves-null-when-the-drop-lands-outside-the-zone-1.png b/invokeai/frontend/webv2/src/workbench/widgets/preview/__screenshots__/PreviewCompareDropZone.browser.test.tsx/PreviewCompareDropZone-resolves-null-when-the-drop-lands-outside-the-zone-1.png
new file mode 100644
index 0000000000..47767d2f3d
Binary files /dev/null and b/invokeai/frontend/webv2/src/workbench/widgets/preview/__screenshots__/PreviewCompareDropZone.browser.test.tsx/PreviewCompareDropZone-resolves-null-when-the-drop-lands-outside-the-zone-1.png differ
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/__screenshots__/PreviewCompareDropZone.browser.test.tsx/PreviewCompareDropZone-shows-the-drop-ring-during-a-gallery-image-drag-and-resolves-the-drop-1.png b/invokeai/frontend/webv2/src/workbench/widgets/preview/__screenshots__/PreviewCompareDropZone.browser.test.tsx/PreviewCompareDropZone-shows-the-drop-ring-during-a-gallery-image-drag-and-resolves-the-drop-1.png
new file mode 100644
index 0000000000..47767d2f3d
Binary files /dev/null and b/invokeai/frontend/webv2/src/workbench/widgets/preview/__screenshots__/PreviewCompareDropZone.browser.test.tsx/PreviewCompareDropZone-shows-the-drop-ring-during-a-gallery-image-drag-and-resolves-the-drop-1.png differ
diff --git a/invokeai/frontend/webv2/vitest.browser.config.mts b/invokeai/frontend/webv2/vitest.browser.config.mts
index bb14e561e3..d2e6b12c46 100644
--- a/invokeai/frontend/webv2/vitest.browser.config.mts
+++ b/invokeai/frontend/webv2/vitest.browser.config.mts
@@ -7,6 +7,9 @@ import viteConfig from './vite.config.mts';
export default mergeConfig(
viteConfig,
defineConfig({
+ // dnd-kit must share the app's React instance in the browser-test module
+ // graph, or its hooks dispatch against a second React copy and crash.
+ optimizeDeps: { include: ['@dnd-kit/core'] },
test: {
browser: {
enabled: true,