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(generation): share concept list rules across generate, video and upscale (#9937)

Josh Corbettccea9c9da7a1
diff --git a/invokeai/frontend/webv2/performance/browser-baseline.json b/invokeai/frontend/webv2/performance/browser-baseline.json
index ac6d601e26..a39c5f61d0 100644
--- a/invokeai/frontend/webv2/performance/browser-baseline.json
+++ b/invokeai/frontend/webv2/performance/browser-baseline.json
@@ -980,6 +980,7 @@
"source:src/features/generation/core/canvas/controlValidation.ts",
"source:src/features/generation/core/catalogSearch.ts",
"source:src/features/generation/core/componentCompatibility.ts",
+ "source:src/features/generation/core/conceptList.ts",
"source:src/features/generation/core/conditioningRebalance.ts",
"source:src/features/generation/core/dimensionLimits.ts",
"source:src/features/generation/core/dynamicPrompts.ts",
@@ -2086,6 +2087,7 @@
"source:src/features/generation/core/canvas/controlValidation.ts",
"source:src/features/generation/core/catalogSearch.ts",
"source:src/features/generation/core/componentCompatibility.ts",
+ "source:src/features/generation/core/conceptList.ts",
"source:src/features/generation/core/conditioningRebalance.ts",
"source:src/features/generation/core/dimensionLimits.ts",
"source:src/features/generation/core/dynamicPrompts.ts",
@@ -3353,6 +3355,7 @@
"source:src/features/generation/core/canvas/controlValidation.ts",
"source:src/features/generation/core/catalogSearch.ts",
"source:src/features/generation/core/componentCompatibility.ts",
+ "source:src/features/generation/core/conceptList.ts",
"source:src/features/generation/core/conditioningRebalance.ts",
"source:src/features/generation/core/dimensionLimits.ts",
"source:src/features/generation/core/dynamicPrompts.ts",
diff --git a/invokeai/frontend/webv2/src/app/ConceptDraftCommits.browser.test.tsx b/invokeai/frontend/webv2/src/app/ConceptDraftCommits.browser.test.tsx
index 52173f9960..ecbcdd3cc9 100644
--- a/invokeai/frontend/webv2/src/app/ConceptDraftCommits.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/app/ConceptDraftCommits.browser.test.tsx
@@ -43,9 +43,12 @@ const models = [
model('upscale-main', 'sdxl', 'main'),
model('upscale-first', 'sdxl', 'lora', 'Upscale Ink Wash'),
model('upscale-second', 'sdxl', 'lora', 'Upscale Detail'),
+ // Not listed by `render`: only offered through the concept picker.
+ model('picked-video', 'minimax-h3', 'lora'),
+ model('picked-upscale', 'sdxl', 'lora'),
];
const modelSnapshot = { models, status: 'loaded' };
-const { notify } = vi.hoisted(() => ({ notify: vi.fn() }));
+const { notify, picker } = vi.hoisted(() => ({ notify: vi.fn(), picker: { pick: null as unknown } }));
const noop = () => undefined;
const generationAdapter = {
sectionPreferences: { sectionsOpen: {}, setSectionOpen: noop },
@@ -73,9 +76,18 @@ vi.mock('@features/models', async (importOriginal) => ({
useOpenModelInManager: () => undefined,
}));
// Picker transport and prompt suggestions are unrelated to concept commits; retain the real list, rows, and controls.
+// The concept picker hands over `picker.pick` unfiltered, as a stale picker would.
vi.mock('@features/models/react', async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
- ModelSelect: () => null,
+ ModelSelect: ({ modelTypes, onChange }: { modelTypes?: readonly string[]; onChange: (model: unknown) => void }) =>
+ modelTypes?.includes('lora') ? (
+ <button
+ aria-label="Add concept"
+ data-testid="concept-picker"
+ type="button"
+ onClick={() => onChange(picker.pick)}
+ />
+ ) : null,
}));
vi.mock('@features/gallery/mediaSlot', async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
@@ -110,7 +122,7 @@ const currentLoras = (widget: Widget): GenerateLora[] =>
const render = async (widget: Widget) => {
const loras = models
- .filter((candidate) => candidate.type === 'lora' && candidate.key.startsWith(widget))
+ .filter((candidate) => candidate.type === 'lora' && candidate.key.startsWith(`${widget}-`))
.map((candidate, index) => ({ isEnabled: true, model: candidate, weight: index === 0 ? 0.75 : 0.5 }));
const defaults =
widget === 'video' ? createDefaultVideoWidgetValues(models) : createDefaultUpscaleWidgetValues(models);
@@ -199,36 +211,31 @@ describe('concept drafts through widget adapters', () => {
}
);
- it.each(['upscale', 'video'] as const)(
- 'does not restore a removed %s concept when another draft flushes',
- async (widget) => {
- const rows = await render(widget);
- await act(() => step(rows[1]!));
- await act(() => {
- rows[0]!.querySelector<HTMLButtonElement>('[aria-label="widgets.generate.removeConceptNamed"]')?.click();
- flushWorkbenchDrafts();
- });
+ it('applies the accelerator rule when a video concept is removed beside a pending draft', async () => {
+ const rows = await render('video');
+ await act(() => step(rows[1]!));
+ await act(() => {
+ rows[0]!.querySelector<HTMLButtonElement>('[aria-label="widgets.generate.removeConceptNamed"]')?.click();
+ flushWorkbenchDrafts();
+ });
- expect(currentLoras(widget).map((lora) => ({ key: lora.model.key, weight: lora.weight }))).toEqual([
- { key: `${widget}-second`, weight: 0.55 },
- ]);
- if (widget === 'video') {
- expect(getProjectWidgetValues(store.getSnapshot().activeProject, widget)).toMatchObject({
- acceleratorEnabled: false,
- acceleratorLoraKeys: [],
- steps: 50,
- });
- expect(notify).toHaveBeenCalledExactlyOnceWith({
- description: 'widgets.video.acceleratorBrokenDescription',
- title: 'widgets.video.acceleratorBroken',
- type: 'info',
- });
- }
- }
- );
+ expect(currentLoras('video').map((lora) => ({ key: lora.model.key, weight: lora.weight }))).toEqual([
+ { key: 'video-second', weight: 0.55 },
+ ]);
+ expect(getProjectWidgetValues(store.getSnapshot().activeProject, 'video')).toMatchObject({
+ acceleratorEnabled: false,
+ acceleratorLoraKeys: [],
+ steps: 50,
+ });
+ expect(notify).toHaveBeenCalledExactlyOnceWith({
+ description: 'widgets.video.acceleratorBrokenDescription',
+ title: 'widgets.video.acceleratorBroken',
+ type: 'info',
+ });
+ });
it.each(['upscale', 'video'] as const)(
- 'writes only the removal when a %s row is removed with its own pending weight',
+ 'writes only the removal when a %s row is double-clicked away with its own pending weight',
async (widget) => {
const rows = await render(widget);
await act(() => step(rows[0]!));
@@ -236,7 +243,9 @@ describe('concept drafts through widget adapters', () => {
const unsubscribe = store.subscribe(() => projects.add(store.getSnapshot().activeProject));
await act(() => {
- rows[0]!.querySelector<HTMLButtonElement>('[aria-label="widgets.generate.removeConceptNamed"]')?.click();
+ const remove = rows[0]!.querySelector<HTMLButtonElement>('[aria-label="widgets.generate.removeConceptNamed"]');
+ remove?.click();
+ remove?.click();
});
await act(() => flushWorkbenchDrafts());
unsubscribe();
@@ -245,4 +254,32 @@ describe('concept drafts through widget adapters', () => {
expect(currentLoras(widget).map((lora) => lora.model.key)).toEqual([`${widget}-second`]);
}
);
+
+ it.each([
+ ['upscale', 'picked-upscale', 'picked-video'],
+ ['video', 'picked-video', 'picked-upscale'],
+ ] as const)(
+ 'adds a picked %s concept once, and only when its model can load it',
+ async (widget, compatible, incompatible) => {
+ await render(widget);
+ const pick = (key: string) =>
+ act(() => {
+ picker.pick = models.find((candidate) => candidate.key === key);
+ host.querySelector<HTMLButtonElement>('[data-testid="concept-picker"]')?.click();
+ });
+
+ await pick(compatible);
+ expect(currentLoras(widget).map((lora) => [lora.model.key, lora.weight])).toEqual([
+ [`${widget}-first`, 0.75],
+ [`${widget}-second`, 0.5],
+ [compatible, 0.75],
+ ]);
+
+ const project = store.getSnapshot().activeProject;
+ await pick(compatible);
+ await pick(`${widget}-first`);
+ await pick(incompatible);
+ expect(store.getSnapshot().activeProject).toBe(project);
+ }
+ );
});
diff --git a/invokeai/frontend/webv2/src/features/generation/components.ts b/invokeai/frontend/webv2/src/features/generation/components.ts
index 26f011e3c4..b101986f9c 100644
--- a/invokeai/frontend/webv2/src/features/generation/components.ts
+++ b/invokeai/frontend/webv2/src/features/generation/components.ts
@@ -11,10 +11,6 @@ export { SeedField, type SeedFieldProps } from './ui/shared/SeedField';
export { FluxReduxControls } from './ui/reference-images/ReferenceImageControls';
export { GenerateCollapsibleSection as GenerationSettingsSection } from './ui/shared/GenerateCollapsibleSection';
export { CapabilitiesGate, type CapabilitiesGateProps } from './ui/shared/CapabilitiesGate';
-export {
- ConceptList,
- ConceptRow,
- type ConceptModelPort,
- type ConceptRowProps,
- type ConceptUpdate,
-} from './ui/shared/ConceptRow';
+export { ConceptList, ConceptRow, type ConceptModelPort, type ConceptRowProps } from './ui/shared/ConceptRow';
+// Only lazy widget UIs edit concept lists; exporting it from `settings` would put it in the editor's startup graph.
+export { addConcept, removeConcept, type ConceptUpdate, updateConcept } from './core/conceptList';
diff --git a/invokeai/frontend/webv2/src/features/generation/core/conceptList.test.ts b/invokeai/frontend/webv2/src/features/generation/core/conceptList.test.ts
new file mode 100644
index 0000000000..6e25125e2c
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/generation/core/conceptList.test.ts
@@ -0,0 +1,129 @@
+import { describe, expect, it } from 'vitest';
+
+import type { GenerateLora, GenerateModelConfig, LoraModelConfig } from './types';
+
+import { addConcept, type ConceptUpdate, removeConcept, updateConcept } from './conceptList';
+
+const lora = (key: string, base = 'sdxl', extra: Partial<LoraModelConfig> = {}): LoraModelConfig => ({
+ base,
+ key,
+ name: key,
+ type: 'lora',
+ ...extra,
+});
+
+const SDXL: GenerateModelConfig = { base: 'sdxl', key: 'sdxl-main', name: 'SDXL', type: 'main' };
+const INK = lora('ink');
+const CHALK = lora('chalk');
+const LIST: GenerateLora[] = [
+ { isEnabled: true, model: INK, weight: 0.5 },
+ { isEnabled: false, model: CHALK, weight: 1.25 },
+];
+
+describe('addConcept', () => {
+ it.each([
+ ['a compatible concept at the default weight', lora('glow'), 0.75],
+ [
+ 'a compatible concept at its own default weight',
+ lora('glow', 'sdxl', { default_settings: { weight: 1.4 } }),
+ 1.4,
+ ],
+ ])('appends %s, enabled', (_, model, weight) => {
+ expect(addConcept(LIST, model, SDXL)).toEqual([...LIST, { isEnabled: true, model, weight }]);
+ });
+
+ it.each([
+ ['is already listed', lora('chalk', 'sdxl', { name: 'Chalk renamed' }), SDXL],
+ ['belongs to another family', lora('glow', 'sd-1'), SDXL],
+ ['has no main model to load it', lora('glow'), null],
+ ])('leaves the list unchanged when the concept %s', (_, model, mainModel) => {
+ expect(addConcept(LIST, model, mainModel)).toBe(LIST);
+ });
+
+ it('checks Wan LoRA variants against the main model in the correct direction', () => {
+ const model = lora('wan-5b', 'wan', { variant: '5b' });
+ const mainModel: GenerateModelConfig = {
+ base: 'wan',
+ key: 'wan-main',
+ name: 'Wan',
+ type: 'main',
+ variant: 't2v_a14b',
+ };
+
+ expect(addConcept(LIST, model, mainModel)).toBe(LIST);
+ expect(addConcept(LIST, model, { ...mainModel, variant: 'ti2v_5b' })).toEqual([
+ ...LIST,
+ { isEnabled: true, model, weight: 0.75 },
+ ]);
+ });
+
+ it('supports compatible video concepts outside the Generate model families', () => {
+ const model = lora('minimax-lora', 'minimax-h3');
+ const mainModel: GenerateModelConfig = {
+ base: 'minimax-h3',
+ key: 'minimax-main',
+ name: 'MiniMax',
+ type: 'main',
+ };
+
+ expect(addConcept(LIST, model, mainModel)).toEqual([...LIST, { isEnabled: true, model, weight: 0.75 }]);
+ });
+});
+
+describe('updateConcept', () => {
+ it.each<[string, ConceptUpdate, GenerateLora]>([
+ ['weight', { weight: 0.9 }, { isEnabled: false, model: CHALK, weight: 0.9 }],
+ ['enabled state', { isEnabled: true }, { isEnabled: true, model: CHALK, weight: 1.25 }],
+ ['both fields', { isEnabled: true, weight: -1 }, { isEnabled: true, model: CHALK, weight: -1 }],
+ ])('changes only the matching row’s %s', (_, update, expected) => {
+ const next = updateConcept(LIST, 'chalk', update);
+
+ expect(next).toEqual([LIST[0], expected]);
+ expect(next[0]).toBe(LIST[0]);
+ });
+
+ it.each<[string, string, ConceptUpdate]>([
+ ['the row was removed', 'gone', { weight: 0.9 }],
+ ['the values already match', 'chalk', { isEnabled: false, weight: 1.25 }],
+ ['the update is empty', 'ink', {}],
+ ])('leaves the list unchanged when %s', (_, key, update) => {
+ expect(updateConcept(LIST, key, update)).toBe(LIST);
+ });
+
+ it('updates every matching key in a loaded list without removing duplicate rows', () => {
+ const list = [...LIST, { isEnabled: true, model: CHALK, weight: -0.5 }];
+ const next = updateConcept(list, 'chalk', { isEnabled: false, weight: 0.9 });
+
+ expect(next).toEqual([
+ LIST[0],
+ { isEnabled: false, model: CHALK, weight: 0.9 },
+ { isEnabled: false, model: CHALK, weight: 0.9 },
+ ]);
+ expect(next[0]).toBe(list[0]);
+ });
+
+ it('updates a later duplicate when the first matching row already has the requested values', () => {
+ const list = [...LIST, { isEnabled: true, model: CHALK, weight: -0.5 }];
+ const next = updateConcept(list, 'chalk', { isEnabled: false, weight: 1.25 });
+
+ expect(next).toEqual([...LIST, { isEnabled: false, model: CHALK, weight: 1.25 }]);
+ expect(next[0]).toBe(list[0]);
+ expect(next[1]).toBe(list[1]);
+ });
+
+ it('leaves a duplicate-key list unchanged when all matching rows already match', () => {
+ const list = [...LIST, { isEnabled: false, model: CHALK, weight: 1.25 }];
+
+ expect(updateConcept(list, 'chalk', { isEnabled: false, weight: 1.25 })).toBe(list);
+ });
+});
+
+describe('removeConcept', () => {
+ it('drops the matching row', () => {
+ expect(removeConcept(LIST, 'ink')).toEqual([LIST[1]]);
+ });
+
+ it('leaves the list unchanged when the row is already gone', () => {
+ expect(removeConcept(LIST, 'gone')).toBe(LIST);
+ });
+});
diff --git a/invokeai/frontend/webv2/src/features/generation/core/conceptList.ts b/invokeai/frontend/webv2/src/features/generation/core/conceptList.ts
new file mode 100644
index 0000000000..a822815e54
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/generation/core/conceptList.ts
@@ -0,0 +1,45 @@
+import type { GenerateLora, GenerateModelConfig, LoraModelConfig } from './types';
+
+import { getDefaultLoraWeight, isLoraCompatibleWithModel } from './settings';
+
+/**
+ * Concept (LoRA) list edits shared by every widget that stores a `GenerateLora[]`. Adds prevent new duplicate keys
+ * and only add concepts the main model can load. An edit that changes nothing returns the same array,
+ * so callers can skip the write: a row removed mid-edit still flushes its draft, and that must stay a no-op.
+ */
+
+export type ConceptUpdate = Partial<Pick<GenerateLora, 'isEnabled' | 'weight'>>;
+
+/** Appends an enabled concept at its default weight unless it is already listed or `mainModel` cannot load it. */
+export const addConcept = (
+ loras: GenerateLora[],
+ model: LoraModelConfig,
+ mainModel: Pick<GenerateModelConfig, 'base' | 'variant'> | null | undefined
+): GenerateLora[] =>
+ !mainModel || !isLoraCompatibleWithModel(model, mainModel) || loras.some((lora) => lora.model.key === model.key)
+ ? loras
+ : [...loras, { isEnabled: true, model, weight: getDefaultLoraWeight(model) }];
+
+export const updateConcept = (loras: GenerateLora[], key: string, update: ConceptUpdate): GenerateLora[] => {
+ let didUpdate = false;
+ const next = loras.map((lora) => {
+ if (
+ lora.model.key !== key ||
+ ((update.isEnabled === undefined || update.isEnabled === lora.isEnabled) &&
+ (update.weight === undefined || update.weight === lora.weight))
+ ) {
+ return lora;
+ }
+
+ didUpdate = true;
+ return { ...lora, ...update };
+ });
+
+ return didUpdate ? next : loras;
+};
+
+export const removeConcept = (loras: GenerateLora[], key: string): GenerateLora[] => {
+ const next = loras.filter((lora) => lora.model.key !== key);
+
+ return next.length === loras.length ? loras : next;
+};
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/GenerateConceptsSection.browser.test.tsx b/invokeai/frontend/webv2/src/features/generation/ui/GenerateConceptsSection.browser.test.tsx
index f3df759e2b..97dd8c9269 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/GenerateConceptsSection.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/GenerateConceptsSection.browser.test.tsx
@@ -134,6 +134,16 @@ describe('GenerateConceptsContent', () => {
]);
});
+ it('ignores a picked concept the selected model cannot load', async () => {
+ const fluxModel: GenerateModelConfig = { base: 'flux', key: 'flux', name: 'FLUX', type: 'main' };
+ const { onCommit, row } = await render(fluxModel);
+
+ await act(() => row.querySelector<HTMLElement>('[data-testid="concept-picker"]')?.click());
+
+ const update = onCommit.mock.calls[0]?.[0] as (settings: GenerateSettings) => GenerateSettings;
+ expect(update(SETTINGS)).toBe(SETTINGS);
+ });
+
it('holds weight steps as a draft and commits them once the debounce settles', async () => {
const { onCommit, row } = await render();
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/GenerateConceptsSection.tsx b/invokeai/frontend/webv2/src/features/generation/ui/GenerateConceptsSection.tsx
index 00259dcc6d..8ddea2d36b 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/GenerateConceptsSection.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/GenerateConceptsSection.tsx
@@ -4,8 +4,8 @@ import type { GenerateLora, GenerateModelConfig, LoraModelConfig } from '@featur
import { Box, Stack, Text } from '@chakra-ui/react';
import { isLoraSupported } from '@features/generation/core/baseGenerationPolicies';
+import { addConcept, type ConceptUpdate, removeConcept, updateConcept } from '@features/generation/core/conceptList';
import {
- getDefaultLoraWeight,
isLoraCompatibleWithModel,
isLoraModelConfig,
syncGenerateLorasWithModels,
@@ -17,7 +17,7 @@ import { useTranslation } from 'react-i18next';
import type { GenerateSettingsUpdate } from './generateDebounce';
import { GenerationModelSelect as ModelSelect, useGenerationUi } from './GenerationUiContext';
-import { ConceptList, ConceptRow, type ConceptUpdate } from './shared/ConceptRow';
+import { ConceptList, ConceptRow } from './shared/ConceptRow';
interface GenerateConceptsContentProps {
loraModels: LoraModelConfig[];
@@ -43,49 +43,33 @@ export const GenerateConceptsContent = ({
const loras = useMemo(() => syncGenerateLorasWithModels(draftLoras, loraModels), [draftLoras, loraModels]);
const selectedLoraKeys = useMemo(() => new Set(loras.map((lora) => lora.model.key)), [loras]);
- const addLora = (model: ModelConfig | null) => {
- if (!isLoraModelConfig(model)) {
- return;
- }
-
- onCommit((settings) => {
- const latestLoras = syncGenerateLorasWithModels(settings.loras, loraModels);
-
- if (latestLoras.some((lora) => lora.model.key === model.key)) {
- return settings;
- }
-
- return {
- ...settings,
- loras: [...latestLoras, { isEnabled: true, model, weight: getDefaultLoraWeight(model) }],
- };
- });
- };
-
- const updateLora = useCallback(
- (modelKey: string, patch: ConceptUpdate) => {
+ /** Edits the latest settings' list as the rows show it; an edit that changes nothing leaves the settings untouched. */
+ const commitLoras = useCallback(
+ (edit: (loras: GenerateLora[]) => GenerateLora[]) => {
onCommit((settings) => {
- const latestLoras = syncGenerateLorasWithModels(settings.loras, loraModels);
- const hasLora = latestLoras.some((lora) => lora.model.key === modelKey);
-
- if (!hasLora) {
- return settings;
- }
+ const latest = syncGenerateLorasWithModels(settings.loras, loraModels);
+ const next = edit(latest);
- return {
- ...settings,
- loras: latestLoras.map((lora) => (lora.model.key === modelKey ? { ...lora, ...patch } : lora)),
- };
+ return next === latest ? settings : { ...settings, loras: next };
});
},
[loraModels, onCommit]
);
+ const addLora = (model: ModelConfig | null) => {
+ if (selectedModel && isLoraSupported(selectedModel) && isLoraModelConfig(model)) {
+ commitLoras((latest) => addConcept(latest, model, selectedModel));
+ }
+ };
+
+ const updateLora = useCallback(
+ (modelKey: string, update: ConceptUpdate) => commitLoras((latest) => updateConcept(latest, modelKey, update)),
+ [commitLoras]
+ );
+
const removeLora = useCallback(
- (modelKey: string) => {
- onCommit((settings) => ({ ...settings, loras: settings.loras.filter((lora) => lora.model.key !== modelKey) }));
- },
- [onCommit]
+ (modelKey: string) => commitLoras((latest) => removeConcept(latest, modelKey)),
+ [commitLoras]
);
const rows =
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/shared/ConceptRow.tsx b/invokeai/frontend/webv2/src/features/generation/ui/shared/ConceptRow.tsx
index 6266a046ac..3074b09765 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/shared/ConceptRow.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/shared/ConceptRow.tsx
@@ -1,4 +1,5 @@
/* oxlint-disable react-perf/jsx-no-jsx-as-prop, react-perf/jsx-no-new-function-as-prop, react-perf/jsx-no-new-object-as-prop -- ListItem slots take JSX; the React Compiler memoizes them. */
+import type { ConceptUpdate } from '@features/generation/core/conceptList';
import type { GenerateLora } from '@features/generation/core/types';
import type { MouseEvent, ReactNode } from 'react';
@@ -31,8 +32,6 @@ export interface ConceptModelPort {
openInModelManager?: (key: string) => void;
}
-export type ConceptUpdate = Partial<Pick<GenerateLora, 'isEnabled' | 'weight'>>;
-
export interface ConceptRowProps {
/** False dims the row, badges it, and locks it off; the caller decides compatibility against its main model. */
isCompatible?: boolean;
diff --git a/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleWidgetView.tsx b/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleWidgetView.tsx
index c78ff1330c..bad9eff1bf 100644
--- a/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleWidgetView.tsx
+++ b/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleWidgetView.tsx
@@ -17,12 +17,16 @@ import {
Text,
} from '@chakra-ui/react';
import {
+ addConcept,
CapabilitiesGate,
ConceptList,
type ConceptModelPort,
ConceptRow,
+ type ConceptUpdate,
GenerationSettingsSection,
+ removeConcept,
SeedField,
+ updateConcept,
} from '@features/generation/components';
import {
type ArchitectureCapabilitiesSnapshot,
@@ -31,7 +35,6 @@ import {
subscribeArchitectureCapabilities,
} from '@features/generation/runtime';
import {
- getDefaultLoraWeight,
isLoraCompatibleWithModel,
isLoraModelConfig,
isMainModelConfig,
@@ -539,34 +542,31 @@ export const UpscaleWidgetView = () => {
[models, patch, t, values]
);
+ /** An edit that leaves the list unchanged writes nothing. */
+ const patchLoras = useCallback(
+ (edit: (current: UpscaleWidgetValues) => GenerateLora[]) =>
+ patchValues((current) => {
+ const loras = edit(current);
+
+ return loras === current.loras ? {} : { loras };
+ }),
+ [patchValues]
+ );
const addLora = useCallback(
(model: ModelConfig | null) => {
- if (!isLoraModelConfig(model)) {
- return;
+ if (isLoraModelConfig(model)) {
+ patchLoras((current) => addConcept(current.loras, model, current.model));
}
-
- patchValues((current) =>
- current.model && isLoraCompatibleWithModel(model, current.model)
- ? { loras: [...current.loras, { isEnabled: true, model, weight: getDefaultLoraWeight(model) }] }
- : {}
- );
},
- [patchValues]
+ [patchLoras]
);
const updateLora = useCallback(
- (key: string, update: Partial<GenerateLora>) =>
- // A row removed mid-edit still flushes its draft; that must not write an unchanged list.
- patchValues((current) =>
- current.loras.some((lora) => lora.model.key === key)
- ? { loras: current.loras.map((lora) => (lora.model.key === key ? { ...lora, ...update } : lora)) }
- : {}
- ),
- [patchValues]
+ (key: string, update: ConceptUpdate) => patchLoras((current) => updateConcept(current.loras, key, update)),
+ [patchLoras]
);
const removeLora = useCallback(
- (key: string) =>
- patchValues((current) => ({ loras: current.loras.filter((candidate) => candidate.model.key !== key) })),
- [patchValues]
+ (key: string) => patchLoras((current) => removeConcept(current.loras, key)),
+ [patchLoras]
);
const selectedLoraKeys = useMemo(() => new Set(values.loras.map((lora) => lora.model.key)), [values.loras]);
diff --git a/invokeai/frontend/webv2/src/features/video/ui/VideoConceptsSection.tsx b/invokeai/frontend/webv2/src/features/video/ui/VideoConceptsSection.tsx
index eab3e76d4e..755c7338a4 100644
--- a/invokeai/frontend/webv2/src/features/video/ui/VideoConceptsSection.tsx
+++ b/invokeai/frontend/webv2/src/features/video/ui/VideoConceptsSection.tsx
@@ -3,12 +3,16 @@ import type { ModelConfig, ModelTaxonomyType } from '@features/models';
import { Stack, Text } from '@chakra-ui/react';
import {
+ addConcept,
ConceptList,
type ConceptModelPort,
ConceptRow,
+ type ConceptUpdate,
GenerationSettingsSection,
+ removeConcept,
+ updateConcept,
} from '@features/generation/components';
-import { getDefaultLoraWeight, isLoraCompatibleWithModel, isLoraModelConfig } from '@features/generation/settings';
+import { isLoraCompatibleWithModel, isLoraModelConfig } from '@features/generation/settings';
import { getModelBaseColorPalette, getModelBaseLabel, getModelImageUrl, useOpenModelInManager } from '@features/models';
import { ModelSelect } from '@features/models/react';
import { memo, useCallback, useMemo } from 'react';
@@ -51,29 +55,18 @@ export const VideoConceptsSection = memo(
);
const addLora = useCallback(
(candidate: ModelConfig | null) => {
- if (!model || !isLoraModelConfig(candidate) || !isLoraCompatibleWithModel(candidate, model)) {
- return;
+ if (isLoraModelConfig(candidate)) {
+ onChangeLoras((current) => addConcept(current, candidate, model));
}
-
- onChangeLoras((current) => [
- ...current,
- { isEnabled: true, model: candidate, weight: getDefaultLoraWeight(candidate) },
- ]);
},
[model, onChangeLoras]
);
const updateLora = useCallback(
- (key: string, update: Partial<GenerateLora>) =>
- // A row removed mid-edit still flushes its draft; returning the list unchanged makes that a no-op.
- onChangeLoras((current) =>
- current.some((lora) => lora.model.key === key)
- ? current.map((lora) => (lora.model.key === key ? { ...lora, ...update } : lora))
- : current
- ),
+ (key: string, update: ConceptUpdate) => onChangeLoras((current) => updateConcept(current, key, update)),
[onChangeLoras]
);
const removeLora = useCallback(
- (key: string) => onChangeLoras((current) => current.filter((candidate) => candidate.model.key !== key)),
+ (key: string) => onChangeLoras((current) => removeConcept(current, key)),
[onChangeLoras]
);