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.

feat(webv2): add FLUX.2 regional guidance

joshistoastf77141fe5586
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.json
index 129c8ac60d..c7c9c1097a 100644
--- a/invokeai/frontend/webv2/public/locales/en.json
+++ b/invokeai/frontend/webv2/public/locales/en.json
@@ -1649,6 +1649,7 @@
"addReferenceImage": "Add reference image",
"autoNegative": "Auto-Negative",
"clearReferenceImage": "Clear reference image",
+ "flux2PositiveOnly": "FLUX.2 regional guidance supports positive prompts only. Negative prompts, Auto-Negative, and reference images must be removed before generation.",
"method": "Method",
"methods": {
"composition": "Composition",
diff --git a/invokeai/frontend/webv2/src/features/generation/core/canvas/addRegionalGuidance.test.ts b/invokeai/frontend/webv2/src/features/generation/core/canvas/addRegionalGuidance.test.ts
index 9819afbfc7..b50c90a839 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/canvas/addRegionalGuidance.test.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/canvas/addRegionalGuidance.test.ts
@@ -68,6 +68,30 @@ const fluxBaseGraph = (): TestGraph => ({
},
});
+/** A minimal FLUX.2 graph with the collector seam used by regional conditioning. */
+const flux2BaseGraph = (): TestGraph => ({
+ edges: [
+ {
+ destination: { field: 'qwen3_encoder', node_id: 'pos_cond' },
+ source: { field: 'qwen3_encoder', node_id: 'model_loader' },
+ },
+ {
+ destination: { field: 'max_seq_len', node_id: 'pos_cond' },
+ source: { field: 'max_seq_len', node_id: 'model_loader' },
+ },
+ {
+ destination: { field: 'positive_text_conditioning', node_id: 'denoise_latents' },
+ source: { field: 'collection', node_id: 'pos_cond_collect' },
+ },
+ ],
+ id: 'g',
+ nodes: {
+ denoise_latents: { id: 'denoise_latents', type: 'flux2_denoise' },
+ pos_cond: { id: 'pos_cond', type: 'flux2_klein_text_encoder' },
+ pos_cond_collect: { id: 'pos_cond_collect', type: 'collect' },
+ },
+});
+
const ipModel = (base: string): RegionalReferenceModel => ({
base,
key: `ip-${base}`,
@@ -97,15 +121,28 @@ const hasEdge = (graph: TestGraph, s: string, sf: string, d: string, df: string)
);
describe('isRegionalGuidanceSupportedForBase', () => {
- it('supports sd-1 / sdxl / flux and nothing else', () => {
+ it('supports sd-1 / sdxl / flux / flux2 and nothing else', () => {
expect(isRegionalGuidanceSupportedForBase('sd-1')).toBe(true);
expect(isRegionalGuidanceSupportedForBase('sdxl')).toBe(true);
expect(isRegionalGuidanceSupportedForBase('flux')).toBe(true);
+ expect(isRegionalGuidanceSupportedForBase('flux2')).toBe(true);
expect(isRegionalGuidanceSupportedForBase('sd-3')).toBe(false);
expect(isRegionalGuidanceSupportedForBase('cogview4')).toBe(false);
});
});
+describe('addRegionalGuidance — FLUX.2 Klein', () => {
+ it('creates mask-scoped positive conditioning and copies Qwen3 inputs', () => {
+ const g = run(flux2BaseGraph(), { base: 'flux2', regions: [region()] });
+
+ expect(g.nodes.rg_pos_cond_r1).toMatchObject({ prompt: 'a cat', type: 'flux2_klein_text_encoder' });
+ expect(hasEdge(g, 'rg_mask_to_tensor_r1', 'mask', 'rg_pos_cond_r1', 'mask')).toBe(true);
+ expect(hasEdge(g, 'model_loader', 'qwen3_encoder', 'rg_pos_cond_r1', 'qwen3_encoder')).toBe(true);
+ expect(hasEdge(g, 'model_loader', 'max_seq_len', 'rg_pos_cond_r1', 'max_seq_len')).toBe(true);
+ expect(hasEdge(g, 'rg_pos_cond_r1', 'conditioning', 'pos_cond_collect', 'item')).toBe(true);
+ });
+});
+
describe('addRegionalGuidance — SD1', () => {
it('wires a mask tensor + positive conditioning into the positive collector, copying clip', () => {
const g = run(sdBaseGraph(), { base: 'sd-1', regions: [region()] });
@@ -309,4 +346,16 @@ describe('getRegionalGuidanceRejectionReason', () => {
/auto-negative is not supported for FLUX/
);
});
+
+ it('rejects FLUX.2 negative prompts, autoNegative, and reference images', () => {
+ expect(getRegionalGuidanceRejectionReason({ ...params, mainBase: 'flux2', negativePrompt: 'blurry' })).toMatch(
+ /negative prompts are not supported for FLUX\.2/
+ );
+ expect(getRegionalGuidanceRejectionReason({ ...params, autoNegative: true, mainBase: 'flux2' })).toMatch(
+ /auto-negative is not supported for FLUX\.2/
+ );
+ expect(getRegionalGuidanceRejectionReason({ ...params, mainBase: 'flux2', referenceImageCount: 1 })).toMatch(
+ /reference images are not supported for FLUX\.2/
+ );
+ });
});
diff --git a/invokeai/frontend/webv2/src/features/generation/core/canvas/addRegionalGuidance.ts b/invokeai/frontend/webv2/src/features/generation/core/canvas/addRegionalGuidance.ts
index 66dd53ac5c..f270bb22cd 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/canvas/addRegionalGuidance.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/canvas/addRegionalGuidance.ts
@@ -10,12 +10,12 @@ const NEG_COND_ID = 'neg_cond';
const POS_COND_COLLECT_ID = 'pos_cond_collect';
const NEG_COND_COLLECT_ID = 'neg_cond_collect';
-/** The base models regional guidance supports (legacy: sd-1 / sdxl / flux). */
-export type RegionalGuidanceBase = 'sd-1' | 'sdxl' | 'flux';
+/** The base models regional guidance supports. */
+export type RegionalGuidanceBase = 'sd-1' | 'sdxl' | 'flux' | 'flux2';
-/** True when `base` supports regional guidance at all (SD1 / SDXL / FLUX). */
+/** True when `base` supports regional guidance at all. */
export const isRegionalGuidanceSupportedForBase = (base: string): base is RegionalGuidanceBase =>
- base === 'sd-1' || base === 'sdxl' || base === 'flux';
+ base === 'sd-1' || base === 'sdxl' || base === 'flux' || base === 'flux2';
/** Whether a base supports regional NEGATIVE prompts / autoNegative (SD family only, not FLUX). */
const supportsRegionalNegative = (base: RegionalGuidanceBase): boolean => base === 'sd-1' || base === 'sdxl';
@@ -81,6 +81,8 @@ const conditioningNodeType = (base: RegionalGuidanceBase): string => {
return 'sdxl_compel_prompt';
case 'flux':
return 'flux_text_encoder';
+ case 'flux2':
+ return 'flux2_klein_text_encoder';
case 'sd-1':
return 'compel';
}
@@ -101,6 +103,8 @@ const copyEncoderFields = (base: RegionalGuidanceBase): readonly string[] => {
return ['clip', 'clip2'];
case 'flux':
return ['clip', 't5_encoder', 't5_max_seq_len'];
+ case 'flux2':
+ return ['qwen3_encoder', 'max_seq_len'];
case 'sd-1':
return ['clip'];
}
@@ -245,7 +249,7 @@ export const addRegionalGuidance = (graph: BackendGraphContract, options: AddReg
// Reference images (mask-scoped): ip_adapter on SD, flux_redux on FLUX.
for (const ref of region.referenceImages) {
- if (ref.type === 'ip_adapter' && base !== 'flux') {
+ if (ref.type === 'ip_adapter' && base !== 'flux' && base !== 'flux2') {
if (!ipAdapterCollector) {
ipAdapterCollector = resolveDenoiseCollector(graph, denoise, 'ip_adapter', 'regional_ip_adapter_collector');
}
@@ -293,7 +297,8 @@ export const addRegionalGuidance = (graph: BackendGraphContract, options: AddReg
* - unsupported main base (sd-2 / sd-3 / cogview / …) → "unsupported model";
* - no drawn mask content → "no region";
* - no positive prompt, no negative prompt, and no reference images → "empty";
- * - FLUX with a negative prompt / autoNegative → those are unsupported on FLUX.
+ * - FLUX-family negative prompts / autoNegative are unsupported;
+ * - FLUX.2 regional reference images are unsupported.
*
* Per-reference-image model/image validity is resolved by the caller (which drops
* incomplete reference images before building), matching how control layers work.
@@ -318,11 +323,14 @@ export const getRegionalGuidanceRejectionReason = (params: {
if (!positivePrompt && !negativePrompt && referenceImageCount === 0) {
return `Regional guidance "${layerName}" has no prompt or reference image.`;
}
- if (mainBase === 'flux' && negativePrompt) {
- return `Regional guidance "${layerName}" negative prompts are not supported for FLUX.`;
+ if ((mainBase === 'flux' || mainBase === 'flux2') && negativePrompt) {
+ return `Regional guidance "${layerName}" negative prompts are not supported for ${mainBase === 'flux2' ? 'FLUX.2' : 'FLUX'}.`;
}
- if (mainBase === 'flux' && autoNegative) {
- return `Regional guidance "${layerName}" auto-negative is not supported for FLUX.`;
+ if ((mainBase === 'flux' || mainBase === 'flux2') && autoNegative) {
+ return `Regional guidance "${layerName}" auto-negative is not supported for ${mainBase === 'flux2' ? 'FLUX.2' : 'FLUX'}.`;
+ }
+ if (mainBase === 'flux2' && referenceImageCount > 0) {
+ return `Regional guidance "${layerName}" reference images are not supported for FLUX.2.`;
}
return null;
};
diff --git a/invokeai/frontend/webv2/src/features/generation/core/canvas/compileCanvasGraph.test.ts b/invokeai/frontend/webv2/src/features/generation/core/canvas/compileCanvasGraph.test.ts
index 93b1b54240..b5734de5c7 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/canvas/compileCanvasGraph.test.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/canvas/compileCanvasGraph.test.ts
@@ -745,4 +745,12 @@ describe('compileCanvasGraph — regional guidance', () => {
expect(backendGraph.nodes.control_net_c1).toBeDefined();
expect(backendGraph.nodes.rg_pos_cond_r1).toBeDefined();
});
+
+ it('grafts positive-only regional conditioning into a FLUX.2 graph', () => {
+ const { backendGraph } = compile(flux2Model, 'txt2img', { regionalGuidance: [region('r1')] });
+
+ expect(backendGraph.nodes.rg_pos_cond_r1).toMatchObject({ prompt: 'a cat', type: 'flux2_klein_text_encoder' });
+ expect(getEdge(backendGraph, 'rg_pos_cond_r1', 'qwen3_encoder')?.source.node_id).toBe('model_loader');
+ expect(getEdge(backendGraph, 'pos_cond_collect', 'item')?.source.node_id).toBe('pos_cond');
+ });
});
diff --git a/invokeai/frontend/webv2/src/features/generation/core/graph.test.ts b/invokeai/frontend/webv2/src/features/generation/core/graph.test.ts
index 96e67feb94..c88af49605 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/graph.test.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/graph.test.ts
@@ -278,6 +278,14 @@ describe('compileGenerateGraph', () => {
expect(getEdge(graph, 'denoise_latents', 'negative_text_conditioning')).toBeUndefined();
});
+ it('routes FLUX.2 positive conditioning through a stable collector', () => {
+ const graph = compile(flux2Model);
+
+ expect(graph.nodes.pos_cond_collect?.type).toBe('collect');
+ expect(getEdge(graph, 'pos_cond_collect', 'item')?.source.node_id).toBe('pos_cond');
+ expect(getEdge(graph, 'denoise_latents', 'positive_text_conditioning')?.source.node_id).toBe('pos_cond_collect');
+ });
+
it('rejects a stale incompatible FLUX.2 component source when Qwen3 is missing', () => {
expect(() => compile(flux2Klein9bModel, { componentSourceModel: incompatibleFlux2Source, vae: flux2Vae })).toThrow(
'Generate needs a Qwen3 Encoder for non-Diffusers FLUX.2 models.'
diff --git a/invokeai/frontend/webv2/src/features/generation/core/graph.ts b/invokeai/frontend/webv2/src/features/generation/core/graph.ts
index 1df5320a68..9eb2ce5392 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/graph.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/graph.ts
@@ -591,6 +591,7 @@ const buildFlux2Graph = (
])
: modelLoader;
const posCond = addNode(graph, { id: 'pos_cond', type: 'flux2_klein_text_encoder' });
+ const posCondCollect = addNode(graph, { id: 'pos_cond_collect', type: 'collect' });
const denoise = addNode(graph, {
cfg_scale: 1,
denoising_end: 1,
@@ -611,7 +612,8 @@ const buildFlux2Graph = (
addEdge(graph, modelLoader, 'vae', denoise, 'vae');
addEdge(graph, modelLoader, 'vae', output, 'vae');
addEdge(graph, positivePrompt, 'value', posCond, 'prompt');
- addEdge(graph, posCond, 'conditioning', denoise, 'positive_text_conditioning');
+ addEdge(graph, posCond, 'conditioning', posCondCollect, 'item');
+ addEdge(graph, posCondCollect, 'collection', denoise, 'positive_text_conditioning');
addEdge(graph, graph.nodes.seed, 'value', denoise, 'seed');
addFluxKontextReferenceImages(graph, settings, denoise, 'flux2_reference_image');
addEdge(graph, denoise, 'latents', output, 'latents');
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/invoke/prepareCanvasInvocation.test.ts b/invokeai/frontend/webv2/src/workbench/widgets/canvas/invoke/prepareCanvasInvocation.test.ts
index f96c5b9f60..205be973c3 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/invoke/prepareCanvasInvocation.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/invoke/prepareCanvasInvocation.test.ts
@@ -1011,6 +1011,10 @@ describe('resolveRegionalReferenceImages', () => {
expect(inputs[0]).toMatchObject({ id: 'ref-ipa', imageName: 'ref.png', type: 'ip_adapter' });
});
+ it('drops regional reference images for FLUX.2', () => {
+ expect(resolveRegionalReferenceImages({ referenceImages: [ipAdapterRef(asset)] }, 'flux2')).toEqual([]);
+ });
+
it('drops a FLUX Redux ref with no image assigned', () => {
expect(resolveRegionalReferenceImages({ referenceImages: [fluxReduxRef(null)] }, 'flux')).toEqual([]);
});
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/invoke/prepareCanvasInvocation.ts b/invokeai/frontend/webv2/src/workbench/widgets/canvas/invoke/prepareCanvasInvocation.ts
index 9ed2357c76..65d67a7c06 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/invoke/prepareCanvasInvocation.ts
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/invoke/prepareCanvasInvocation.ts
@@ -193,7 +193,7 @@ export const resolveRegionalReferenceImages = (
continue;
}
const { config } = ref;
- if (config.type === 'ip_adapter' && base !== 'flux') {
+ if (config.type === 'ip_adapter' && base !== 'flux' && base !== 'flux2') {
if (!config.image || !config.model || config.model.base !== base) {
continue;
}
@@ -264,7 +264,7 @@ const createRegionalGuidanceCollector = (
mainBase: model.base,
negativePrompt: layer.negativePrompt,
positivePrompt: layer.positivePrompt,
- referenceImageCount: referenceImages.length,
+ referenceImageCount: layer.referenceImages.length,
});
if (rejection) {
return false;
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersHeaderActions.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersHeaderActions.tsx
index b938f500ce..ab3ec2dfbc 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersHeaderActions.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersHeaderActions.tsx
@@ -15,8 +15,9 @@ import { useTranslation } from 'react-i18next';
import type { AddLayerItemId } from './addLayerMenu';
-import { ADD_LAYER_MENU } from './addLayerMenu';
+import { ADD_LAYER_MENU, isAddLayerItemAvailable } from './addLayerMenu';
import { useAddLayer } from './useAddLayer';
+import { useSelectedModelBase } from './useSelectedModelBase';
const MENU_POSITIONING = { placement: 'bottom-end' } as const;
@@ -38,6 +39,7 @@ const ADD_LAYER_ICONS: Record<AddLayerItemId, LucideIcon> = {
export const LayersHeaderActions = () => {
const { t } = useTranslation();
const addLayer = useAddLayer();
+ const base = useSelectedModelBase();
const handleSelect = useCallback((id: AddLayerItemId) => () => addLayer(id), [addLayer]);
@@ -58,19 +60,21 @@ export const LayersHeaderActions = () => {
<Menu.ItemGroupLabel color="fg.subtle" fontSize="2xs" textTransform="uppercase">
{t(group.titleKey)}
</Menu.ItemGroupLabel>
- {group.items.map((item) => {
- const ItemIcon = ADD_LAYER_ICONS[item.id];
- return (
- <Menu.Item key={item.id} value={item.id} onSelect={handleSelect(item.id)}>
- <HStack gap="2" minW="0" w="full">
- <Icon as={ItemIcon} boxSize="3.5" color="fg.subtle" flexShrink={0} />
- <Text flex="1" fontSize="xs">
- {t(item.labelKey)}
- </Text>
- </HStack>
- </Menu.Item>
- );
- })}
+ {group.items
+ .filter((item) => isAddLayerItemAvailable(item.id, base))
+ .map((item) => {
+ const ItemIcon = ADD_LAYER_ICONS[item.id];
+ return (
+ <Menu.Item key={item.id} value={item.id} onSelect={handleSelect(item.id)}>
+ <HStack gap="2" minW="0" w="full">
+ <Icon as={ItemIcon} boxSize="3.5" color="fg.subtle" flexShrink={0} />
+ <Text flex="1" fontSize="xs">
+ {t(item.labelKey)}
+ </Text>
+ </HStack>
+ </Menu.Item>
+ );
+ })}
</Menu.ItemGroup>
</Fragment>
))}
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/RegionalGuidanceSettings.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/RegionalGuidanceSettings.tsx
index 6f6e937209..a8f2eac695 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/RegionalGuidanceSettings.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/RegionalGuidanceSettings.tsx
@@ -98,6 +98,10 @@ export const RegionalGuidanceSettings = ({ engine, layer }: RegionalGuidanceSett
const fill = layer.mask.fill;
const isFlux = base === 'flux';
+ const isFlux2 = base === 'flux2';
+ const isFluxFamily = isFlux || isFlux2;
+ const showNegativeControls = !isFluxFamily || Boolean(layer.negativePrompt) || layer.autoNegative;
+ const showReferenceImages = !isFlux2 || layer.referenceImages.length > 0;
const commitConfig = useCallback(
(label: string, next: RegionalConfigPatch, before: RegionalConfigPatch) => {
@@ -335,6 +339,11 @@ export const RegionalGuidanceSettings = ({ engine, layer }: RegionalGuidanceSett
return (
<Stack gap="2" onKeyDown={stopKeyboardPropagation}>
+ {isFlux2 && (
+ <Text color="fg.warning" fontSize="xs" role="alert">
+ {t('widgets.layers.regionalGuidance.flux2PositiveOnly')}
+ </Text>
+ )}
<Field label={t('widgets.layers.regionalGuidance.positivePrompt')}>
<PromptTextarea
{...PROMPT_ATTENTION_TARGET_PROPS}
@@ -350,7 +359,7 @@ export const RegionalGuidanceSettings = ({ engine, layer }: RegionalGuidanceSett
onChange={handlePositiveChange}
/>
</Field>
- {!isFlux && (
+ {showNegativeControls && (
<Field label={t('widgets.layers.regionalGuidance.negativePrompt')}>
<PromptTextarea
{...PROMPT_ATTENTION_TARGET_PROPS}
@@ -367,7 +376,7 @@ export const RegionalGuidanceSettings = ({ engine, layer }: RegionalGuidanceSett
/>
</Field>
)}
- {!isFlux && (
+ {showNegativeControls && (
<Switch.Root checked={layer.autoNegative} size="sm" onCheckedChange={handleAutoNegative}>
<Switch.HiddenInput />
<Switch.Control>
@@ -404,37 +413,41 @@ export const RegionalGuidanceSettings = ({ engine, layer }: RegionalGuidanceSett
{t('widgets.layers.maskFill.invert')}
</Button>
- <Stack gap="2">
- <HStack justify="space-between">
- <Text fontSize="xs" fontWeight="medium">
- {t('widgets.layers.regionalGuidance.referenceImages')}
- </Text>
- <IconButton
- aria-label={t('widgets.layers.regionalGuidance.addReferenceImage')}
- size="2xs"
- variant="ghost"
- onClick={handleAddReferenceImage}
- >
- <PlusIcon />
- </IconButton>
- </HStack>
- {referenceImages.map((ref, index) => (
- <ReferenceImageRow
- dropId={referenceImageDropId(layer.id, ref.id)}
- index={index}
- ipAdapterModelCollection={ipAdapterModelCollection}
- fluxReduxModelCollection={fluxReduxModelCollection}
- key={ref.id}
- methodCollection={methodCollection}
- models={models}
- referenceImage={ref}
- referenceImages={referenceImages}
- onCommit={commitReferenceImages}
- onSetImage={setReferenceImageAsset}
- onUpload={uploadReferenceImageAsset}
- />
- ))}
- </Stack>
+ {showReferenceImages && (
+ <Stack gap="2">
+ <HStack justify="space-between">
+ <Text fontSize="xs" fontWeight="medium">
+ {t('widgets.layers.regionalGuidance.referenceImages')}
+ </Text>
+ {!isFlux2 && (
+ <IconButton
+ aria-label={t('widgets.layers.regionalGuidance.addReferenceImage')}
+ size="2xs"
+ variant="ghost"
+ onClick={handleAddReferenceImage}
+ >
+ <PlusIcon />
+ </IconButton>
+ )}
+ </HStack>
+ {referenceImages.map((ref, index) => (
+ <ReferenceImageRow
+ dropId={referenceImageDropId(layer.id, ref.id)}
+ index={index}
+ ipAdapterModelCollection={ipAdapterModelCollection}
+ fluxReduxModelCollection={fluxReduxModelCollection}
+ key={ref.id}
+ methodCollection={methodCollection}
+ models={models}
+ referenceImage={ref}
+ referenceImages={referenceImages}
+ onCommit={commitReferenceImages}
+ onSetImage={setReferenceImageAsset}
+ onUpload={uploadReferenceImageAsset}
+ />
+ ))}
+ </Stack>
+ )}
</Stack>
);
};
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/addLayerMenu.test.ts b/invokeai/frontend/webv2/src/workbench/widgets/layers/addLayerMenu.test.ts
index 17475e8777..9c4e20630b 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/addLayerMenu.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/addLayerMenu.test.ts
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';
-import { ADD_LAYER_MENU, groupAddItemId } from './addLayerMenu';
+import { ADD_LAYER_MENU, groupAddItemId, isAddLayerItemAvailable } from './addLayerMenu';
describe('ADD_LAYER_MENU', () => {
it('splits into the legacy Regional / Layers groups in order', () => {
@@ -31,6 +31,14 @@ describe('ADD_LAYER_MENU', () => {
});
});
+describe('isAddLayerItemAvailable', () => {
+ it('hides only regional reference-image creation for FLUX.2', () => {
+ expect(isAddLayerItemAvailable('regional_reference_image', 'flux2')).toBe(false);
+ expect(isAddLayerItemAvailable('regional_guidance', 'flux2')).toBe(true);
+ expect(isAddLayerItemAvailable('regional_reference_image', 'flux')).toBe(true);
+ });
+});
+
describe('groupAddItemId', () => {
it('maps a group key to its own add-layer item', () => {
expect(groupAddItemId('raster')).toBe('raster');
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/addLayerMenu.ts b/invokeai/frontend/webv2/src/workbench/widgets/layers/addLayerMenu.ts
index aa3888bd48..c10afbc049 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/addLayerMenu.ts
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/addLayerMenu.ts
@@ -44,5 +44,9 @@ export const ADD_LAYER_MENU: readonly AddLayerMenuGroup[] = [
},
];
+/** Whether an add action is supported by the selected model base. */
+export const isAddLayerItemAvailable = (id: AddLayerItemId, base: string | null): boolean =>
+ id !== 'regional_reference_image' || base !== 'flux2';
+
/** The add-layer action a group-header "New" button triggers for its type. */
export const groupAddItemId = (groupKey: LayerGroupKey): AddLayerItemId => groupKey;
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/useAddLayer.ts b/invokeai/frontend/webv2/src/workbench/widgets/layers/useAddLayer.ts
index 161122178b..3739abcdfb 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/useAddLayer.ts
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/useAddLayer.ts
@@ -7,6 +7,7 @@ import { useTranslation } from 'react-i18next';
import type { AddLayerItemId } from './addLayerMenu';
+import { isAddLayerItemAvailable } from './addLayerMenu';
import {
applyStructural,
createControlLayer,
@@ -41,6 +42,9 @@ export const useAddLayer = (): ((id: AddLayerItemId) => void) => {
return useCallback(
(id: AddLayerItemId) => {
+ if (!isAddLayerItemAvailable(id, base)) {
+ return;
+ }
switch (id) {
case 'raster': {
const layer = createEmptyPaintLayer(nextLayerName(layerNames));