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): add Generate concepts to the latest settings
Josh Corbett489d603f9828
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.tsxindex 7f4b9d86d1..966f6e9d32 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@@ -27,6 +27,7 @@ vi.mock('react-i18next', () => {seedArchitectureCapabilities();const LORA_MODEL: LoraModelConfig = { base: 'sdxl', key: 'lora-1', name: 'Ink Wash', type: 'lora' };+const ADDED_LORA_MODEL: LoraModelConfig = { base: 'sdxl', key: 'lora-2', name: 'Chalk', type: 'lora' };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];@@ -34,7 +35,11 @@ const LORA: GenerateLora = { isEnabled: true, model: LORA_MODEL, weight: 0.75 };const SETTINGS: GenerateSettings = { ...getDefaultGenerateSettings(), loras: [LORA] };const ADAPTER = {models: {- ModelSelect: () => <div data-testid="concept-picker" />,+ ModelSelect: ({ onChange }: { onChange: (model: LoraModelConfig) => void }) => (+ <button data-testid="concept-picker" type="button" onClick={() => onChange(ADDED_LORA_MODEL)}>+ Add concept+ </button>+ ),getBaseColorPalette: () => 'gray',getBaseLabel: (base: string) => base,getImageUrl: () => '',@@ -47,7 +52,6 @@ let root: Root | null = null;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);@@ -63,7 +67,6 @@ const render = async (selectedModel: GenerateModelConfig = MAIN_MODEL, settingsselectedModel={selectedModel}settings={settings}onCommit={onCommit}- onCommitImmediate={onCommitImmediate}/></GenerationUiProvider></ChakraProvider>@@ -71,7 +74,7 @@ const render = async (selectedModel: GenerateModelConfig = MAIN_MODEL, settings);await renderProject('project-1');- return { onCommit, onCommitImmediate, renderProject, row: host };+ return { onCommit, renderProject, row: host };};/** The settings a recorded commit produces from the rendered ones. */@@ -94,7 +97,7 @@ afterEach(async () => {describe('GenerateConceptsContent', () => {it('discards a concept menu when switching projects with the same concept', async () => {- const { onCommit, onCommitImmediate, renderProject, row } = await render();+ const { onCommit, renderProject, row } = await render();await stepWeight(row);expect(row.querySelector('[role="slider"]')?.getAttribute('aria-valuenow')).toBe('0.8');@@ -113,7 +116,22 @@ describe('GenerateConceptsContent', () => {expect(document.querySelector('[role="menu"][data-state="open"]')).toBeNull();act(() => flushGenerateDrafts());expect(onCommit).not.toHaveBeenCalled();- expect(onCommitImmediate).not.toHaveBeenCalled();+ });++ it('adds a concept to the latest settings rather than the rendered list', async () => {+ const { onCommit, row } = await render();++ await act(() => row.querySelector<HTMLElement>('[data-testid="concept-picker"]')?.click());++ expect(onCommit).toHaveBeenCalledTimes(1);+ const update = onCommit.mock.calls[0]?.[0];+ expect(typeof update).toBe('function');+ // A weight that landed after this render must survive the add.+ const latest = { ...SETTINGS, loras: [{ ...LORA, weight: 0.9 }] };+ expect((update as (settings: GenerateSettings) => GenerateSettings)(latest).loras).toEqual([+ { ...LORA, weight: 0.9 },+ { isEnabled: true, model: ADDED_LORA_MODEL, weight: expect.any(Number) },+ ]);});it('holds weight steps as a draft and commits them once the debounce settles', async () => {diff --git a/invokeai/frontend/webv2/src/features/generation/ui/GenerateConceptsSection.tsx b/invokeai/frontend/webv2/src/features/generation/ui/GenerateConceptsSection.tsxindex ca1d317992..a1a677631e 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/GenerateConceptsSection.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/GenerateConceptsSection.tsx@@ -30,7 +30,6 @@ interface GenerateConceptsContentProps {projectId: string;selectedModel: GenerateModelConfig | undefined;onCommit: (update: GenerateSettingsUpdate) => void;- onCommitImmediate: (patch: Partial<GenerateSettings>) => void;}/** Whether the selected model's graph will load this concept: its family must take LoRAs and match the LoRA. */@@ -40,7 +39,6 @@ export const isCompatibleLora = (lora: GenerateLora, selectedModel: GenerateModeexport const GenerateConceptsContent = ({loraModels,onCommit,- onCommitImmediate,projectId,selectedModel,settings,@@ -51,12 +49,21 @@ export const GenerateConceptsContent = ({const selectedLoraKeys = useMemo(() => new Set(loras.map((lora) => lora.model.key)), [loras]);const addLora = (model: ModelConfig | null) => {- if (!isLoraModelConfig(model) || selectedLoraKeys.has(model.key)) {+ if (!isLoraModelConfig(model)) {return;}- onCommitImmediate({- loras: [...loras, { isEnabled: true, model, weight: getDefaultLoraWeight(model) }],+ 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) }],+ };});};diff --git a/invokeai/frontend/webv2/src/features/generation/ui/GenerateGuidanceSection.tsx b/invokeai/frontend/webv2/src/features/generation/ui/GenerateGuidanceSection.tsxindex bcb829f56a..422a9f3925 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/GenerateGuidanceSection.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/GenerateGuidanceSection.tsx@@ -84,7 +84,6 @@ export const GenerateGuidanceSection = ({selectedModel={selectedModel}settings={settings}onCommit={onConceptCommit}- onCommitImmediate={onCommitImmediate}/></Stack></GenerateCollapsibleSection>