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(ui): animate the concept row menu out instead of unmounting it on close
Josh Corbett055c4392131c
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/shared/ConceptRow.browser.test.tsx b/invokeai/frontend/webv2/src/features/generation/ui/shared/ConceptRow.browser.test.tsxindex 30db872df6..8e38dfbebd 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/shared/ConceptRow.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/shared/ConceptRow.browser.test.tsx@@ -2,6 +2,7 @@ import type { GenerateLora } from '@features/generation/core/types';import { ChakraProvider } from '@chakra-ui/react';import { flushWorkbenchDrafts } from '@platform/react/draftRegistry';+import { closingFrames, recordDialogExit } from '@platform/ui/dialogExit.testing';import { system } from '@theme/system';import { act, Profiler, useCallback, useState } from 'react';import { createRoot, type Root } from 'react-dom/client';@@ -238,6 +239,21 @@ describe('ConceptRow', () => {expect(onRemove).toHaveBeenCalledWith('lora-1');});+ it('animates the row menu out with its actions instead of unmounting them on close', async () => {+ const row = await render(makeLora());+ await act(() => userEvent.click(row.querySelector<HTMLElement>('[data-list-primary]')!, { button: 'right' }));+ await expect.poll(menuLabels).toContain('widgets.generate.conceptMenu.remove');+ const menu = document.querySelector('[role="menu"]')!;++ const frames = closingFrames(await recordDialogExit(menu, () => act(() => userEvent.keyboard('{Escape}'))));+ await expect.poll(() => document.querySelector('[role="menu"]')).toBeNull();++ expect(frames).not.toHaveLength(0);+ for (const frame of frames) {+ expect(frame.text).toContain('widgets.generate.conceptMenu.remove');+ }+ });+it('does not open row actions on a pointer click', async () => {const row = await render(makeLora());diff --git a/invokeai/frontend/webv2/src/features/generation/ui/shared/ConceptRow.tsx b/invokeai/frontend/webv2/src/features/generation/ui/shared/ConceptRow.tsxindex baed69256d..ebc80d8506 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/shared/ConceptRow.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/shared/ConceptRow.tsx@@ -6,6 +6,7 @@ import { Avatar, Badge, Box, Flex, Icon, Menu, Portal } from '@chakra-ui/react';import { DEFAULT_LORA_WEIGHT_CONFIG, getDefaultLoraWeight } from '@features/generation/core/settings';import { useDebouncedDraftValue } from '@features/generation/ui/useDebouncedDraftValue';import { useRegisterDraftFlusher } from '@platform/react/draftRegistry';+import { useExitRetainedValue } from '@platform/react/useExitRetainedValue';import { IconButton } from '@platform/ui/Button';import { ListItem } from '@platform/ui/list/ListItem';import { ListStack } from '@platform/ui/list/ListStack';@@ -173,6 +174,8 @@ const ConceptRowContent = ({const isActive = lora.isEnabled && isCompatible;const defaultWeight = getDefaultLoraWeight(lora.model);const menu = useContextMenu();+ // Kept through the exit animation: the anchor clears the moment the menu closes.+ const { release: releaseMenu, value: shownAnchor } = useExitRetainedValue(menu.anchor);const handleToggle = useCallback((isEnabled: boolean) => onUpdate(key, { isEnabled }), [key, onUpdate]);const handleWeightChange = useCallback((weight: number) => onUpdate(key, { weight }), [key, onUpdate]);const removeFrom = useCallback(@@ -289,19 +292,21 @@ const ConceptRowContent = ({lazyMountopen={menu.anchor !== null}positioning={{- getAnchorRect: () => (menu.anchor ? { height: 1, width: 1, x: menu.anchor.x, y: menu.anchor.y } : null),+ getAnchorRect: () => (shownAnchor ? { height: 1, width: 1, x: shownAnchor.x, y: shownAnchor.y } : null),placement: 'bottom-start',}}unmountOnExit+ onExitComplete={releaseMenu}onOpenChange={(event) => {if (!event.open) {menu.close();}}}+ onRequestDismiss={menu.onRequestDismiss}><Portal><Menu.Positioner>- {menu.anchor ? (+ {shownAnchor ? (<MenuContent minW="12rem">{openInModelManager ? (<MenuActionItem@@ -333,7 +338,7 @@ const ConceptRowContent = ({label={t('widgets.generate.conceptMenu.remove')}tone="danger"value="remove"- onSelect={() => removeFrom(menu.anchor?.focusTarget?.() ?? null)}+ onSelect={() => removeFrom(shownAnchor.focusTarget?.() ?? null)}/></MenuContent>) : null}diff --git a/invokeai/frontend/webv2/src/features/generation/ui/shared/GenerateFieldContextMenu.tsx b/invokeai/frontend/webv2/src/features/generation/ui/shared/GenerateFieldContextMenu.tsxindex 0447c03aec..6ebf4e5f9c 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/shared/GenerateFieldContextMenu.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/shared/GenerateFieldContextMenu.tsx@@ -24,7 +24,7 @@ export const GenerateFieldContextMenu = ({resetLabel,}: GenerateFieldContextMenuProps) => {const { t } = useTranslation();- const { anchor: point, close, open } = useContextMenu();+ const { anchor: point, close, onRequestDismiss, open } = useContextMenu();return (<Box@@ -46,6 +46,7 @@ export const GenerateFieldContextMenu = ({close();}}}+ onRequestDismiss={onRequestDismiss}><Portal><Menu.Positioner>diff --git a/invokeai/frontend/webv2/src/platform/ui/Menu.tsx b/invokeai/frontend/webv2/src/platform/ui/Menu.tsxindex f22c6f5d97..47bc4ac2ed 100644--- a/invokeai/frontend/webv2/src/platform/ui/Menu.tsx+++ b/invokeai/frontend/webv2/src/platform/ui/Menu.tsx@@ -143,6 +143,13 @@ const activeMenu = createExternalStore<{ owner: string | null; anchor: ContextMeanchor: null,});+/**+ * Menus sharing this ownership replace one another; none is a parent of the next. The layer stack dismisses every+ * layer registered after one being torn down, so a menu that registers before its predecessor is gone (its content+ * still mounted from an exit animation) would be closed as if nested. Pass this as the menu root's `onRequestDismiss`.+ */+const keepOpenThroughSiblingTeardown = (event: Event) => event.preventDefault();+/** Row and field menus share ownership so a second right-click replaces the first menu. */export const useContextMenu = () => {const owner = useId();@@ -163,5 +170,5 @@ export const useContextMenu = () => {}});- return { anchor, close, open };+ return { anchor, close, onRequestDismiss: keepOpenThroughSiblingTeardown, open };};