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): preserve mixed gallery drag identity

joshistoastf4e677d4d16d
diff --git a/.superpowers/sdd/mixed-media-gallery-parity/task-6-report.md b/.superpowers/sdd/mixed-media-gallery-parity/task-6-report.md
index 9b3632f4c7..54832f591e 100644
--- a/.superpowers/sdd/mixed-media-gallery-parity/task-6-report.md
+++ b/.superpowers/sdd/mixed-media-gallery-parity/task-6-report.md
@@ -109,7 +109,9 @@ Tests 15 passed (15)
- Added `GalleryItemDragData` with `kind: 'gallery-item'` and an ordered
`GalleryItemRef[]`.
-- Draggable IDs are exact `GalleryItemKey` values.
+- Draggable IDs retain the exact `GalleryItemKey` under a source namespace so
+ co-mounted Grid, Preview frame, and Preview filmstrip registrations remain
+ independent.
- Added the non-empty item guard and retained
`isGalleryImageDragData()` as a non-empty all-image refinement whose narrowed
items expose image names without a media cast.
@@ -225,8 +227,9 @@ architecture: 3 files passed, 34 tests passed
an all-image vector and rejects video/mixed vectors without moving an image
subset.
2. The canonical Gallery context target is converted to the current
- `ImageContextMenu` target only when every target item is an image. Video and
- mixed targets are rejected pending the Task 7 common item action menu.
+ `ImageContextMenu` target only when its complete ordered ref vector resolves
+ to images. Video, mixed, and unresolved targets are rejected pending the
+ Task 7 common item action menu.
3. Grid delete/star hotkeys still call the image-action port only for a fully
resolved all-image selection. Video, mixed, and unresolved selections are
rejected pending Task 7.
@@ -244,7 +247,9 @@ architecture: 3 files passed, 34 tests passed
comparison targets remain intentionally image-only. Their shared refinement
accepts only non-empty all-image item payloads.
-No retained adapter converts or casts a video to an image.
+The App context-menu bridge retains
+`actions as unknown as ImageActions` as a Task 7 compatibility cast. It does
+not cast a media value or allow a video to cross an image-only boundary.
## Self-review
@@ -259,3 +264,114 @@ No retained adapter converts or casts a video to an image.
regression test.
- Confirmed `git diff --check` is clean.
- No unresolved implementation concern.
+
+## Review follow-up: ordered identity and drop presentation
+
+An independent review of `4c5aae43c1` found four interaction gaps. The
+follow-up keeps the original scope and constraints while correcting them:
+
+1. Grid drag payloads now derive the complete ordered ref vector directly from
+ `selectedItemKeys`. Lazy range members that are not materialized remain in
+ the payload, including videos that must make the Task 7 image bridge reject
+ the entire move.
+2. Context targets carry both the complete ordered `itemRefs` and the currently
+ loaded canonical `items`. The App image menu resolves every ref by qualified
+ key and rejects mixed or unresolved targets instead of exposing a loaded
+ image subset.
+3. Draggable registrations use
+ `gallery-grid|preview-frame|preview-filmstrip:<GalleryItemKey>`. This keeps
+ co-mounted sources independent while preserving qualified identity in every
+ ID. Disabled frames use a per-mount React ID instead of a synthetic
+ `image:none` registration.
+4. Upscale, Generate Reference Images, and Regional Guidance share a compatible
+ image-droppable boundary. It disables dnd-kit registration and suppresses
+ visible `isOver` for video/mixed active payloads while continuing to accept
+ all-image payloads.
+
+The board menu now also memoizes one `GalleryItemKey -> boardId` index and
+passes it to every row, avoiding a complete loaded-item index rebuild per row.
+
+### Follow-up RED
+
+The full-ref Grid regressions initially produced:
+
+```text
+Test Files 1 failed (1)
+Tests 3 failed | 9 passed (12)
+```
+
+The failures showed the unloaded video missing from the drag payload and
+`itemRefs` missing from single and mixed context targets. The App bridge
+regression then produced:
+
+```text
+Test Files 1 failed (1)
+Tests 1 failed | 1 passed (2)
+```
+
+It exposed `["loaded.png"]` for a target whose complete selection also
+contained an unloaded video.
+
+The co-mounted registration regressions produced:
+
+```text
+Unit: 1 failed | 6 passed (7)
+Browser: 1 failed | 12 passed (13)
+```
+
+The unit failure showed an un-namespaced `image:shared` ID. The browser failure
+showed Preview's single-image registration replacing the Grid's mixed payload.
+
+The visual-target regression initially failed at suite import because the
+compatible image-droppable boundary did not exist:
+
+```text
+Test Files 1 failed (1)
+Tests no tests
+```
+
+### Follow-up GREEN
+
+The combined affected unit run was:
+
+```text
+Test Files 5 passed (5)
+Tests 37 passed (37)
+```
+
+The combined affected browser run covered the App bridge, Grid, all three
+image-only visual targets, Preview frame, and Preview comparison:
+
+```text
+Test Files 5 passed (5)
+Tests 27 passed (27)
+```
+
+### Follow-up verification
+
+```text
+pnpm lint:tsc
+tsc --noEmit: passed
+
+pnpm test
+Test Files 375 passed (375)
+Tests 4951 passed (4951)
+
+pnpm test:browser
+Test Files 63 passed (63)
+Tests 268 passed (268)
+
+pnpm test:fixtures
+Tests 4 passed (4)
+
+pnpm architecture:check
+Test Files 3 passed (3)
+Tests 34 passed (34)
+
+pnpm lint
+format, oxlint, tsc, and architecture: passed
+```
+
+The full browser suite again emitted its existing React `act(...)`,
+missing-i18n-instance, and intentional error-boundary diagnostics and exited
+successfully.
diff --git a/invokeai/frontend/webv2/src/app/GalleryImageActionsBridge.browser.test.tsx b/invokeai/frontend/webv2/src/app/GalleryImageActionsBridge.browser.test.tsx
new file mode 100644
index 0000000000..c75d0968bf
--- /dev/null
+++ b/invokeai/frontend/webv2/src/app/GalleryImageActionsBridge.browser.test.tsx
@@ -0,0 +1,115 @@
+/* oxlint-disable react-perf/jsx-no-new-array-as-prop, react-perf/jsx-no-new-object-as-prop */
+import type { GalleryImageItem, GalleryItemRef } from '@features/gallery/contracts';
+import type { GalleryImageActions, GalleryItemContextMenuTarget } from '@features/gallery/react';
+import type { ReactNode, Ref } from 'react';
+
+import { useGalleryImageActions } from '@features/gallery/ui/GalleryUiContext';
+import { act, createRef, useImperativeHandle } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+
+import { GalleryImageActionsAdapter, GalleryImageContextMenu } from './GalleryImageActionsBridge';
+
+const mocks = vi.hoisted(() => ({
+ moveImagesToBoard: vi.fn(),
+}));
+
+vi.mock('@workbench/image-actions', () => ({
+ ImageContextMenu: ({ target }: { target: { images: Array<{ imageName: string }> } | null }) => (
+ <output data-testid="image-context-target">
+ {JSON.stringify(target?.images.map((image) => image.imageName) ?? null)}
+ </output>
+ ),
+ useImageActions: () => ({
+ deleteImages: vi.fn(),
+ moveImagesToBoard: mocks.moveImagesToBoard,
+ setImagesStarred: vi.fn(),
+ }),
+}));
+
+const loadedImage: GalleryImageItem = {
+ boardId: 'board-a',
+ category: 'general',
+ createdAt: '2026-07-30T00:00:00.000Z',
+ fullUrl: '/full/loaded.png',
+ height: 64,
+ isIntermediate: false,
+ kind: 'image',
+ name: 'loaded.png',
+ starred: false,
+ thumbnailUrl: '/thumbnail/loaded.png',
+ width: 64,
+};
+const mixedRefs: GalleryItemRef[] = [
+ { kind: 'image', name: loadedImage.name },
+ { kind: 'video', name: 'unloaded.mp4' },
+];
+const noop = vi.fn();
+const directActions: GalleryImageActions = {
+ deleteImages: vi.fn(),
+ moveImagesToBoard: mocks.moveImagesToBoard,
+ moveItemsToBoard: vi.fn(),
+ setImagesStarred: vi.fn(),
+};
+
+let host: HTMLDivElement | null = null;
+let root: Root | null = null;
+const actionsRef = createRef<GalleryImageActions>();
+(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
+
+const ActionsProbe = ({ ref }: { ref: Ref<GalleryImageActions> }) => {
+ const actions = useGalleryImageActions();
+ useImperativeHandle(ref, () => actions, [actions]);
+ return null;
+};
+
+const render = async (children: ReactNode) => {
+ await act(() => {
+ root?.render(children);
+ });
+};
+
+beforeEach(() => {
+ vi.clearAllMocks();
+ host = document.createElement('div');
+ document.body.append(host);
+ root = createRoot(host);
+});
+
+afterEach(async () => {
+ await act(() => {
+ root?.unmount();
+ });
+ host?.remove();
+ host = null;
+ root = null;
+});
+
+describe('GalleryImageActionsBridge mixed selection boundaries', () => {
+ it('does not expose a partial image context target when an unloaded video ref is selected', async () => {
+ const target: GalleryItemContextMenuTarget = {
+ itemRefs: mixedRefs,
+ items: [loadedImage],
+ x: 20,
+ y: 40,
+ };
+
+ await render(<GalleryImageContextMenu actions={directActions} boards={[]} target={target} onClose={noop} />);
+
+ expect(host?.querySelector('[data-testid="image-context-target"]')?.textContent).toBe('null');
+ });
+
+ it('does not move the loaded image subset of an image plus unloaded-video ref vector', async () => {
+ await render(
+ <GalleryImageActionsAdapter boards={[]} generateValues={{}} projectId="project-1" onImagesDeleted={noop}>
+ <ActionsProbe ref={actionsRef} />
+ </GalleryImageActionsAdapter>
+ );
+
+ await act(async () => {
+ await actionsRef.current?.moveItemsToBoard(mixedRefs, 'board-b');
+ });
+
+ expect(mocks.moveImagesToBoard).not.toHaveBeenCalled();
+ });
+});
diff --git a/invokeai/frontend/webv2/src/app/GalleryImageActionsBridge.tsx b/invokeai/frontend/webv2/src/app/GalleryImageActionsBridge.tsx
index ff56aa30b1..7c65ac0100 100644
--- a/invokeai/frontend/webv2/src/app/GalleryImageActionsBridge.tsx
+++ b/invokeai/frontend/webv2/src/app/GalleryImageActionsBridge.tsx
@@ -5,7 +5,7 @@ import type {
} from '@features/gallery/react';
import type { ReactNode } from 'react';
-import { galleryImageItemToGalleryImage, isGalleryImageItem } from '@features/gallery/contracts';
+import { galleryImageItemToGalleryImage, isGalleryImageItem, toGalleryItemKey } from '@features/gallery/contracts';
import { GalleryImageActionsProvider } from '@features/gallery/react';
import { getGalleryItemDragData, isGalleryImageDragData } from '@features/gallery/utility';
import { ImageContextMenu, useImageActions, type ImageActions } from '@workbench/image-actions';
@@ -14,17 +14,28 @@ import { useMemo } from 'react';
const GalleryImageContextMenuComponent = ({ actions, boards, onClose, target }: GalleryItemContextMenuProps) => {
// TODO(Task 7): The current App action menu is image-only. Keep its input
// strict until the canonical mixed-media context menu/actions port lands.
- const imageTarget = useMemo(
- () =>
- target && target.items.length > 0 && target.items.every(isGalleryImageItem)
- ? {
- images: target.items.map(galleryImageItemToGalleryImage),
- x: target.x,
- y: target.y,
- }
- : null,
- [target]
- );
+ const imageTarget = useMemo(() => {
+ if (!target || target.itemRefs.length === 0 || target.itemRefs.some((ref) => ref.kind !== 'image')) {
+ return null;
+ }
+
+ const loadedItemsByKey = new Map(target.items.map((item) => [toGalleryItemKey(item), item]));
+ const imageItems = target.itemRefs.flatMap((ref) => {
+ const item = loadedItemsByKey.get(toGalleryItemKey(ref));
+
+ return item && isGalleryImageItem(item) ? [item] : [];
+ });
+
+ if (imageItems.length !== target.itemRefs.length) {
+ return null;
+ }
+
+ return {
+ images: imageItems.map(galleryImageItemToGalleryImage),
+ x: target.x,
+ y: target.y,
+ };
+ }, [target]);
return (
<ImageContextMenu
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryBoardSelect.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryBoardSelect.tsx
index 73b550f5b8..32b93d33bf 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryBoardSelect.tsx
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryBoardSelect.tsx
@@ -1,4 +1,4 @@
-import type { GalleryItem, GalleryItemRef } from '@features/gallery/core/items';
+import type { GalleryItem, GalleryItemKey, GalleryItemRef } from '@features/gallery/core/items';
import type { GalleryBoard } from '@features/gallery/core/types';
import {
@@ -16,6 +16,7 @@ import {
Text,
} from '@chakra-ui/react';
import { useDndContext, useDndMonitor, useDroppable, type DragEndEvent, type DragStartEvent } from '@dnd-kit/core';
+import { toGalleryItemKey } from '@features/gallery/core/items';
import { Button, CloseButton, IconButton } from '@platform/ui';
import {
ArchiveIcon,
@@ -47,7 +48,6 @@ import { GalleryBoardMenu, type GalleryBoardMenuTarget } from './GalleryBoardMen
import {
getGalleryBoardDropData,
getGalleryBoardDropId,
- getGalleryItemRefsOutsideBoard,
isGalleryItemDragData,
resolveGalleryBoardDrop,
} from './galleryDnd';
@@ -85,6 +85,10 @@ export const GalleryBoardSelect = () => {
const boardMenuActiveRef = useRef(false);
const dragOpenedMenuRef = useRef(false);
const isGalleryItemDragActive = isGalleryItemDragData(active?.data.current);
+ const loadedItemBoardIds = useMemo(
+ () => new Map<GalleryItemKey, string>(gallery.items.map((item) => [toGalleryItemKey(item), item.boardId])),
+ [gallery.items]
+ );
const trimmedSearchTerm = boardSearchTerm.trim();
const normalizedSearchTerm = trimmedSearchTerm.toLowerCase();
const matchesSearch = useCallback(
@@ -284,6 +288,7 @@ export const GalleryBoardSelect = () => {
badgeColor="blue"
board={projectBoard}
isSelected={projectBoard.id === gallery.selectedBoardId}
+ loadedItemBoardIds={loadedItemBoardIds}
onOpenMenu={openBoardMenu}
onSelectBoard={actions.selectBoard}
onSelectComplete={closeAndReset}
@@ -305,6 +310,7 @@ export const GalleryBoardSelect = () => {
<BoardRow
board={uncategorizedBoard}
isSelected={uncategorizedBoard.id === gallery.selectedBoardId}
+ loadedItemBoardIds={loadedItemBoardIds}
onOpenMenu={openBoardMenu}
onSelectBoard={actions.selectBoard}
onSelectComplete={closeAndReset}
@@ -318,6 +324,7 @@ export const GalleryBoardSelect = () => {
key={board.id}
board={board}
isSelected={board.id === gallery.selectedBoardId}
+ loadedItemBoardIds={loadedItemBoardIds}
onSelectBoard={actions.selectBoard}
onSelectComplete={closeAndReset}
/>
@@ -334,6 +341,7 @@ export const GalleryBoardSelect = () => {
badgeColor="gray"
board={board}
isSelected={board.id === gallery.selectedBoardId}
+ loadedItemBoardIds={loadedItemBoardIds}
onOpenMenu={openBoardMenu}
onSelectBoard={actions.selectBoard}
onSelectComplete={closeAndReset}
@@ -455,6 +463,7 @@ const BoardRow = ({
badgeColor,
board,
isSelected,
+ loadedItemBoardIds,
onOpenMenu,
onSelectBoard,
onSelectComplete,
@@ -463,19 +472,19 @@ const BoardRow = ({
badgeColor?: 'blue' | 'gray';
board: GalleryBoard;
isSelected: boolean;
+ loadedItemBoardIds: ReadonlyMap<GalleryItemKey, string>;
onOpenMenu?: (board: GalleryBoard, x: number, y: number) => void;
onSelectBoard: (boardId: string) => void;
onSelectComplete: () => void;
}) => {
const { t } = useTranslation();
const { active } = useDndContext();
- const { gallery } = useGalleryWidget();
const dragData = active?.data.current;
const canDropItems =
board.kind === 'board' &&
isGalleryItemDragData(dragData) &&
- getGalleryItemRefsOutsideBoard(dragData, board.id, gallery.items).length > 0;
+ dragData.items.some((ref) => loadedItemBoardIds.get(toGalleryItemKey(ref)) !== board.id);
const { isOver, setNodeRef } = useDroppable({
data: getGalleryBoardDropData(board.id, board.kind),
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 4034e4cdf1..380bc0bbc4 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
@@ -1,13 +1,17 @@
-/* oxlint-disable react-perf/jsx-no-new-object-as-prop */
-import type { GalleryItem, GalleryItemRef } from '@features/gallery/contracts';
+/* oxlint-disable react-perf/jsx-no-new-array-as-prop, react-perf/jsx-no-new-object-as-prop */
+import type { GalleryItem, GalleryItemRef, GeneratedImageContract } from '@features/gallery/contracts';
+import type { StreamingImageSource } from '@platform/ui/streaming-image/streamingImageSource';
import { ChakraProvider } from '@chakra-ui/react';
import { DndContext, PointerSensor, useDndMonitor, useSensor, useSensors, type DragStartEvent } from '@dnd-kit/core';
import { DEFAULT_GALLERY_SETTINGS } from '@features/gallery/core/settings';
import { GalleryUiProvider, type GalleryUiAdapter } from '@features/gallery/react';
+import { isGalleryImageDragData } from '@features/gallery/utility';
import { accountLifecycle } from '@platform/state/accountLifecycle';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { system } from '@theme/system';
+import { PreviewFilmstrip } from '@workbench/widgets/preview/PreviewFilmstrip';
+import { PreviewFrame } from '@workbench/widgets/preview/PreviewFrame';
import { createInstance } from 'i18next';
import { act, type ReactNode } from 'react';
import { createRoot, type Root } from 'react-dom/client';
@@ -135,6 +139,23 @@ const createItem = (kind: GalleryItem['kind'], name: string, overrides: Partial<
: ({ ...base, kind } as GalleryItem);
};
+const createPreviewImage = (name: string): GeneratedImageContract => ({
+ height: 96,
+ imageName: name,
+ imageUrl: `/full/image/${name}`,
+ queuedAt: '2026-07-30T00:00:00.000Z',
+ sourceQueueItemId: 'queue-1',
+ thumbnailUrl: `/thumbnail/image/${name}`,
+ width: 128,
+});
+const previewSource: StreamingImageSource = {
+ alt: 'shared',
+ height: 96,
+ kind: 'final',
+ src: '/full/image/shared',
+ width: 128,
+};
+
const board = {
archived: false,
assetCount: 0,
@@ -219,10 +240,22 @@ const createActions = (): GalleryActions =>
uploadFiles: vi.fn(),
}) as unknown as GalleryActions;
-type CanonicalContextTarget = { items: GalleryItem[]; x: number; y: number } | null;
+type CanonicalContextTarget = {
+ itemRefs?: GalleryItemRef[];
+ items: GalleryItem[];
+ x: number;
+ y: number;
+} | null;
const ContextMenuProbe = ({ target }: { target: CanonicalContextTarget }) => (
<output data-testid="context-target">
- {JSON.stringify(target?.items.map(({ kind, name }) => ({ kind, name })) ?? null)}
+ {JSON.stringify(
+ target
+ ? {
+ itemRefs: target.itemRefs ?? null,
+ items: target.items.map(({ kind, name }) => ({ kind, name })),
+ }
+ : null
+ )}
</output>
);
const NoopProvider = ({ children }: { children: ReactNode }) => children;
@@ -277,7 +310,13 @@ const DragMonitor = () => {
return null;
};
-const Harness = ({ gallery }: { gallery: GalleryStateView }) => {
+const Harness = ({
+ coMountPreviewSources = false,
+ gallery,
+}: {
+ coMountPreviewSources?: boolean;
+ gallery: GalleryStateView;
+}) => {
const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 6 } }));
const contextValue: GalleryWidgetContextValue = {
actions: createActions(),
@@ -297,6 +336,26 @@ const Harness = ({ gallery }: { gallery: GalleryStateView }) => {
<DndContext sensors={sensors}>
<DragMonitor />
<GalleryImageGrid layout="wide" />
+ {coMountPreviewSources ? (
+ <>
+ <PreviewFrame
+ dragItem={{ kind: 'image', name: 'shared' }}
+ frameHeight={96}
+ frameWidth={128}
+ isLive={false}
+ liveBadgeLabel="Generating"
+ shouldAntialiasLiveImage
+ source={previewSource}
+ variant="framed"
+ />
+ <PreviewFilmstrip
+ density="full"
+ images={[createPreviewImage('shared'), createPreviewImage('other.png')]}
+ selectedImageName="shared"
+ onSelect={noop}
+ />
+ </>
+ ) : null}
</DndContext>
</GalleryWidgetContext>
</GalleryUiProvider>
@@ -314,9 +373,9 @@ const interact = (action: () => void, delay = 0): Promise<void> =>
});
});
-const renderGallery = async (gallery = currentGallery) => {
+const renderGallery = async (gallery = currentGallery, coMountPreviewSources = false) => {
currentGallery = gallery;
- await interact(() => root?.render(<Harness gallery={gallery} />));
+ await interact(() => root?.render(<Harness coMountPreviewSources={coMountPreviewSources} gallery={gallery} />));
};
const getButton = (label: string): HTMLButtonElement => {
@@ -405,7 +464,7 @@ describe('GalleryImageGrid mixed item cells', () => {
expect(onDragStart).toHaveBeenCalledWith({
data: { items: [{ kind: 'video', name: 'shared' }], kind: 'gallery-item' },
- id: 'video:shared',
+ id: 'gallery-grid:video:shared',
});
// dnd-kit briefly suppresses the click following a completed drag. Let
@@ -413,6 +472,61 @@ describe('GalleryImageGrid mixed item cells', () => {
await interact(() => pointer('pointerup', videoButton.ownerDocument, 120, 80), 300);
});
+ it('preserves the ordered full selection when an unloaded video is dragged from a loaded image', async () => {
+ await renderGallery(
+ createGallery({
+ items: [createItem('image', 'loaded.png')],
+ selectedItemKey: 'image:loaded.png',
+ selectedItemKeys: ['image:loaded.png', 'video:unloaded.mp4'],
+ })
+ );
+ const imageButton = getButton('Select loaded.png for preview');
+
+ await interact(() => pointer('pointerdown', imageButton, 80, 80), 20);
+ await interact(() => pointer('pointermove', imageButton.ownerDocument, 120, 80), 50);
+
+ const drag = onDragStart.mock.calls[0]?.[0];
+ await interact(() => pointer('pointerup', imageButton.ownerDocument, 120, 80), 300);
+
+ expect(drag).toEqual({
+ data: {
+ items: [
+ { kind: 'image', name: 'loaded.png' },
+ { kind: 'video', name: 'unloaded.mp4' },
+ ],
+ kind: 'gallery-item',
+ },
+ id: 'gallery-grid:image:loaded.png',
+ });
+ expect(isGalleryImageDragData(drag?.data)).toBe(false);
+ });
+
+ it('keeps grid multi-selection data when preview sources for the same image are co-mounted', async () => {
+ await renderGallery(
+ createGallery({
+ items: [createItem('image', 'shared'), createItem('video', 'selected.mp4')],
+ selectedItemKey: 'image:shared',
+ selectedItemKeys: ['image:shared', 'video:selected.mp4'],
+ }),
+ true
+ );
+ const imageButton = getButton('Select shared for preview');
+
+ await interact(() => pointer('pointerdown', imageButton, 80, 80), 20);
+ await interact(() => pointer('pointermove', imageButton.ownerDocument, 120, 80), 50);
+
+ const drag = onDragStart.mock.calls[0]?.[0];
+ await interact(() => pointer('pointerup', imageButton.ownerDocument, 120, 80), 300);
+
+ expect(drag?.data).toEqual({
+ items: [
+ { kind: 'image', name: 'shared' },
+ { kind: 'video', name: 'selected.mp4' },
+ ],
+ kind: 'gallery-item',
+ });
+ });
+
it('keeps Alt comparison image-only and forms a one-video context target outside selection', async () => {
const image = createItem('image', 'first.png');
const video = createItem('video', 'clip.mp4', { durationSeconds: 2 });
@@ -439,7 +553,38 @@ describe('GalleryImageGrid mixed item cells', () => {
)
);
expect(host?.querySelector('[data-testid="context-target"]')?.textContent).toBe(
- JSON.stringify([{ kind: 'video', name: 'clip.mp4' }])
+ JSON.stringify({
+ itemRefs: [{ kind: 'video', name: 'clip.mp4' }],
+ items: [{ kind: 'video', name: 'clip.mp4' }],
+ })
+ );
+ });
+
+ it('retains an unloaded video ref when opening the context menu inside a mixed selection', async () => {
+ const image = createItem('image', 'loaded.png');
+ await renderGallery(
+ createGallery({
+ items: [image],
+ selectedItemKey: 'image:loaded.png',
+ selectedItemKeys: ['image:loaded.png', 'video:unloaded.mp4'],
+ })
+ );
+ const imageButton = getButton('Select loaded.png for preview');
+
+ await interact(() =>
+ imageButton.dispatchEvent(
+ new MouseEvent('contextmenu', { bubbles: true, cancelable: true, clientX: 23, clientY: 41 })
+ )
+ );
+
+ expect(host?.querySelector('[data-testid="context-target"]')?.textContent).toBe(
+ JSON.stringify({
+ itemRefs: [
+ { kind: 'image', name: 'loaded.png' },
+ { kind: 'video', name: 'unloaded.mp4' },
+ ],
+ items: [{ kind: 'image', name: 'loaded.png' }],
+ })
);
});
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.tsx
index 812525f426..fc6b0ca3bb 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.tsx
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.tsx
@@ -7,6 +7,7 @@ import { CSS } from '@dnd-kit/utilities';
import {
formatGalleryVideoDuration,
isGalleryImageItem,
+ parseGalleryItemKey,
toGalleryItemKey,
toGalleryItemRef,
} from '@features/gallery/core/items';
@@ -109,6 +110,7 @@ export const GalleryImageGrid = ({ layout }: { layout: 'stacked' | 'wide' }) =>
gallery.settings;
const columnCount = getGalleryColumnCount(imageDensityPercent, layout);
const selectedItemKeys = useMemo(() => new Set(gallery.selectedItemKeys), [gallery.selectedItemKeys]);
+ const selectedItemRefs = useMemo(() => gallery.selectedItemKeys.map(parseGalleryItemKey), [gallery.selectedItemKeys]);
const isFollowingLive = gallery.currentItem?.kind === 'placeholder';
const isComparisonActive =
gallery.selectedItemKey?.startsWith('image:') === true &&
@@ -335,6 +337,7 @@ export const GalleryImageGrid = ({ layout }: { layout: 'stacked' | 'wide' }) =>
const itemKey = toGalleryItemKey(item);
if (selectedItemKeys.has(itemKey) && selectedItemKeys.size > 1) {
+ const itemRefs = selectedItemRefs;
const selectionItems = [
item,
...gallery.items.filter(
@@ -342,13 +345,13 @@ export const GalleryImageGrid = ({ layout }: { layout: 'stacked' | 'wide' }) =>
),
];
- setContextMenuTarget({ items: selectionItems, x, y });
+ setContextMenuTarget({ itemRefs, items: selectionItems, x, y });
return;
}
- setContextMenuTarget({ items: [item], x, y });
+ setContextMenuTarget({ itemRefs: [toGalleryItemRef(item)], items: [item], x, y });
},
- [gallery.items, selectedItemKeys]
+ [gallery.items, selectedItemKeys, selectedItemRefs]
);
const getDragItems = useCallback(
@@ -356,14 +359,12 @@ export const GalleryImageGrid = ({ layout }: { layout: 'stacked' | 'wide' }) =>
const itemKey = toGalleryItemKey(item);
if (selectedItemKeys.has(itemKey) && selectedItemKeys.size > 1) {
- return gallery.items
- .filter((candidate) => selectedItemKeys.has(toGalleryItemKey(candidate)))
- .map(toGalleryItemRef);
+ return selectedItemRefs;
}
return [toGalleryItemRef(item)];
},
- [gallery.items, selectedItemKeys]
+ [selectedItemKeys, selectedItemRefs]
);
const handleDragEnter = useCallback((event: DragEvent) => {
@@ -769,7 +770,7 @@ const GalleryThumbnail = ({
const { isDragging, listeners, setNodeRef, transform } = useDraggable({
data: getGalleryItemDragData(dragItems),
- id: getGalleryItemDragId(toGalleryItemRef(item)),
+ id: getGalleryItemDragId(toGalleryItemRef(item), 'gallery-grid'),
});
const containerStyle = useMemo(() => ({ transform: CSS.Transform.toString(transform) }), [transform]);
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryUiContext.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryUiContext.tsx
index d4232c6260..c46ad1aeea 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryUiContext.tsx
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryUiContext.tsx
@@ -26,6 +26,7 @@ export interface GalleryImageActionsOptions {
}
export interface GalleryItemContextMenuTarget {
+ itemRefs: GalleryItemRef[];
items: GalleryItem[];
x: number;
y: number;
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/galleryDnd.test.ts b/invokeai/frontend/webv2/src/features/gallery/ui/galleryDnd.test.ts
index a4214779bd..62b85448bf 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/galleryDnd.test.ts
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/galleryDnd.test.ts
@@ -30,7 +30,7 @@ const createItem = (kind: GalleryItem['kind'], name: string, boardId: string): G
};
describe('galleryDnd', () => {
- it('constructs the shared item payload and uses qualified item keys as draggable ids', () => {
+ it('constructs the shared item payload and namespaces qualified draggable ids by source', () => {
const refs = [
{ kind: 'image', name: 'shared' },
{ kind: 'video', name: 'shared' },
@@ -40,8 +40,10 @@ describe('galleryDnd', () => {
items: refs,
kind: 'gallery-item',
});
- expect(getGalleryItemDragId(refs[0])).toBe('image:shared');
- expect(getGalleryItemDragId(refs[1])).toBe('video:shared');
+ expect(getGalleryItemDragId(refs[0], 'gallery-grid')).toBe('gallery-grid:image:shared');
+ expect(getGalleryItemDragId(refs[0], 'preview-frame')).toBe('preview-frame:image:shared');
+ expect(getGalleryItemDragId(refs[0], 'preview-filmstrip')).toBe('preview-filmstrip:image:shared');
+ expect(getGalleryItemDragId(refs[1], 'gallery-grid')).toBe('gallery-grid:video:shared');
});
it('recognizes only non-empty, well-formed gallery item payloads', () => {
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/galleryDnd.ts b/invokeai/frontend/webv2/src/features/gallery/ui/galleryDnd.ts
index 052f7b39e1..fb868da594 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/galleryDnd.ts
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/galleryDnd.ts
@@ -1,6 +1,7 @@
import type { GalleryItem, GalleryItemKey, GalleryItemRef } from '@features/gallery/core/items';
import type { GalleryBoardKind } from '@features/gallery/core/types';
+import { useDndContext, useDroppable, type UseDroppableArguments } from '@dnd-kit/core';
import { toGalleryItemKey } from '@features/gallery/core/items';
export interface GalleryItemDragData {
@@ -27,7 +28,11 @@ export interface GalleryBoardDropResolution {
items: GalleryItemRef[];
}
-export const getGalleryItemDragId = (item: GalleryItemRef): GalleryItemKey => toGalleryItemKey(item);
+export type GalleryItemDragSource = 'gallery-grid' | 'preview-filmstrip' | 'preview-frame';
+export type GalleryItemDragId = `${GalleryItemDragSource}:${GalleryItemKey}`;
+
+export const getGalleryItemDragId = (item: GalleryItemRef, source: GalleryItemDragSource): GalleryItemDragId =>
+ `${source}:${toGalleryItemKey(item)}`;
export const getGalleryBoardDropId = (boardId: string): string => `gallery-board:${boardId}`;
@@ -52,6 +57,14 @@ export const isGalleryItemDragData = (value: unknown): value is GalleryItemDragD
export const isGalleryImageDragData = (value: unknown): value is GalleryImageDragData =>
isGalleryItemDragData(value) && value.items.every((item): item is GalleryImageDragItem => item.kind === 'image');
+export const useGalleryImageDroppable = ({ disabled = false, ...args }: UseDroppableArguments) => {
+ const { active } = useDndContext();
+ const acceptsActiveDrag = isGalleryImageDragData(active?.data.current);
+ const droppable = useDroppable({ ...args, disabled: disabled || !acceptsActiveDrag });
+
+ return { ...droppable, isOver: acceptsActiveDrag && droppable.isOver };
+};
+
export const isGalleryBoardDropData = (value: unknown): value is GalleryBoardDropData =>
isRecord(value) &&
value.kind === 'gallery-board' &&
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/galleryImageDroppable.browser.test.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/galleryImageDroppable.browser.test.tsx
new file mode 100644
index 0000000000..9bd36c95ae
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/galleryImageDroppable.browser.test.tsx
@@ -0,0 +1,117 @@
+import { DndContext, PointerSensor, useDraggable, useSensor, useSensors } from '@dnd-kit/core';
+import { act } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import { afterEach, beforeEach, describe, expect, it } from 'vitest';
+
+import type { GalleryItemDragData } from './galleryDnd';
+
+import { getGalleryItemDragData, useGalleryImageDroppable } from './galleryDnd';
+
+const TARGET_IDS = [
+ 'upscale-input-image',
+ 'generate-reference-images',
+ 'regional-ref-image:layer-1:reference-1',
+] as const;
+const imageData = getGalleryItemDragData([{ kind: 'image', name: 'still.png' }]);
+const videoData = getGalleryItemDragData([{ kind: 'video', name: 'clip.mp4' }]);
+const mixedData = getGalleryItemDragData([
+ { kind: 'image', name: 'still.png' },
+ { kind: 'video', name: 'clip.mp4' },
+]);
+
+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 DragSource = ({ data }: { data: GalleryItemDragData }) => {
+ const { listeners, setNodeRef } = useDraggable({ data, id: 'test-gallery-source' });
+
+ return (
+ <button
+ ref={setNodeRef}
+ {...listeners}
+ data-testid="drag-source"
+ style={{ height: 80, left: 20, position: 'fixed', top: 20, touchAction: 'none', width: 80 }}
+ type="button"
+ />
+ );
+};
+
+const ImageDropTarget = ({ id }: { id: string }) => {
+ const { isOver, setNodeRef } = useGalleryImageDroppable({ data: { kind: id }, id });
+
+ return (
+ <output
+ ref={setNodeRef}
+ data-over={String(isOver)}
+ data-testid="drop-target"
+ style={{ height: 120, left: 300, position: 'fixed', top: 20, width: 120 }}
+ />
+ );
+};
+
+const Harness = ({ data, targetId }: { data: GalleryItemDragData; targetId: string }) => {
+ const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 6 } }));
+
+ return (
+ <DndContext sensors={sensors}>
+ <DragSource data={data} />
+ <ImageDropTarget id={targetId} />
+ </DndContext>
+ );
+};
+
+const interact = (action: () => void, delay = 50): Promise<void> =>
+ act(async () => {
+ action();
+ await new Promise<void>((resolve) => {
+ globalThis.setTimeout(resolve, delay);
+ });
+ });
+
+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 })
+ );
+};
+
+const dragOverTarget = async (data: GalleryItemDragData, targetId: string): Promise<string | null> => {
+ await interact(() => root?.render(<Harness data={data} targetId={targetId} />));
+ const source = host!.querySelector<HTMLElement>('[data-testid="drag-source"]')!;
+
+ await interact(() => pointer('pointerdown', source, 50, 50));
+ await interact(() => pointer('pointermove', source.ownerDocument, 90, 50));
+ await interact(() => pointer('pointermove', source.ownerDocument, 340, 60));
+
+ const isOver = host!.querySelector('[data-testid="drop-target"]')?.getAttribute('data-over') ?? null;
+ await interact(() => pointer('pointerup', source.ownerDocument, 340, 60));
+
+ return isOver;
+};
+
+beforeEach(() => {
+ host = document.createElement('div');
+ document.body.append(host);
+ root = createRoot(host);
+});
+
+afterEach(async () => {
+ await interact(() => root?.unmount(), 0);
+ host?.remove();
+ host = null;
+ root = null;
+});
+
+describe.each(TARGET_IDS)('%s image-only drop presentation', (targetId) => {
+ it('visually accepts an all-image gallery drag', async () => {
+ expect(await dragOverTarget(imageData, targetId)).toBe('true');
+ });
+
+ it('does not visually accept a video gallery drag', async () => {
+ expect(await dragOverTarget(videoData, targetId)).toBe('false');
+ });
+
+ it('does not visually accept a mixed gallery drag', async () => {
+ expect(await dragOverTarget(mixedData, targetId)).toBe('false');
+ });
+});
diff --git a/invokeai/frontend/webv2/src/features/gallery/utility.ts b/invokeai/frontend/webv2/src/features/gallery/utility.ts
index f7fb292acf..4eef91f783 100644
--- a/invokeai/frontend/webv2/src/features/gallery/utility.ts
+++ b/invokeai/frontend/webv2/src/features/gallery/utility.ts
@@ -8,11 +8,14 @@ export {
isGalleryImageDragData,
isGalleryItemDragData,
resolveGalleryBoardDrop,
+ useGalleryImageDroppable,
type GalleryBoardDropData,
type GalleryBoardDropResolution,
type GalleryImageDragData,
type GalleryImageDragItem,
type GalleryItemDragData,
+ type GalleryItemDragId,
+ type GalleryItemDragSource,
} from './ui/galleryDnd';
import { getGalleryImageFullUrl, getGalleryImageThumbnailUrl } from './data/imageUrls';
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/reference-images/GenerateReferenceImagesSection.tsx b/invokeai/frontend/webv2/src/features/generation/ui/reference-images/GenerateReferenceImagesSection.tsx
index 11bc77e4a1..f742d126d2 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/reference-images/GenerateReferenceImagesSection.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/reference-images/GenerateReferenceImagesSection.tsx
@@ -9,9 +9,9 @@ import type { GenerateSettingsUpdate } from '@features/generation/ui/generateDeb
import type { ChangeEvent } from 'react';
import { Badge, HStack, Input, Stack, Text } from '@chakra-ui/react';
-import { useDndMonitor, useDroppable } from '@dnd-kit/core';
+import { useDndMonitor } from '@dnd-kit/core';
import { galleryImages, galleryTransfers } from '@features/gallery';
-import { isGalleryImageDragData } from '@features/gallery/utility';
+import { isGalleryImageDragData, useGalleryImageDroppable } from '@features/gallery/utility';
import {
createReferenceImageId,
getDefaultReferenceImageConfig,
@@ -59,7 +59,7 @@ export const GenerateReferenceImagesSection = ({
const isSupported = isReferenceImageSupported(selectedModel);
const maxReferenceImages = getMaxReferenceImages(selectedModel);
const canAdd = referenceImages.length < maxReferenceImages;
- const { isOver, setNodeRef } = useDroppable({
+ const { isOver, setNodeRef } = useGalleryImageDroppable({
data: { kind: 'generate-reference-images' },
disabled: !canAdd,
id: 'generate-reference-images',
diff --git a/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleWidgetView.tsx b/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleWidgetView.tsx
index b121581316..0dd5443ec8 100644
--- a/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleWidgetView.tsx
+++ b/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleWidgetView.tsx
@@ -21,9 +21,9 @@ import {
Switch,
Text,
} from '@chakra-ui/react';
-import { useDndMonitor, useDroppable } from '@dnd-kit/core';
+import { useDndMonitor } from '@dnd-kit/core';
import { galleryImages, galleryTransfers } from '@features/gallery';
-import { galleryImageUrls, isGalleryImageDragData } from '@features/gallery/utility';
+import { galleryImageUrls, isGalleryImageDragData, useGalleryImageDroppable } from '@features/gallery/utility';
import { GenerationSettingsSection, NegativePromptField, PositivePromptField } from '@features/generation/components';
import {
SCHEDULER_OPTIONS,
@@ -337,9 +337,13 @@ const UpscaleImageField = ({
const { t } = useTranslation();
const { reportError, touchGalleryImages } = useUpscaleUi();
const fileInputRef = useRef<HTMLInputElement | null>(null);
- const { isOver, setNodeRef } = useDroppable({ data: { kind: DROP_ID }, id: DROP_ID });
const [isLoading, setIsLoading] = useState(false);
const [errorMessage, setErrorMessage] = useState<string | null>(null);
+ const { isOver, setNodeRef } = useGalleryImageDroppable({
+ data: { kind: DROP_ID },
+ disabled: isLoading,
+ id: DROP_ID,
+ });
const setGalleryImage = useCallback(
async (imageName: string) => {
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/RegionalGuidanceSettings.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/RegionalGuidanceSettings.tsx
index 7e55af3257..d15f6a7890 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/RegionalGuidanceSettings.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/RegionalGuidanceSettings.tsx
@@ -12,10 +12,10 @@ import type { CanvasStructuralEngine } from '@workbench/widgets/layers/layerOps'
import type { ChangeEvent, CSSProperties, FocusEvent } from 'react';
import { Box, createListCollection, HStack, IconButton, Input, Stack, Switch, Text } from '@chakra-ui/react';
-import { useDndMonitor, useDroppable } from '@dnd-kit/core';
+import { useDndMonitor } from '@dnd-kit/core';
import { galleryImages, galleryTransfers } from '@features/gallery';
import { invalidateGallery } from '@features/gallery/queries';
-import { isGalleryImageDragData } from '@features/gallery/utility';
+import { isGalleryImageDragData, useGalleryImageDroppable } from '@features/gallery/utility';
import { FluxReduxControls, PROMPT_ATTENTION_TARGET_PROPS, PromptTextarea } from '@features/generation/components';
import { useModelsSelector } from '@features/models';
import {
@@ -502,7 +502,10 @@ const ReferenceImageRow = ({
const { t } = useTranslation();
const { config } = referenceImage;
const fileInputRef = useRef<HTMLInputElement | null>(null);
- const { isOver, setNodeRef } = useDroppable({ data: { kind: 'regional-reference-image' }, id: dropId });
+ const { isOver, setNodeRef } = useGalleryImageDroppable({
+ data: { kind: 'regional-reference-image' },
+ id: dropId,
+ });
const replaceRef = useCallback(
(next: RegionalGuidanceReferenceImage) => {
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
index ccb90acf52..7242678b48 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewCompareDropZone.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewCompareDropZone.browser.test.tsx
@@ -46,7 +46,7 @@ const interact = (action: () => void): Promise<void> =>
const DraggableThumb = () => {
const { listeners, setNodeRef } = useDraggable({
data: getGalleryItemDragData([{ kind: 'image', name: 'dragged.png' }]),
- id: getGalleryItemDragId({ kind: 'image', name: 'dragged.png' }),
+ id: getGalleryItemDragId({ kind: 'image', name: 'dragged.png' }, 'gallery-grid'),
});
return (
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFilmstrip.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFilmstrip.tsx
index cdd4c2ee1d..79ea129893 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFilmstrip.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFilmstrip.tsx
@@ -86,7 +86,7 @@ const FilmstripThumb = ({
const dragData = useMemo(() => getGalleryItemDragData([{ kind: 'image', name: image.imageName }]), [image.imageName]);
const { listeners, setNodeRef } = useDraggable({
data: dragData,
- id: getGalleryItemDragId(dragData.items[0]!),
+ id: getGalleryItemDragId(dragData.items[0]!, 'preview-filmstrip'),
});
const handleClick = useCallback(() => onSelect(image), [image, onSelect]);
// Ref callbacks re-run when `isSelected` changes, keeping the selected thumb
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrame.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrame.tsx
index 3bc280c4c0..9e1bb6e80b 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrame.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrame.tsx
@@ -5,7 +5,7 @@ import type { StreamingImageSource } from '@platform/ui/streaming-image/streamin
import { Badge, Box, Flex, type SystemStyleObject } from '@chakra-ui/react';
import { useDraggable } from '@dnd-kit/core';
import { getGalleryItemDragData, getGalleryItemDragId } from '@features/gallery/utility';
-import { useCallback, useMemo, type CSSProperties, type MouseEvent, type ReactNode, type Ref } from 'react';
+import { useCallback, useId, useMemo, type CSSProperties, type MouseEvent, type ReactNode, type Ref } from 'react';
import { useTranslation } from 'react-i18next';
import { PreviewCompareDropZone } from './PreviewCompareDropZone';
@@ -76,6 +76,7 @@ export const PreviewFrame = ({
});
const dragData = useMemo(() => (dragItem ? getGalleryItemDragData([dragItem]) : undefined), [dragItem]);
const isDragDisabled = !dragItem || isLive || loupe.isZoomed;
+ const disabledDragId = useId();
const {
isDragging,
listeners,
@@ -83,7 +84,7 @@ export const PreviewFrame = ({
} = useDraggable({
data: dragData,
disabled: isDragDisabled,
- id: getGalleryItemDragId(dragItem ?? { kind: 'image', name: 'none' }),
+ id: dragItem ? getGalleryItemDragId(dragItem, 'preview-frame') : `preview-frame:disabled:${disabledDragId}`,
});
const setContentRef = useCallback(
(element: HTMLDivElement | null) => {