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): replace the seed dropdown that crashed the Generate widget

joshistoast29c5f9f933b9
diff --git a/invokeai/frontend/webv2/performance/browser-baseline.json b/invokeai/frontend/webv2/performance/browser-baseline.json
index f6149a97b8..618bea88e7 100644
--- a/invokeai/frontend/webv2/performance/browser-baseline.json
+++ b/invokeai/frontend/webv2/performance/browser-baseline.json
@@ -39,22 +39,22 @@
"fontRawBytes": 23664,
"imageRawBytes": 0,
"largestAssetRawBytes": 737748,
- "otherRawBytes": 89849,
+ "otherRawBytes": 90719,
"requestCount": 19,
- "scriptRawBytes": 1453501,
+ "scriptRawBytes": 1453717,
"scriptRequestCount": 15,
- "totalRawBytes": 1569173
+ "totalRawBytes": 1570259
},
"resourceLimits": {
"cssRawBytes": 2181,
"fontRawBytes": 23901,
"imageRawBytes": 0,
"largestAssetRawBytes": 745126,
- "otherRawBytes": 90742,
+ "otherRawBytes": 91627,
"requestCount": 19,
- "scriptRawBytes": 1468037,
+ "scriptRawBytes": 1468255,
"scriptRequestCount": 15,
- "totalRawBytes": 1584859
+ "totalRawBytes": 1585962
},
"routeReadyMedianMs": 227.19999999925494,
"scriptSourceOwnerSet": "launchpad-static",
@@ -97,22 +97,22 @@
"fontRawBytes": 23664,
"imageRawBytes": 0,
"largestAssetRawBytes": 737748,
- "otherRawBytes": 89849,
+ "otherRawBytes": 90719,
"requestCount": 19,
- "scriptRawBytes": 1453501,
+ "scriptRawBytes": 1453717,
"scriptRequestCount": 15,
- "totalRawBytes": 1569173
+ "totalRawBytes": 1570259
},
"resourceLimits": {
"cssRawBytes": 2181,
"fontRawBytes": 23901,
"imageRawBytes": 0,
"largestAssetRawBytes": 745126,
- "otherRawBytes": 90742,
+ "otherRawBytes": 91627,
"requestCount": 19,
- "scriptRawBytes": 1468037,
+ "scriptRawBytes": 1468255,
"scriptRequestCount": 15,
- "totalRawBytes": 1584859
+ "totalRawBytes": 1585962
},
"routeReadyMedianMs": 278.8999999985099,
"scriptSourceOwnerSet": "launchpad-static",
@@ -155,22 +155,22 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 737748,
- "otherRawBytes": 89849,
+ "otherRawBytes": 90719,
"requestCount": 95,
- "scriptRawBytes": 2920198,
+ "scriptRawBytes": 2950107,
"scriptRequestCount": 89,
- "totalRawBytes": 3207659
+ "totalRawBytes": 3238438
},
"resourceLimits": {
"cssRawBytes": 17748,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 745126,
- "otherRawBytes": 90742,
+ "otherRawBytes": 91627,
"requestCount": 95,
- "scriptRawBytes": 2949400,
+ "scriptRawBytes": 2979609,
"scriptRequestCount": 89,
- "totalRawBytes": 3239730
+ "totalRawBytes": 3270823
},
"routeReadyMedianMs": 614.6999999992549,
"scriptSourceOwnerSet": "editor-minimal-static",
@@ -213,22 +213,22 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 737748,
- "otherRawBytes": 89849,
+ "otherRawBytes": 90719,
"requestCount": 95,
- "scriptRawBytes": 2920198,
+ "scriptRawBytes": 2950107,
"scriptRequestCount": 89,
- "totalRawBytes": 3207659
+ "totalRawBytes": 3238438
},
"resourceLimits": {
"cssRawBytes": 17748,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 745126,
- "otherRawBytes": 90742,
+ "otherRawBytes": 91627,
"requestCount": 95,
- "scriptRawBytes": 2949400,
+ "scriptRawBytes": 2979609,
"scriptRequestCount": 89,
- "totalRawBytes": 3239730
+ "totalRawBytes": 3270823
},
"routeReadyMedianMs": 663.1999999992549,
"scriptSourceOwnerSet": "editor-minimal-static",
@@ -242,9 +242,9 @@
"largestAssetRawBytes": 136446,
"otherRawBytes": 0,
"requestCount": 7,
- "scriptRawBytes": 290434,
+ "scriptRawBytes": 290437,
"scriptRequestCount": 7,
- "totalRawBytes": 290434
+ "totalRawBytes": 290437
},
"activatedResourceLimits": {
"cssRawBytes": 0,
@@ -253,9 +253,9 @@
"largestAssetRawBytes": 137811,
"otherRawBytes": 0,
"requestCount": 7,
- "scriptRawBytes": 293339,
+ "scriptRawBytes": 293342,
"scriptRequestCount": 7,
- "totalRawBytes": 293339
+ "totalRawBytes": 293342
},
"domContentLoadedMedianMs": 114.40000000037253,
"id": "editor-canvas",
@@ -271,22 +271,22 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 737748,
- "otherRawBytes": 89849,
+ "otherRawBytes": 90719,
"requestCount": 99,
- "scriptRawBytes": 3196397,
+ "scriptRawBytes": 3226309,
"scriptRequestCount": 93,
- "totalRawBytes": 3483858
+ "totalRawBytes": 3514640
},
"resourceLimits": {
"cssRawBytes": 17748,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 745126,
- "otherRawBytes": 90742,
+ "otherRawBytes": 91627,
"requestCount": 99,
- "scriptRawBytes": 3228361,
+ "scriptRawBytes": 3258573,
"scriptRequestCount": 93,
- "totalRawBytes": 3518691
+ "totalRawBytes": 3549787
},
"routeReadyMedianMs": 767.3000000007451,
"scriptSourceOwnerSet": "editor-canvas-static",
@@ -300,9 +300,9 @@
"largestAssetRawBytes": 136446,
"otherRawBytes": 0,
"requestCount": 7,
- "scriptRawBytes": 290434,
+ "scriptRawBytes": 290437,
"scriptRequestCount": 7,
- "totalRawBytes": 290434
+ "totalRawBytes": 290437
},
"activatedResourceLimits": {
"cssRawBytes": 0,
@@ -311,9 +311,9 @@
"largestAssetRawBytes": 137811,
"otherRawBytes": 0,
"requestCount": 7,
- "scriptRawBytes": 293339,
+ "scriptRawBytes": 293342,
"scriptRequestCount": 7,
- "totalRawBytes": 293339
+ "totalRawBytes": 293342
},
"domContentLoadedMedianMs": 114.30000000074506,
"id": "editor-canvas",
@@ -329,22 +329,22 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 737748,
- "otherRawBytes": 89849,
+ "otherRawBytes": 90719,
"requestCount": 99,
- "scriptRawBytes": 3196397,
+ "scriptRawBytes": 3226309,
"scriptRequestCount": 93,
- "totalRawBytes": 3483858
+ "totalRawBytes": 3514640
},
"resourceLimits": {
"cssRawBytes": 17748,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 745126,
- "otherRawBytes": 90742,
+ "otherRawBytes": 91627,
"requestCount": 99,
- "scriptRawBytes": 3228361,
+ "scriptRawBytes": 3258573,
"scriptRequestCount": 93,
- "totalRawBytes": 3518691
+ "totalRawBytes": 3549787
},
"routeReadyMedianMs": 1164.4000000003725,
"scriptSourceOwnerSet": "editor-canvas-static",
@@ -387,22 +387,22 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 737748,
- "otherRawBytes": 89849,
+ "otherRawBytes": 90719,
"requestCount": 95,
- "scriptRawBytes": 2920198,
+ "scriptRawBytes": 2950107,
"scriptRequestCount": 89,
- "totalRawBytes": 3207659
+ "totalRawBytes": 3238438
},
"resourceLimits": {
"cssRawBytes": 17748,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 745126,
- "otherRawBytes": 90742,
+ "otherRawBytes": 91627,
"requestCount": 95,
- "scriptRawBytes": 2949400,
+ "scriptRawBytes": 2979609,
"scriptRequestCount": 89,
- "totalRawBytes": 3239730
+ "totalRawBytes": 3270823
},
"routeReadyMedianMs": 750.6999999992549,
"scriptSourceOwnerSet": "editor-minimal-static",
@@ -445,22 +445,22 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 737748,
- "otherRawBytes": 89849,
+ "otherRawBytes": 90719,
"requestCount": 95,
- "scriptRawBytes": 2920198,
+ "scriptRawBytes": 2950107,
"scriptRequestCount": 89,
- "totalRawBytes": 3207659
+ "totalRawBytes": 3238438
},
"resourceLimits": {
"cssRawBytes": 17748,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 745126,
- "otherRawBytes": 90742,
+ "otherRawBytes": 91627,
"requestCount": 95,
- "scriptRawBytes": 2949400,
+ "scriptRawBytes": 2979609,
"scriptRequestCount": 89,
- "totalRawBytes": 3239730
+ "totalRawBytes": 3270823
},
"routeReadyMedianMs": 977.9000000003725,
"scriptSourceOwnerSet": "editor-minimal-static",
@@ -503,22 +503,22 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 737748,
- "otherRawBytes": 89849,
+ "otherRawBytes": 90719,
"requestCount": 95,
- "scriptRawBytes": 2920198,
+ "scriptRawBytes": 2950107,
"scriptRequestCount": 89,
- "totalRawBytes": 3207659
+ "totalRawBytes": 3238438
},
"resourceLimits": {
"cssRawBytes": 17748,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 745126,
- "otherRawBytes": 90742,
+ "otherRawBytes": 91627,
"requestCount": 95,
- "scriptRawBytes": 2949400,
+ "scriptRawBytes": 2979609,
"scriptRequestCount": 89,
- "totalRawBytes": 3239730
+ "totalRawBytes": 3270823
},
"routeReadyMedianMs": 708.5,
"scriptSourceOwnerSet": "editor-minimal-static",
@@ -561,22 +561,22 @@
"fontRawBytes": 23664,
"imageRawBytes": 156376,
"largestAssetRawBytes": 737748,
- "otherRawBytes": 89849,
+ "otherRawBytes": 90719,
"requestCount": 95,
- "scriptRawBytes": 2920198,
+ "scriptRawBytes": 2950107,
"scriptRequestCount": 89,
- "totalRawBytes": 3207659
+ "totalRawBytes": 3238438
},
"resourceLimits": {
"cssRawBytes": 17748,
"fontRawBytes": 23901,
"imageRawBytes": 157940,
"largestAssetRawBytes": 745126,
- "otherRawBytes": 90742,
+ "otherRawBytes": 91627,
"requestCount": 95,
- "scriptRawBytes": 2949400,
+ "scriptRawBytes": 2979609,
"scriptRequestCount": 89,
- "totalRawBytes": 3239730
+ "totalRawBytes": 3270823
},
"routeReadyMedianMs": 857,
"scriptSourceOwnerSet": "editor-minimal-static",
@@ -1024,6 +1024,7 @@
"source:src/features/generation/ui/generateFormViewModel.ts",
"source:src/features/generation/ui/modelSelectionNotice.ts",
"source:src/features/generation/ui/promptFields/DynamicPromptsButton.tsx",
+ "source:src/features/generation/ui/promptFields/DynamicPromptsPanel.tsx",
"source:src/features/generation/ui/promptFields/GeneratePromptFields.tsx",
"source:src/features/generation/ui/promptFields/NegativePromptField.tsx",
"source:src/features/generation/ui/promptFields/PositivePromptActions.tsx",
@@ -1805,6 +1806,7 @@
"source:src/features/generation/ui/generateFormViewModel.ts",
"source:src/features/generation/ui/modelSelectionNotice.ts",
"source:src/features/generation/ui/promptFields/DynamicPromptsButton.tsx",
+ "source:src/features/generation/ui/promptFields/DynamicPromptsPanel.tsx",
"source:src/features/generation/ui/promptFields/GeneratePromptFields.tsx",
"source:src/features/generation/ui/promptFields/NegativePromptField.tsx",
"source:src/features/generation/ui/promptFields/PositivePromptActions.tsx",
diff --git a/invokeai/frontend/webv2/src/features/generation/core/dynamicPrompts.test.ts b/invokeai/frontend/webv2/src/features/generation/core/dynamicPrompts.test.ts
index a778617ec4..7db01a0d62 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/dynamicPrompts.test.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/dynamicPrompts.test.ts
@@ -1,11 +1,6 @@
import { describe, expect, it } from 'vitest';
-import {
- findWildcardReferences,
- hasDynamicPromptSyntax,
- sanitizeDynamicPromptsConfig,
- sanitizeMaxPrompts,
-} from './dynamicPrompts';
+import { hasDynamicPromptSyntax, sanitizeDynamicPromptsConfig, sanitizeMaxPrompts } from './dynamicPrompts';
describe('hasDynamicPromptSyntax', () => {
it('detects a variant anywhere in the prompt', () => {
@@ -28,19 +23,6 @@ describe('hasDynamicPromptSyntax', () => {
});
});
-describe('findWildcardReferences', () => {
- it('collects each referenced name once, in order', () => {
- expect(findWildcardReferences('a __colors__ __animals/dogs__ and __colors__ again')).toEqual([
- 'colors',
- 'animals/dogs',
- ]);
- });
-
- it('returns nothing for a prompt with no references', () => {
- expect(findWildcardReferences('a {red|green} ball')).toEqual([]);
- });
-});
-
describe('sanitizeMaxPrompts', () => {
it('clamps to the backend bounds and falls back on garbage', () => {
expect(sanitizeMaxPrompts(50)).toBe(50);
diff --git a/invokeai/frontend/webv2/src/features/generation/core/dynamicPrompts.ts b/invokeai/frontend/webv2/src/features/generation/core/dynamicPrompts.ts
index f0352bef3f..7b7526666b 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/dynamicPrompts.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/dynamicPrompts.ts
@@ -18,8 +18,6 @@ export const DYNAMIC_PROMPTS_DEFAULT_MAX_PROMPTS = 100;
export type DynamicPromptsSeedBehaviour = 'per-iteration' | 'per-image';
-export const DYNAMIC_PROMPTS_SEED_BEHAVIOURS: readonly DynamicPromptsSeedBehaviour[] = ['per-iteration', 'per-image'];
-
export interface DynamicPromptsConfig {
combinatorial: boolean;
maxPrompts: number;
@@ -32,7 +30,12 @@ export interface DynamicPromptsConfig {
seedBehaviour: DynamicPromptsSeedBehaviour;
}
-/** `__name__`, the reference form for a wildcard. Mirrors the backend's name rule. */
+/**
+ * `__name__`, the reference form for a wildcard. Mirrors the backend's name rule
+ * exactly — each `/`-separated segment must begin and end alphanumerically, so
+ * `snake__case` is ordinary text rather than a reference. Shared with the syntax
+ * scanner so highlighting and expansion agree on what counts as a wildcard.
+ */
export const WILDCARD_REFERENCE_RE =
/__([A-Za-z0-9](?:[A-Za-z0-9_-]*[A-Za-z0-9])?(?:\/[A-Za-z0-9](?:[A-Za-z0-9_-]*[A-Za-z0-9])?)*)__/;
@@ -44,20 +47,6 @@ export const WILDCARD_REFERENCE_RE =
export const hasDynamicPromptSyntax = (prompt: string): boolean =>
/\{[\s\S]*\}/.test(prompt) || WILDCARD_REFERENCE_RE.test(prompt);
-/** The wildcard names a prompt references, in order of first appearance. */
-export const findWildcardReferences = (prompt: string): string[] => {
- const pattern = new RegExp(WILDCARD_REFERENCE_RE, 'g');
- const names: string[] = [];
-
- for (let match = pattern.exec(prompt); match; match = pattern.exec(prompt)) {
- if (!names.includes(match[1])) {
- names.push(match[1]);
- }
- }
-
- return names;
-};
-
export const isDynamicPromptsSeedBehaviour = (value: unknown): value is DynamicPromptsSeedBehaviour =>
value === 'per-iteration' || value === 'per-image';
diff --git a/invokeai/frontend/webv2/src/features/generation/core/prompt/dynamicPromptSyntax.ts b/invokeai/frontend/webv2/src/features/generation/core/prompt/dynamicPromptSyntax.ts
index 91bc065088..c0cb088e6f 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/prompt/dynamicPromptSyntax.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/prompt/dynamicPromptSyntax.ts
@@ -11,6 +11,8 @@
* embedding parser untouched.
*/
+import { WILDCARD_REFERENCE_RE } from '@features/generation/core/dynamicPrompts';
+
import type { PromptRange } from './ast';
export type DynamicPromptSyntaxKind =
@@ -27,7 +29,6 @@ export interface DynamicPromptSyntaxAnnotation {
range: PromptRange;
}
-const WILDCARD_PATTERN = /__(.+?)__/g;
/** `2::`, `1.5::` — a variant value's relative weight. */
const WEIGHT_PATTERN = /^\s*\d+(?:\.\d+)?::/;
/** `2$$`, `2-3$$`, `-3$$`, and the custom-separator form `2$$, $$`. */
@@ -154,9 +155,9 @@ export const scanDynamicPromptSyntax = (
annotations[openBrace.annotationIndex].kind = 'error';
}
- WILDCARD_PATTERN.lastIndex = 0;
+ const wildcardPattern = new RegExp(WILDCARD_REFERENCE_RE, 'g');
- for (let match = WILDCARD_PATTERN.exec(prompt); match; match = WILDCARD_PATTERN.exec(prompt)) {
+ for (let match = wildcardPattern.exec(prompt); match; match = wildcardPattern.exec(prompt)) {
const wildcardRange = { end: match.index + match[0].length, start: match.index };
if (!variableRanges.some((variableRange) => covers(variableRange, wildcardRange))) {
diff --git a/invokeai/frontend/webv2/src/features/generation/settings.ts b/invokeai/frontend/webv2/src/features/generation/settings.ts
index 0a181c7bff..3e6f633b18 100644
--- a/invokeai/frontend/webv2/src/features/generation/settings.ts
+++ b/invokeai/frontend/webv2/src/features/generation/settings.ts
@@ -55,7 +55,6 @@ export {
DYNAMIC_PROMPTS_DEFAULT_MAX_PROMPTS,
DYNAMIC_PROMPTS_MAX_PROMPTS,
DYNAMIC_PROMPTS_MIN_PROMPTS,
- DYNAMIC_PROMPTS_SEED_BEHAVIOURS,
hasDynamicPromptSyntax,
isDynamicPromptsSeedBehaviour,
sanitizeDynamicPromptsConfig,
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/DynamicPromptsButton.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/DynamicPromptsButton.tsx
index 15ac17eec4..1d07dfab6c 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/DynamicPromptsButton.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/DynamicPromptsButton.tsx
@@ -1,42 +1,18 @@
-/* oxlint-disable react-perf/jsx-no-new-object-as-prop, react-perf/jsx-no-new-function-as-prop */
-import type { DynamicPromptsConfig, DynamicPromptsSeedBehaviour } from '@features/generation/core/dynamicPrompts';
+import type { DynamicPromptsFieldConfig } from '@features/generation/ui/promptFields/DynamicPromptsPanel';
-import {
- createListCollection,
- HStack,
- NumberInput,
- Popover,
- Portal,
- SegmentGroup,
- Stack,
- Text,
-} from '@chakra-ui/react';
-import {
- createDynamicPromptsSampleSeed,
- DYNAMIC_PROMPTS_MAX_PROMPTS,
- DYNAMIC_PROMPTS_MIN_PROMPTS,
- isDynamicPromptsSeedBehaviour,
- sanitizeMaxPrompts,
-} from '@features/generation/core/dynamicPrompts';
+import { Popover, Portal, SegmentGroup, Stack, Text } from '@chakra-ui/react';
+import { DynamicPromptsPanel } from '@features/generation/ui/promptFields/DynamicPromptsPanel';
import { WildcardsPanel } from '@features/generation/ui/promptFields/WildcardsPanel';
import { useDynamicPrompts } from '@features/generation/ui/useDynamicPrompts';
import { useWildcards } from '@features/generation/ui/useWildcards';
-import { Button, IconButton } from '@platform/ui/Button';
-import { Scrollable } from '@platform/ui/Scrollable';
-import { Select } from '@platform/ui/Select';
+import { IconButton } from '@platform/ui/Button';
import { Tooltip } from '@platform/ui/Tooltip';
-import { BracesIcon, ShuffleIcon } from 'lucide-react';
+import { BracesIcon } from 'lucide-react';
import { useCallback, useId, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
-/** Rendering every row of a 10,000-prompt expansion would cost more than it tells the user. */
-const MAX_PREVIEW_ROWS = 200;
const POPOVER_POSITIONING_BOTTOM_END = { placement: 'bottom-end' } as const;
-const COUNT_TEXT_PROPS = { fontVariantNumeric: 'tabular-nums' } as const;
-
-export interface DynamicPromptsFieldConfig extends DynamicPromptsConfig {
- onChange: (patch: Partial<DynamicPromptsConfig>) => void;
-}
+const TABULAR_NUMS = { fontVariantNumeric: 'tabular-nums' } as const;
interface DynamicPromptsButtonProps {
config: DynamicPromptsFieldConfig;
@@ -60,25 +36,22 @@ export const DynamicPromptsButton = ({
const expansion = useDynamicPrompts(positivePrompt, config);
const catalog = useWildcards();
const popoverIds = useMemo(() => ({ trigger: triggerId }), [triggerId]);
+
const handleOpenChange = useCallback((event: { open: boolean }) => setIsOpen(event.open), []);
- const handleUsePrompt = useCallback(
- (prompt: string) => {
- onUsePrompt(prompt);
- setIsOpen(false);
- },
- [onUsePrompt]
+ const handleTabChange = useCallback(
+ (event: { value: string | null }) => setTab(event.value === 'wildcards' ? 'wildcards' : 'preview'),
+ []
);
- const handleInsert = useCallback(
- (text: string) => {
- onInsertText(text);
+ const closeWith = useCallback(
+ (apply: (value: string) => void) => (value: string) => {
+ apply(value);
setIsOpen(false);
},
- [onInsertText]
- );
- const handleTabChange = useCallback(
- (event: { value: string | null }) => setTab(event.value === 'wildcards' ? 'wildcards' : 'preview'),
[]
);
+ const handleUsePrompt = useMemo(() => closeWith(onUsePrompt), [closeWith, onUsePrompt]);
+ const handleInsert = useMemo(() => closeWith(onInsertText), [closeWith, onInsertText]);
+
const tabItems = useMemo(
() => [
{ label: t('widgets.generate.dynamicPrompts.preview'), value: 'preview' },
@@ -90,8 +63,8 @@ export const DynamicPromptsButton = ({
const tooltip = expansion.isDynamic
? t('widgets.generate.dynamicPrompts.showPrompts')
: t('widgets.generate.dynamicPrompts.noDynamicSyntax');
- // Quiet states only: an em-dash while the expansion is in flight, an error
- // tint when it failed. No spinner, no animation on a control this small.
+ // Quiet states only: an em-dash while the expansion is in flight, an error tint
+ // when it failed. No spinner, no animation on a control this small.
const countLabel = !expansion.isDynamic ? null : expansion.isLoading ? '—' : String(expansion.count);
return (
@@ -116,7 +89,7 @@ export const DynamicPromptsButton = ({
>
<BracesIcon />
{countLabel ? (
- <Text as="span" css={COUNT_TEXT_PROPS} fontSize="2xs">
+ <Text as="span" css={TABULAR_NUMS} fontSize="2xs">
{countLabel}
</Text>
) : null}
@@ -128,7 +101,9 @@ export const DynamicPromptsButton = ({
<Popover.Content bg="bg.muted" borderColor="border.emphasized" borderWidth="1px" w="26rem">
<Popover.Body p="2.5">
<Stack gap="2.5">
- <SegmentGroup.Root size="xs" value={tab} onValueChange={handleTabChange}>
+ {/* `alignSelf` keeps the tabs to their content width; stretched across
+ the popover they read as a header band rather than a control. */}
+ <SegmentGroup.Root alignSelf="start" size="xs" value={tab} onValueChange={handleTabChange}>
<SegmentGroup.Indicator />
<SegmentGroup.Items items={tabItems} />
</SegmentGroup.Root>
@@ -150,190 +125,3 @@ export const DynamicPromptsButton = ({
</Popover.Root>
);
};
-
-const DynamicPromptsPanel = ({
- batchCount,
- config,
- expansion,
- onUsePrompt,
-}: {
- batchCount: number;
- config: DynamicPromptsFieldConfig;
- expansion: ReturnType<typeof useDynamicPrompts>;
- onUsePrompt: (prompt: string) => void;
-}) => {
- const { t } = useTranslation();
- const { onChange } = config;
- const visiblePrompts = expansion.prompts.slice(0, MAX_PREVIEW_ROWS);
- const hiddenPromptCount = expansion.prompts.length - visiblePrompts.length;
-
- const handleModeChange = useCallback(
- (event: { value: string | null }) => onChange({ combinatorial: event.value !== 'random' }),
- [onChange]
- );
- const handleMaxPromptsChange = useCallback(
- ({ valueAsNumber }: { valueAsNumber: number }) =>
- Number.isFinite(valueAsNumber) && onChange({ maxPrompts: sanitizeMaxPrompts(valueAsNumber) }),
- [onChange]
- );
- const handleSeedBehaviourChange = useCallback(
- ({ value }: { value: string[] }) =>
- isDynamicPromptsSeedBehaviour(value[0]) && onChange({ seedBehaviour: value[0] as DynamicPromptsSeedBehaviour }),
- [onChange]
- );
- const handleShuffle = useCallback(() => onChange({ sampleSeed: createDynamicPromptsSampleSeed() }), [onChange]);
- const modeItems = useMemo(
- () => [
- { label: t('widgets.generate.dynamicPrompts.allCombinations'), value: 'all' },
- { label: t('widgets.generate.dynamicPrompts.randomSample'), value: 'random' },
- ],
- [t]
- );
- const maxPromptsLabel = config.combinatorial
- ? t('widgets.generate.dynamicPrompts.maxPrompts')
- : t('widgets.generate.dynamicPrompts.numberOfPrompts');
- const seedBehaviourValue = useMemo(() => [config.seedBehaviour], [config.seedBehaviour]);
- const seedBehaviourCollection = useMemo(
- () =>
- createListCollection({
- items: [
- { label: t('widgets.generate.dynamicPrompts.seedPerIteration'), value: 'per-iteration' },
- { label: t('widgets.generate.dynamicPrompts.seedPerImage'), value: 'per-image' },
- ],
- }),
- [t]
- );
-
- return (
- <Stack gap="2.5">
- <HStack justify="space-between">
- <Text color="fg.subtle" fontSize="2xs" fontWeight="700" textTransform="uppercase">
- {t('widgets.generate.dynamicPrompts.title')}
- </Text>
- <Text color="fg.muted" css={COUNT_TEXT_PROPS} fontSize="2xs">
- {expansion.isLoading
- ? t('widgets.generate.dynamicPrompts.expanding')
- : t('widgets.generate.dynamicPrompts.summary', {
- generations: expansion.count * batchCount,
- iterations: batchCount,
- prompts: expansion.count,
- })}
- </Text>
- </HStack>
-
- <HStack gap="2">
- <SegmentGroup.Root
- flex="1"
- size="xs"
- value={config.combinatorial ? 'all' : 'random'}
- onValueChange={handleModeChange}
- >
- <SegmentGroup.Indicator />
- <SegmentGroup.Items items={modeItems} />
- </SegmentGroup.Root>
- {config.combinatorial ? null : (
- <Tooltip content={t('widgets.generate.dynamicPrompts.shuffle')}>
- <IconButton
- aria-label={t('widgets.generate.dynamicPrompts.shuffle')}
- size="xs"
- variant="ghost"
- onClick={handleShuffle}
- >
- <ShuffleIcon />
- </IconButton>
- </Tooltip>
- )}
- </HStack>
-
- <HStack gap="2">
- <Stack flex="1" gap="1">
- <Text color="fg.subtle" fontSize="2xs">
- {maxPromptsLabel}
- </Text>
- <NumberInput.Root
- allowMouseWheel
- max={DYNAMIC_PROMPTS_MAX_PROMPTS}
- min={DYNAMIC_PROMPTS_MIN_PROMPTS}
- size="xs"
- value={String(config.maxPrompts)}
- onValueChange={handleMaxPromptsChange}
- >
- <NumberInput.Control />
- <NumberInput.Input aria-label={maxPromptsLabel} paddingStart="2" />
- </NumberInput.Root>
- </Stack>
- <Stack flex="1" gap="1">
- <Text color="fg.subtle" fontSize="2xs">
- {t('widgets.generate.dynamicPrompts.seedBehaviour')}
- </Text>
- <Select
- aria-label={t('widgets.generate.dynamicPrompts.seedBehaviour')}
- collection={seedBehaviourCollection}
- size="xs"
- value={seedBehaviourValue}
- onValueChange={handleSeedBehaviourChange}
- />
- </Stack>
- </HStack>
-
- {expansion.isError ? (
- <Text color="fg.error" fontSize="2xs">
- {t('widgets.generate.dynamicPrompts.problemGeneratingPrompts')}
- </Text>
- ) : expansion.error ? (
- <Text color="fg.error" fontSize="2xs" wordBreak="break-word">
- {expansion.error}
- </Text>
- ) : null}
-
- <Scrollable h="14rem" label={t('widgets.generate.dynamicPrompts.promptsPreview')}>
- <Stack gap="0">
- {visiblePrompts.map((prompt, index) => (
- <DynamicPromptRow key={`${index}-${prompt}`} index={index} prompt={prompt} onUsePrompt={onUsePrompt} />
- ))}
- {hiddenPromptCount > 0 ? (
- <Text color="fg.subtle" fontSize="2xs" px="2" py="1.5">
- {t('widgets.generate.dynamicPrompts.andMore', { count: hiddenPromptCount })}
- </Text>
- ) : null}
- </Stack>
- </Scrollable>
- </Stack>
- );
-};
-
-const DynamicPromptRow = ({
- index,
- onUsePrompt,
- prompt,
-}: {
- index: number;
- prompt: string;
- onUsePrompt: (prompt: string) => void;
-}) => {
- const { t } = useTranslation();
- const handleClick = useCallback(() => onUsePrompt(prompt), [onUsePrompt, prompt]);
-
- return (
- <Button
- alignItems="start"
- gap="2"
- h="auto"
- justifyContent="start"
- px="2"
- py="1.5"
- size="xs"
- title={t('widgets.generate.dynamicPrompts.usePrompt')}
- transitionDuration="faster"
- variant="ghost"
- onClick={handleClick}
- >
- <Text as="span" color="fg.subtle" css={COUNT_TEXT_PROPS} fontSize="2xs">
- {index + 1}
- </Text>
- <Text as="span" color="fg" fontFamily="mono" fontSize="0.72rem" textAlign="start" wordBreak="break-word">
- {prompt}
- </Text>
- </Button>
- );
-};
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/DynamicPromptsControls.browser.test.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/DynamicPromptsControls.browser.test.tsx
new file mode 100644
index 0000000000..db41366992
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/DynamicPromptsControls.browser.test.tsx
@@ -0,0 +1,162 @@
+/* oxlint-disable react-perf/jsx-no-new-object-as-prop, react-perf/jsx-no-new-function-as-prop */
+import type { DynamicPromptsConfig } from '@features/generation/core/dynamicPrompts';
+
+import { ChakraProvider } from '@chakra-ui/react';
+import { DynamicPromptsButton } from '@features/generation/ui/promptFields/DynamicPromptsButton';
+import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
+import { system } from '@theme/system';
+import { act } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { userEvent } from 'vitest/browser';
+
+const parseDynamicPrompts = vi.hoisted(() => vi.fn());
+
+vi.mock('@features/generation/data/promptUtilities', () => ({ parseDynamicPrompts }));
+vi.mock('@features/generation/data/wildcards', () => ({
+ createWildcard: vi.fn(),
+ deleteWildcard: vi.fn(),
+ invalidateWildcardDependents: vi.fn(),
+ updateWildcard: vi.fn(),
+ wildcardsQueryOptions: () => ({ queryFn: () => Promise.resolve([]), queryKey: ['generation', 'wildcards'] }),
+}));
+
+let host: HTMLDivElement | null = null;
+let root: Root | null = null;
+const pageErrors: string[] = [];
+(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
+
+const BASE_CONFIG: DynamicPromptsConfig = {
+ combinatorial: true,
+ maxPrompts: 100,
+ sampleSeed: 0,
+ seedBehaviour: 'per-iteration',
+};
+
+/**
+ * Renders with real state, so a control that reflects its own value (a segmented
+ * control does) can actually be toggled back and forth.
+ */
+const render = async (onChange: (patch: Partial<DynamicPromptsConfig>) => void = vi.fn()) => {
+ host = document.createElement('div');
+ document.body.append(host);
+ root = createRoot(host);
+ const client = new QueryClient();
+ let config = BASE_CONFIG;
+
+ const draw = () =>
+ root?.render(
+ <QueryClientProvider client={client}>
+ <ChakraProvider value={system}>
+ <DynamicPromptsButton
+ batchCount={2}
+ config={{
+ ...config,
+ onChange: (patch) => {
+ onChange(patch);
+ config = { ...config, ...patch };
+ void act(() => draw());
+ },
+ }}
+ positivePrompt="a {red|green} cat"
+ onInsertText={vi.fn()}
+ onUsePrompt={vi.fn()}
+ />
+ </ChakraProvider>
+ </QueryClientProvider>
+ );
+
+ await act(() => draw());
+};
+
+const openPopover = async () => {
+ await act(async () => {
+ await userEvent.click([...host!.querySelectorAll('button')].at(-1)!);
+ });
+};
+
+/**
+ * Segment labels intercept pointer events, so the visible text is the click
+ * target. i18n is not bootstrapped in browser tests, so labels render as keys —
+ * segments are addressed by their stable value instead.
+ */
+const segmentLabel = (value: string) =>
+ document.querySelector(`[data-scope="segment-group"][data-part="item-text"][id$=":radio:label:${value}"]`);
+
+const captureError = (event: ErrorEvent) => pageErrors.push(event.message);
+
+beforeEach(() => {
+ pageErrors.length = 0;
+ window.addEventListener('error', captureError);
+ parseDynamicPrompts.mockReset();
+ parseDynamicPrompts.mockResolvedValue({ error: null, prompts: ['a red cat', 'a green cat'] });
+});
+
+afterEach(async () => {
+ window.removeEventListener('error', captureError);
+ await act(() => root?.unmount());
+ host?.remove();
+ host = null;
+ root = null;
+});
+
+describe('dynamic prompts popover controls', () => {
+ it('switches seed behaviour without tearing down the widget', async () => {
+ // Regression: a Chakra Select here threw `r.options is not iterable` from
+ // syncSelectElement as the popover opened, taking the Generate widget down
+ // with it. A two-option choice is a segmented control now.
+ const onChange = vi.fn();
+
+ await render(onChange);
+ await openPopover();
+
+ for (const expected of ['per-image', 'per-iteration'] as const) {
+ const target = segmentLabel(expected);
+
+ expect(target, `${expected} should be rendered`).toBeTruthy();
+ await act(async () => {
+ await userEvent.click(target!);
+ });
+ expect(onChange).toHaveBeenCalledWith({ seedBehaviour: expected });
+ }
+
+ expect(pageErrors).toEqual([]);
+ expect(segmentLabel('preview'), 'popover should still be mounted').toBeTruthy();
+ });
+
+ it('never lets the shuffle button drive the mode row height', async () => {
+ // The button used to be ~8px taller than the segmented control beside it, so
+ // switching to Random visibly nudged the row. It is now always rendered (just
+ // hidden) and never taller than the control, so the row is governed by the
+ // segmented control in both modes.
+ await render();
+ await openPopover();
+
+ const segments = () => segmentLabel('all')!.closest('[data-scope="segment-group"][data-part="root"]')!;
+ const row = () => segments().parentElement!;
+ const heights = () => [row().getBoundingClientRect().height, segments().getBoundingClientRect().height];
+
+ const [combinatorialRow, combinatorialSegments] = heights();
+
+ expect(combinatorialRow).toBe(combinatorialSegments);
+
+ await act(async () => {
+ await userEvent.click(segmentLabel('random')!);
+ });
+
+ const [randomRow, randomSegments] = heights();
+
+ expect(randomRow).toBe(randomSegments);
+ });
+
+ it('keeps the tabs to their content width rather than stretching them', async () => {
+ await render(vi.fn());
+ await openPopover();
+
+ const tabs = segmentLabel('preview')!.closest('[data-scope="segment-group"][data-part="root"]')!;
+
+ // Asserting the computed alignment rather than a pixel width: browser tests
+ // render i18n keys, so the labels are not their real size here.
+ expect(getComputedStyle(tabs).alignSelf).toBe('start');
+ });
+});
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/DynamicPromptsPanel.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/DynamicPromptsPanel.tsx
new file mode 100644
index 0000000000..991b749e95
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/DynamicPromptsPanel.tsx
@@ -0,0 +1,217 @@
+import type { DynamicPromptsConfig } from '@features/generation/core/dynamicPrompts';
+import type { DynamicPromptsExpansion } from '@features/generation/ui/useDynamicPrompts';
+
+import { HStack, NumberInput, SegmentGroup, Stack, Text } from '@chakra-ui/react';
+import {
+ createDynamicPromptsSampleSeed,
+ DYNAMIC_PROMPTS_MAX_PROMPTS,
+ DYNAMIC_PROMPTS_MIN_PROMPTS,
+ sanitizeMaxPrompts,
+} from '@features/generation/core/dynamicPrompts';
+import { Button, IconButton } from '@platform/ui/Button';
+import { Scrollable } from '@platform/ui/Scrollable';
+import { Tooltip } from '@platform/ui/Tooltip';
+import { ShuffleIcon } from 'lucide-react';
+import { useCallback, useMemo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+/** Rendering every row of a 10,000-prompt expansion would cost more than it tells the user. */
+const MAX_PREVIEW_ROWS = 200;
+const TABULAR_NUMS = { fontVariantNumeric: 'tabular-nums' } as const;
+
+export interface DynamicPromptsFieldConfig extends DynamicPromptsConfig {
+ onChange: (patch: Partial<DynamicPromptsConfig>) => void;
+}
+
+export const DynamicPromptsPanel = ({
+ batchCount,
+ config,
+ expansion,
+ onUsePrompt,
+}: {
+ batchCount: number;
+ config: DynamicPromptsFieldConfig;
+ expansion: DynamicPromptsExpansion;
+ onUsePrompt: (prompt: string) => void;
+}) => {
+ const { t } = useTranslation();
+ const { onChange } = config;
+ const visiblePrompts = expansion.prompts.slice(0, MAX_PREVIEW_ROWS);
+ const hiddenPromptCount = expansion.prompts.length - visiblePrompts.length;
+
+ const handleModeChange = useCallback(
+ (event: { value: string | null }) => onChange({ combinatorial: event.value !== 'random' }),
+ [onChange]
+ );
+ const handleMaxPromptsChange = useCallback(
+ ({ valueAsNumber }: { valueAsNumber: number }) => {
+ if (Number.isFinite(valueAsNumber)) {
+ onChange({ maxPrompts: sanitizeMaxPrompts(valueAsNumber) });
+ }
+ },
+ [onChange]
+ );
+ const handleSeedBehaviourChange = useCallback(
+ (event: { value: string | null }) =>
+ onChange({ seedBehaviour: event.value === 'per-image' ? 'per-image' : 'per-iteration' }),
+ [onChange]
+ );
+ const handleShuffle = useCallback(() => onChange({ sampleSeed: createDynamicPromptsSampleSeed() }), [onChange]);
+
+ const modeItems = useMemo(
+ () => [
+ { label: t('widgets.generate.dynamicPrompts.allCombinations'), value: 'all' },
+ { label: t('widgets.generate.dynamicPrompts.randomSample'), value: 'random' },
+ ],
+ [t]
+ );
+ const seedItems = useMemo(
+ () => [
+ { label: t('widgets.generate.dynamicPrompts.seedPerIteration'), value: 'per-iteration' },
+ { label: t('widgets.generate.dynamicPrompts.seedPerImage'), value: 'per-image' },
+ ],
+ [t]
+ );
+ const maxPromptsLabel = config.combinatorial
+ ? t('widgets.generate.dynamicPrompts.maxPrompts')
+ : t('widgets.generate.dynamicPrompts.numberOfPrompts');
+
+ return (
+ <Stack gap="2.5">
+ <HStack justify="space-between">
+ <Text color="fg.subtle" fontSize="2xs" fontWeight="700" textTransform="uppercase">
+ {t('widgets.generate.dynamicPrompts.title')}
+ </Text>
+ <Text color="fg.muted" css={TABULAR_NUMS} fontSize="2xs">
+ {expansion.isLoading
+ ? t('widgets.generate.dynamicPrompts.expanding')
+ : t('widgets.generate.dynamicPrompts.summary', {
+ generations: expansion.count * batchCount,
+ iterations: batchCount,
+ prompts: expansion.count,
+ })}
+ </Text>
+ </HStack>
+
+ {/* Shuffle only means anything for a random sample, but it is always
+ rendered — merely hidden — so switching modes cannot change the row's
+ shape. `visibility: hidden` also takes it out of the tab order. */}
+ <HStack gap="2">
+ <SegmentGroup.Root
+ flex="1"
+ size="xs"
+ value={config.combinatorial ? 'all' : 'random'}
+ onValueChange={handleModeChange}
+ >
+ <SegmentGroup.Indicator />
+ <SegmentGroup.Items items={modeItems} />
+ </SegmentGroup.Root>
+ <Tooltip content={t('widgets.generate.dynamicPrompts.shuffle')}>
+ <IconButton
+ aria-label={t('widgets.generate.dynamicPrompts.shuffle')}
+ size="2xs"
+ variant="ghost"
+ visibility={config.combinatorial ? 'hidden' : 'visible'}
+ onClick={handleShuffle}
+ >
+ <ShuffleIcon />
+ </IconButton>
+ </Tooltip>
+ </HStack>
+
+ <HStack align="end" gap="2">
+ <Stack flex="1" gap="1" minW="0">
+ <Text color="fg.subtle" fontSize="2xs">
+ {maxPromptsLabel}
+ </Text>
+ <NumberInput.Root
+ allowMouseWheel
+ max={DYNAMIC_PROMPTS_MAX_PROMPTS}
+ min={DYNAMIC_PROMPTS_MIN_PROMPTS}
+ size="xs"
+ value={String(config.maxPrompts)}
+ onValueChange={handleMaxPromptsChange}
+ >
+ <NumberInput.Control />
+ <NumberInput.Input aria-label={maxPromptsLabel} paddingStart="2" />
+ </NumberInput.Root>
+ </Stack>
+ <Stack flex="1" gap="1" minW="0">
+ <Text color="fg.subtle" fontSize="2xs">
+ {t('widgets.generate.dynamicPrompts.seedBehaviour')}
+ </Text>
+ {/* A two-option choice reads better as a segmented control than a dropdown:
+ one click instead of two, and it matches the mode control above. */}
+ <SegmentGroup.Root
+ aria-label={t('widgets.generate.dynamicPrompts.seedBehaviour')}
+ size="xs"
+ value={config.seedBehaviour}
+ onValueChange={handleSeedBehaviourChange}
+ >
+ <SegmentGroup.Indicator />
+ <SegmentGroup.Items items={seedItems} />
+ </SegmentGroup.Root>
+ </Stack>
+ </HStack>
+
+ {expansion.isError ? (
+ <Text color="fg.error" fontSize="2xs">
+ {t('widgets.generate.dynamicPrompts.problemGeneratingPrompts')}
+ </Text>
+ ) : expansion.error ? (
+ <Text color="fg.error" fontSize="2xs" wordBreak="break-word">
+ {expansion.error}
+ </Text>
+ ) : null}
+
+ <Scrollable h="14rem" label={t('widgets.generate.dynamicPrompts.promptsPreview')}>
+ <Stack gap="0">
+ {visiblePrompts.map((prompt, index) => (
+ <DynamicPromptRow key={`${index}-${prompt}`} index={index} prompt={prompt} onUsePrompt={onUsePrompt} />
+ ))}
+ {hiddenPromptCount > 0 ? (
+ <Text color="fg.subtle" fontSize="2xs" px="2" py="1.5">
+ {t('widgets.generate.dynamicPrompts.andMore', { count: hiddenPromptCount })}
+ </Text>
+ ) : null}
+ </Stack>
+ </Scrollable>
+ </Stack>
+ );
+};
+
+const DynamicPromptRow = ({
+ index,
+ onUsePrompt,
+ prompt,
+}: {
+ index: number;
+ prompt: string;
+ onUsePrompt: (prompt: string) => void;
+}) => {
+ const { t } = useTranslation();
+ const handleClick = useCallback(() => onUsePrompt(prompt), [onUsePrompt, prompt]);
+
+ return (
+ <Button
+ alignItems="start"
+ gap="2"
+ h="auto"
+ justifyContent="start"
+ px="2"
+ py="1.5"
+ size="xs"
+ title={t('widgets.generate.dynamicPrompts.usePrompt')}
+ transitionDuration="faster"
+ variant="ghost"
+ onClick={handleClick}
+ >
+ <Text as="span" color="fg.subtle" css={TABULAR_NUMS} fontSize="2xs">
+ {index + 1}
+ </Text>
+ <Text as="span" color="fg" fontFamily="mono" fontSize="0.72rem" textAlign="start" wordBreak="break-word">
+ {prompt}
+ </Text>
+ </Button>
+ );
+};
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/GeneratePromptFields.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/GeneratePromptFields.tsx
index 5fb230de7a..f444b55dbf 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/GeneratePromptFields.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/GeneratePromptFields.tsx
@@ -27,6 +27,16 @@ interface GeneratePromptValues {
positivePromptHeightPx: number;
}
+/** The flat GenerateSettings field behind each dynamic prompts config key. */
+const DYNAMIC_PROMPT_SETTING_KEYS = {
+ combinatorial: 'dynamicPromptsCombinatorial',
+ maxPrompts: 'dynamicPromptsMaxPrompts',
+ sampleSeed: 'dynamicPromptsSampleSeed',
+ seedBehaviour: 'dynamicPromptsSeedBehaviour',
+} as const satisfies Record<keyof DynamicPromptsConfig, keyof GenerateSettings>;
+
+type DynamicPromptsConfigKey = keyof typeof DYNAMIC_PROMPT_SETTING_KEYS;
+
const getPromptValues = (values: Record<string, unknown>): GeneratePromptValues => ({
negativePrompt: typeof values.negativePrompt === 'string' ? values.negativePrompt : '',
negativePromptEnabled: values.negativePromptEnabled !== false,
@@ -65,12 +75,14 @@ export const GeneratePromptFields = ({
const handleDynamicPromptsChange = useCallback(
(patch: Partial<DynamicPromptsConfig>) =>
- onCommitImmediate({
- ...(patch.combinatorial === undefined ? {} : { dynamicPromptsCombinatorial: patch.combinatorial }),
- ...(patch.maxPrompts === undefined ? {} : { dynamicPromptsMaxPrompts: patch.maxPrompts }),
- ...(patch.sampleSeed === undefined ? {} : { dynamicPromptsSampleSeed: patch.sampleSeed }),
- ...(patch.seedBehaviour === undefined ? {} : { dynamicPromptsSeedBehaviour: patch.seedBehaviour }),
- }),
+ onCommitImmediate(
+ Object.fromEntries(
+ Object.entries(patch).map(([key, value]) => [
+ DYNAMIC_PROMPT_SETTING_KEYS[key as DynamicPromptsConfigKey],
+ value,
+ ])
+ )
+ ),
[onCommitImmediate]
);
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptActions.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptActions.tsx
index da46a458cc..1ab98e9aac 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptActions.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptActions.tsx
@@ -1,16 +1,14 @@
/* eslint-disable react/react-compiler */
import type { GenerationModelCatalogItem as ModelConfig, PromptHistoryItem } from '@features/generation/contracts';
import type { GenerateLora, GenerateModelConfig } from '@features/generation/core/types';
+import type { DynamicPromptsFieldConfig } from '@features/generation/ui/promptFields/DynamicPromptsPanel';
import type { ChangeEvent, MouseEvent } from 'react';
import { HStack, Icon, Image, Input, Popover, Portal, Separator, Stack, Text } from '@chakra-ui/react';
import { filterPromptHistory } from '@features/generation/core/promptHistory';
import { expandPrompt, imageToPrompt } from '@features/generation/data/promptUtilities';
import { GenerationModelSelect as ModelSelect, useGenerationUi } from '@features/generation/ui/GenerationUiContext';
-import {
- DynamicPromptsButton,
- type DynamicPromptsFieldConfig,
-} from '@features/generation/ui/promptFields/DynamicPromptsButton';
+import { DynamicPromptsButton } from '@features/generation/ui/promptFields/DynamicPromptsButton';
import { useWildcards } from '@features/generation/ui/useWildcards';
import { useMountEffect } from '@platform/react/useMountEffect';
import { getApiErrorMessage } from '@platform/transport/http';
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptField.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptField.tsx
index 46d503053f..329dbd3e2b 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptField.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptField.tsx
@@ -9,7 +9,7 @@ import { Field } from '@platform/ui';
import { useCallback, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
-import type { DynamicPromptsFieldConfig } from './DynamicPromptsButton';
+import type { DynamicPromptsFieldConfig } from './DynamicPromptsPanel';
import { PositivePromptActions, PromptTriggerPopover } from './PositivePromptActions';
import { PROMPT_ATTENTION_TARGET_PROPS } from './promptAttentionHotkeys';