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(webv2): prevent gallery scrolling during image drags

Josh Corbett5d065dd12bb9
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.browser.test.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.browser.test.tsx
index 605119792b..2afed8ebb6 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.browser.test.tsx
@@ -28,6 +28,7 @@ import { accountLifecycle } from '@platform/state/accountLifecycle';
import { getContrastRatio } from '@platform/ui/theme/contrastRatio.testing';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { system } from '@theme/system';
+import { workbenchAutoScroll } from '@workbench/widgetDnd';
import { PreviewFilmstrip } from '@workbench/widgets/preview/PreviewFilmstrip';
import { PreviewFrame } from '@workbench/widgets/preview/PreviewFrame';
import { createInstance } from 'i18next';
@@ -453,7 +454,7 @@ const Harness = ({
<QueryClientProvider client={queryClient!}>
<GalleryUiProvider adapter={createAdapter(progressSessions, liveFollowEnabled, pinnedSessionId)}>
<GalleryWidgetContext value={contextValue}>
- <DndContext sensors={sensors}>
+ <DndContext autoScroll={workbenchAutoScroll} sensors={sensors}>
<DragMonitor />
<Box bg={background} data-testid="gallery-surface" h="full">
<GalleryImageGrid />
@@ -566,6 +567,34 @@ afterEach(async () => {
});
describe('GalleryImageGrid mixed item cells', () => {
+ it('keeps the gallery scroll position when an image is dragged upward out of a long grid', async () => {
+ const items = Array.from({ length: 60 }, (_, index) => createItem('image', `image-${index}.png`));
+ await renderGallery(createGallery({ items, settings: DENSE_SETTINGS }));
+
+ const viewport = host!.querySelector<HTMLElement>('[data-part="viewport"]')!;
+ await interact(() => {
+ viewport.scrollTop = viewport.scrollHeight;
+ }, 50);
+ const initialScrollTop = viewport.scrollTop;
+ expect(initialScrollTop).toBeGreaterThan(viewport.clientHeight);
+
+ const tile = getButton('Select image-59.png for preview');
+ const rect = tile.getBoundingClientRect();
+ const x = rect.left + rect.width / 2;
+ const y = rect.top + rect.height / 2;
+ await interact(() => pointer('pointerdown', tile, x, y));
+ await interact(() => pointer('pointermove', document, x, y - 20), 50);
+ expect(onDragStart).toHaveBeenCalledOnce();
+
+ const edgeY = viewport.getBoundingClientRect().top + 2;
+ await interact(() => pointer('pointermove', document, x, edgeY), 250);
+ expect(viewport.scrollTop).toBe(initialScrollTop);
+
+ await interact(() => pointer('pointermove', document, x, edgeY - 20), 100);
+ await interact(() => pointer('pointerup', document, x, edgeY - 20));
+ expect(viewport.scrollTop).toBe(initialScrollTop);
+ });
+
const starred = createItem('image', 'starred.png', { starred: true });
const sectionOrder = () =>
Array.from(host?.querySelectorAll('[data-gallery-section]') ?? []).map((row) =>
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.tsx
index 5d26671873..19ca418757 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.tsx
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.tsx
@@ -637,7 +637,7 @@ export const GalleryImageGrid = () => {
</Flex>
) : null}
<ScrollArea.Root h="full" minH="0" size="xs" variant="hover" w="full">
- <ScrollArea.Viewport ref={viewportRef} h="full" outline="none" w="full">
+ <ScrollArea.Viewport ref={viewportRef} data-dnd-auto-scroll="false" h="full" outline="none" w="full">
<ScrollArea.Content display="flex" flexDirection="column" minH="full">
{pinnedHeight > 0 ? (
<Box
diff --git a/invokeai/frontend/webv2/src/workbench/shell/WorkbenchShell.tsx b/invokeai/frontend/webv2/src/workbench/shell/WorkbenchShell.tsx
index d89c255343..6774dd5407 100644
--- a/invokeai/frontend/webv2/src/workbench/shell/WorkbenchShell.tsx
+++ b/invokeai/frontend/webv2/src/workbench/shell/WorkbenchShell.tsx
@@ -26,6 +26,7 @@ import {
isWidgetInstanceDragData,
resolveWidgetDragEnd,
type ActiveWidgetDrag,
+ workbenchAutoScroll,
widgetCollisionDetection,
} from '@workbench/widgetDnd';
import { resolveWidgetLabel } from '@workbench/widgetLabels';
@@ -61,11 +62,6 @@ import { TopBar } from './topbar';
const DND_MODIFIERS = [restrictToWindowEdges];
-/**
- * Keep 20% edge zones for short board lists but halve scrolling speed. Collision visibility checks exclude
- * offscreen targets rather than narrowing usable zones.
- */
-const DND_AUTO_SCROLL = { acceleration: 5 };
const EMPTY_FLOATING: NonNullable<Project['floatingWidgets']> = {};
export const WorkbenchShell = () => {
@@ -283,7 +279,7 @@ export const WorkbenchShell = () => {
return (
<FocusRegionProvider>
<DndContext
- autoScroll={DND_AUTO_SCROLL}
+ autoScroll={workbenchAutoScroll}
collisionDetection={widgetCollisionDetection}
modifiers={DND_MODIFIERS}
sensors={sensors}
diff --git a/invokeai/frontend/webv2/src/workbench/widgetDnd.ts b/invokeai/frontend/webv2/src/workbench/widgetDnd.ts
index d812c591bb..4b61f669b1 100644
--- a/invokeai/frontend/webv2/src/workbench/widgetDnd.ts
+++ b/invokeai/frontend/webv2/src/workbench/widgetDnd.ts
@@ -8,10 +8,17 @@ import {
type Collision,
type CollisionDetection,
type ClientRect,
+ type DndContextProps,
} from '@dnd-kit/core';
import { arrayMove } from '@dnd-kit/sortable';
import { isWidgetRegion as isKnownWidgetRegion } from '@workbench/layoutContracts';
+/** Preserve board-list edge scrolling while non-sortable surfaces opt out. */
+export const workbenchAutoScroll = {
+ acceleration: 5,
+ canScroll: (element) => element.getAttribute('data-dnd-auto-scroll') !== 'false',
+} satisfies NonNullable<DndContextProps['autoScroll']>;
+
const clipsOverflow = (value: string): boolean => value !== 'visible';
/**