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): resolve concepts panel merge conflicts

Josh Corbettb02f548532ea
diff --cc invokeai/frontend/webv2/public/locales/en.json
index 2d2d44f738,a536784bd7..67f22a4585
--- a/invokeai/frontend/webv2/public/locales/en.json
+++ b/invokeai/frontend/webv2/public/locales/en.json
@@@ -2240,14 -2234,9 +2240,15 @@@
"coherenceMinDenoise": "Coherence min denoise",
"maskBlur": "Mask blur"
},
+ "conceptMenu": {
+ "disable": "Disable",
+ "enable": "Enable",
+ "openInModelManager": "Open in Model Manager",
+ "remove": "Remove"
+ },
"conceptWeight": "{{name}} weight",
"concepts": "Concepts",
+ "conceptsUnsupported": "Concepts are not supported by the selected model.",
"copyValue": "Copy value",
"couldNotExpandPrompt": "Could not expand the prompt.",
"couldNotGeneratePromptFromImage": "Could not generate a prompt from the selected image.",
diff --cc invokeai/frontend/webv2/src/features/generation/ui/GenerateConceptsSection.browser.test.tsx
index b6cd0000b2,7cdfe6fe52..271537bc88
--- a/invokeai/frontend/webv2/src/features/generation/ui/GenerateConceptsSection.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/GenerateConceptsSection.browser.test.tsx
@@@ -1,13 -1,9 +1,14 @@@
-/* oxlint-disable react-perf/jsx-no-new-object-as-prop, react-perf/jsx-no-new-array-as-prop */
-import type { GenerateModelConfig, GenerateSettings, LoraModelConfig } from '@features/generation/core/types';
+import type {
+ GenerateLora,
+ GenerateModelConfig,
+ GenerateSettings,
+ LoraModelConfig,
+} from '@features/generation/core/types';
import { ChakraProvider } from '@chakra-ui/react';
+ import { seedArchitectureCapabilities } from '@features/generation/core/architectureCapabilities.testing';
import { getDefaultGenerateSettings } from '@features/generation/core/baseGenerationPolicies';
+import { flushGenerateDrafts } from '@features/generation/react';
import { system } from '@theme/system';
import { act } from 'react';
import { createRoot, type Root } from 'react-dom/client';
@@@ -18,66 -12,55 +19,72 @@@ import type { GenerateSettingsUpdate }
import { GenerateConceptsContent } from './GenerateConceptsSection';
import { GenerationUiProvider, type GenerationUiAdapter } from './GenerationUiContext';
- vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));
+ vi.mock('react-i18next', () => {
+ const t = (key: string) => key;
+ return { useTranslation: () => ({ i18n: { resolvedLanguage: 'en' }, t }) };
+ });
+
+ seedArchitectureCapabilities();
-(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
-const sdxl: GenerateModelConfig = { base: 'sdxl', key: 'sdxl', name: 'SDXL', type: 'main' };
-const sd3: GenerateModelConfig = { base: 'sd-3', key: 'sd3', name: 'SD3', type: 'main' };
-const inkLora: LoraModelConfig = { base: 'sdxl', key: 'ink', name: 'Ink', type: 'lora' };
-
-const adapter = {
+const LORA_MODEL: LoraModelConfig = { base: 'sdxl', key: 'lora-1', name: 'Ink Wash', type: 'lora' };
- const MAIN_MODEL = { base: 'sdxl', key: 'main-1', name: 'Base', type: 'main' } as GenerateModelConfig;
++const MAIN_MODEL: GenerateModelConfig = { base: 'sdxl', key: 'main-1', name: 'Base', type: 'main' };
++const SD3_MODEL: GenerateModelConfig = { base: 'sd-3', key: 'sd3', name: 'SD3', type: 'main' };
+const LORA_MODELS = [LORA_MODEL];
+const LORA: GenerateLora = { isEnabled: true, model: LORA_MODEL, weight: 0.75 };
+const SETTINGS: GenerateSettings = { ...getDefaultGenerateSettings(), loras: [LORA] };
+const ADAPTER = {
models: {
- ModelSelect: () => null,
+ ModelSelect: () => <div data-testid="concept-picker" />,
getBaseColorPalette: () => 'gray',
getBaseLabel: (base: string) => base,
+ getImageUrl: () => '',
},
} as unknown as GenerationUiAdapter;
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 render = async () => {
-const renderConcepts = async (selectedModel: GenerateModelConfig, loras: GenerateSettings['loras']) => {
++const render = async (selectedModel: GenerateModelConfig = MAIN_MODEL, settings = SETTINGS) => {
+ const onCommit = vi.fn<(update: GenerateSettingsUpdate) => void>();
const onCommitImmediate = vi.fn();
host = document.createElement('div');
document.body.append(host);
root = createRoot(host);
- await act(() => {
- root?.render(
- <ChakraProvider value={system}>
- <GenerationUiProvider adapter={adapter}>
- <GenerateConceptsContent
- loraModels={[inkLora]}
- projectId="project-1"
- selectedModel={selectedModel}
- settings={{ ...getDefaultGenerateSettings(sdxl as never), loras }}
- onCommit={vi.fn()}
- onCommitImmediate={onCommitImmediate}
- />
- </GenerationUiProvider>
- </ChakraProvider>
+ const renderProject = (projectId: string) =>
+ act(() =>
+ root?.render(
+ <ChakraProvider value={system}>
+ <GenerationUiProvider adapter={ADAPTER}>
+ <GenerateConceptsContent
+ loraModels={LORA_MODELS}
+ projectId={projectId}
- selectedModel={MAIN_MODEL}
- settings={SETTINGS}
++ selectedModel={selectedModel}
++ settings={settings}
+ onCommit={onCommit}
+ onCommitImmediate={onCommitImmediate}
+ />
+ </GenerationUiProvider>
+ </ChakraProvider>
+ )
);
- });
+ await renderProject('project-1');
- return { host, onCommitImmediate };
+ return { onCommit, onCommitImmediate, renderProject, row: host };
};
+/** The settings a recorded commit produces from the rendered ones. */
+const applied = (update: GenerateSettingsUpdate | undefined): GenerateLora | undefined =>
+ (typeof update === 'function' ? update(SETTINGS) : { ...SETTINGS, ...update }).loras[0];
+
+const stepWeight = (row: HTMLElement) =>
+ act(() => {
+ row
+ .querySelector('[role="slider"]')
+ ?.dispatchEvent(new KeyboardEvent('keydown', { bubbles: true, key: 'ArrowRight' }));
+ });
+
afterEach(async () => {
await act(() => root?.unmount());
host?.remove();
@@@ -86,54 -69,42 +93,96 @@@
});
describe('GenerateConceptsContent', () => {
+ it('discards a concept menu when switching projects with the same concept', async () => {
+ const { onCommit, onCommitImmediate, renderProject, row } = await render();
+
+ await act(() => {
+ row
+ .querySelector('[data-list-primary]')
+ ?.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, cancelable: true }));
+ });
+ await expect.poll(() => document.querySelector('[role="menu"][data-state="open"]')).not.toBeNull();
+
+ await renderProject('project-2');
+
+ expect(document.querySelector('[role="menu"][data-state="open"]')).toBeNull();
+ await renderProject('project-1');
+ expect(document.querySelector('[role="menu"][data-state="open"]')).toBeNull();
+ expect(onCommit).not.toHaveBeenCalled();
+ expect(onCommitImmediate).not.toHaveBeenCalled();
+ });
+
+ it('holds weight steps as a draft and commits them once the debounce settles', async () => {
+ const { onCommit, row } = await render();
+
+ await stepWeight(row);
+ await stepWeight(row);
+
+ expect(row.querySelector('[role="slider"]')?.getAttribute('aria-valuenow')).toBe('0.85');
+ expect(onCommit).not.toHaveBeenCalled();
+
+ await expect.poll(() => onCommit.mock.calls.length, { timeout: 1000 }).toBe(1);
+ expect(applied(onCommit.mock.calls[0]?.[0])?.weight).toBe(0.85);
+ });
+
+ it('commits a pending weight when drafts are flushed', async () => {
+ const { onCommit, row } = await render();
+
+ await stepWeight(row);
+ act(() => flushGenerateDrafts());
+
+ expect(onCommit).toHaveBeenCalledTimes(1);
+ expect(applied(onCommit.mock.calls[0]?.[0])?.weight).toBe(0.8);
+ });
+
+ it('commits toggles immediately rather than through the weight draft', async () => {
+ const { onCommit, row } = await render();
+
+ await act(() => row.querySelector<HTMLElement>('[data-scope="switch"][data-part="control"]')?.click());
+
+ expect(onCommit).toHaveBeenCalledTimes(1);
+ expect(applied(onCommit.mock.calls[0]?.[0])).toMatchObject({ isEnabled: false, weight: 0.75 });
+ });
++
+ it('offers the concept picker for a model family that loads LoRAs', async () => {
- const { host } = await renderConcepts(sdxl, []);
++ const { row } = await render(MAIN_MODEL, { ...SETTINGS, loras: [] });
+
- expect(host.querySelector('[data-testid="concept-picker"]')).not.toBeNull();
- expect(host.textContent).toContain('widgets.generate.addConceptsHelp');
- expect(host.textContent).not.toContain('widgets.generate.conceptsUnsupported');
++ expect(row.querySelector('[data-testid="concept-picker"]')).not.toBeNull();
++ expect(row.textContent).toContain('widgets.generate.addConceptsHelp');
++ expect(row.textContent).not.toContain('widgets.generate.conceptsUnsupported');
+ });
+
+ it('explains instead of offering an always-empty picker when the model cannot use concepts', async () => {
- const { host } = await renderConcepts(sd3, []);
++ const { row } = await render(SD3_MODEL, { ...SETTINGS, loras: [] });
+
- expect(host.querySelector('[data-testid="concept-picker"]')).toBeNull();
- expect(host.textContent).toContain('widgets.generate.conceptsUnsupported');
- expect(host.textContent).not.toContain('widgets.generate.addConceptsHelp');
++ expect(row.querySelector('[data-testid="concept-picker"]')).toBeNull();
++ expect(row.textContent).toContain('widgets.generate.conceptsUnsupported');
++ expect(row.textContent).not.toContain('widgets.generate.addConceptsHelp');
+ });
+
+ it('keeps concepts from another model removable when the model cannot use concepts', async () => {
- const { host, onCommitImmediate } = await renderConcepts(sd3, [{ isEnabled: true, model: inkLora, weight: 0.8 }]);
++ const { row, onCommitImmediate } = await render(SD3_MODEL);
+
- expect(host.textContent).toContain('Ink');
- expect(host.textContent).toContain('widgets.generate.incompatible');
++ expect(row.textContent).toContain('Ink Wash');
++ expect(row.textContent).toContain('widgets.generate.incompatible');
+
- const remove = host.querySelector<HTMLButtonElement>('button[aria-label="widgets.generate.removeConceptNamed"]');
++ const remove = row.querySelector<HTMLButtonElement>('button[aria-label="widgets.generate.removeConceptNamed"]');
+
+ expect(remove).not.toBeNull();
+ await act(() => {
+ remove?.click();
+ });
+
+ expect(onCommitImmediate).toHaveBeenCalledWith({ loras: [] });
+ });
+
+ it('marks a same-family concept incompatible when the model cannot use concepts', async () => {
+ const sd3Lora: LoraModelConfig = { base: 'sd-3', key: 'sd3-lora', name: 'Glow', type: 'lora' };
- const { host } = await renderConcepts(sd3, [{ isEnabled: true, model: sd3Lora, weight: 0.8 }]);
++ const { row } = await render(SD3_MODEL, {
++ ...SETTINGS,
++ loras: [{ isEnabled: true, model: sd3Lora, weight: 0.8 }],
++ });
+
- expect(host.textContent).toContain('widgets.generate.incompatible');
++ expect(row.textContent).toContain('widgets.generate.incompatible');
+ });
});
diff --cc invokeai/frontend/webv2/src/features/generation/ui/GenerateConceptsSection.tsx
index c6d18c22e9,74c983502e..2ea540dfc7
--- a/invokeai/frontend/webv2/src/features/generation/ui/GenerateConceptsSection.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/GenerateConceptsSection.tsx
@@@ -7,8 -7,10 +7,9 @@@ import type
LoraModelConfig,
} from '@features/generation/core/types';
-import { Badge, HStack, Stack, Text } from '@chakra-ui/react';
+import { Box, Stack, Text } from '@chakra-ui/react';
+ import { isLoraSupported } from '@features/generation/core/baseGenerationPolicies';
import {
- DEFAULT_LORA_WEIGHT_CONFIG,
getDefaultLoraWeight,
isLoraCompatibleWithModel,
isLoraModelConfig,
@@@ -34,10 -40,12 +35,11 @@@ interface GenerateConceptsContentProps
onCommitImmediate: (patch: Partial<GenerateSettings>) => void;
}
-const LORA_WEIGHT_MARKS = [-1, 0, 1, 2];
const LORA_WEIGHT_DEBOUNCE_MS = 250;
- const isCompatibleLora = (lora: GenerateLora, selectedModel: GenerateModelConfig | undefined): boolean =>
- Boolean(selectedModel && isLoraCompatibleWithModel(lora.model, selectedModel));
+ /** Whether the selected model's graph will load this concept: its family must take LoRAs and match the LoRA. */
+ export const isCompatibleLora = (lora: GenerateLora, selectedModel: GenerateModelConfig | undefined): boolean =>
+ Boolean(selectedModel && isLoraSupported(selectedModel) && isLoraCompatibleWithModel(lora.model, selectedModel));
export const GenerateConceptsContent = ({
loraModels,
@@@ -81,6 -89,35 +83,36 @@@
onCommitImmediate({ loras: loras.filter((lora) => lora.model.key !== modelKey) });
};
+ const rows =
+ loras.length > 0 ? (
- <Stack gap="2">
- {loras.map((lora) => (
- <LoraRow
- key={lora.model.key}
- isCompatible={isCompatibleLora(lora, selectedModel)}
- lora={lora}
- projectId={projectId}
- onRemove={() => removeLora(lora.model.key)}
- onToggle={(isEnabled) => updateLora(lora.model.key, { isEnabled })}
- onWeightChange={(weight) => updateLora(lora.model.key, { weight })}
- />
- ))}
- </Stack>
++ <Box mx={-1}>
++ <ConceptList label={t('widgets.generate.concepts')} projectId={projectId}>
++ {loras.map((lora) => (
++ <GenerateConceptRow
++ key={lora.model.key}
++ isCompatible={isCompatibleLora(lora, selectedModel)}
++ lora={lora}
++ projectId={projectId}
++ onRemove={removeLora}
++ onUpdate={updateLora}
++ />
++ ))}
++ </ConceptList>
++ </Box>
+ ) : null;
+
+ if (selectedModel && !isLoraSupported(selectedModel)) {
+ // Rows left from another model stay listed, marked incompatible, so they can still be removed.
+ return (
+ <Stack gap="2">
- <Text color="fg.muted" fontSize="2xs">
++ <Text color="fg.muted" fontSize="xs">
+ {t('widgets.generate.conceptsUnsupported')}
+ </Text>
+ {rows}
+ </Stack>
+ );
+ }
+
return (
<Stack gap="2">
<Field
@@@ -103,25 -140,10 +135,10 @@@
/>
</Field>
- {loras.length === 0 ? (
+ {rows ?? (
- <Text color="fg.muted" fontSize="2xs">
+ <Text color="fg.muted" fontSize="xs">
{t('widgets.generate.addConceptsHelp')}
</Text>
- ) : (
- <Box mx={-1}>
- <ConceptList label={t('widgets.generate.concepts')} projectId={projectId}>
- {loras.map((lora) => (
- <GenerateConceptRow
- key={lora.model.key}
- isCompatible={isCompatibleLora(lora, selectedModel)}
- lora={lora}
- projectId={projectId}
- onRemove={removeLora}
- onUpdate={updateLora}
- />
- ))}
- </ConceptList>
- </Box>
)}
</Stack>
);