mirror of
https://github.com/invoke-ai/InvokeAI.git
synced 2026-04-23 03:00:31 -04:00
fix(ui): dynamic prompts infinite recursion (wip)
This commit is contained in:
@@ -29,8 +29,7 @@ export const StringGeneratorDynamicPromptsCombinatorialSettings = memo(
|
||||
);
|
||||
|
||||
const arg = useMemo(() => {
|
||||
const { input, maxPrompts } = state;
|
||||
return { prompt: input, max_prompts: maxPrompts, combinatorial: true };
|
||||
return { prompt: state.input, max_prompts: state.maxPrompts, combinatorial: true };
|
||||
}, [state]);
|
||||
const [debouncedArg] = useDebounce(arg, 300);
|
||||
|
||||
@@ -38,13 +37,16 @@ export const StringGeneratorDynamicPromptsCombinatorialSettings = memo(
|
||||
|
||||
useEffect(() => {
|
||||
if (isLoading) {
|
||||
onChange({ ...state, values: loadingValues });
|
||||
} else if (data) {
|
||||
onChange({ ...state, values: data.prompts });
|
||||
} else {
|
||||
onChange({ ...state, values: [] });
|
||||
return;
|
||||
}
|
||||
}, [data, isLoading, loadingValues, onChange, state]);
|
||||
|
||||
if (!data) {
|
||||
onChange({ ...state, values: [] });
|
||||
return;
|
||||
}
|
||||
|
||||
onChange({ ...state, values: data.prompts });
|
||||
}, [data, isLoading, onChange, state]);
|
||||
|
||||
return (
|
||||
<Flex gap={2} flexDir="column">
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Checkbox, CompositeNumberInput, Flex, FormControl, FormLabel } from '@invoke-ai/ui-library';
|
||||
import { GeneratorTextareaWithFileUpload } from 'features/nodes/components/flow/nodes/Invocation/fields/inputs/GeneratorTextareaWithFileUpload';
|
||||
import { useViewContext } from 'features/nodes/contexts/ViewContext';
|
||||
import type { StringGeneratorDynamicPromptsRandom } from 'features/nodes/types/field';
|
||||
import { isNil, random } from 'lodash-es';
|
||||
import { memo, useCallback, useEffect, useMemo } from 'react';
|
||||
@@ -14,6 +15,7 @@ type StringGeneratorDynamicPromptsRandomSettingsProps = {
|
||||
export const StringGeneratorDynamicPromptsRandomSettings = memo(
|
||||
({ state, onChange }: StringGeneratorDynamicPromptsRandomSettingsProps) => {
|
||||
const { t } = useTranslation();
|
||||
const view = useViewContext();
|
||||
const loadingValues = useMemo(() => [`<${t('nodes.generatorLoading')}>`], [t]);
|
||||
|
||||
const onChangeInput = useCallback(
|
||||
@@ -39,22 +41,25 @@ export const StringGeneratorDynamicPromptsRandomSettings = memo(
|
||||
);
|
||||
|
||||
const arg = useMemo(() => {
|
||||
const { input, count, seed } = state;
|
||||
return { prompt: input, max_prompts: count, combinatorial: false, seed: seed ?? random() };
|
||||
}, [state]);
|
||||
return { prompt: state.input, max_prompts: state.count, combinatorial: false, seed: state.seed ?? random() };
|
||||
}, [state.count, state.input, state.seed]);
|
||||
|
||||
const [debouncedArg] = useDebounce(arg, 300);
|
||||
|
||||
const { data, isLoading } = useDynamicPromptsQuery(debouncedArg);
|
||||
|
||||
useEffect(() => {
|
||||
if (isLoading) {
|
||||
onChange({ ...state, values: loadingValues });
|
||||
} else if (data) {
|
||||
onChange({ ...state, values: data.prompts });
|
||||
} else {
|
||||
onChange({ ...state, values: [] });
|
||||
return;
|
||||
}
|
||||
}, [data, isLoading, loadingValues, onChange, state]);
|
||||
|
||||
if (!data) {
|
||||
onChange({ ...state, values: [] });
|
||||
return;
|
||||
}
|
||||
|
||||
onChange({ ...state, values: data.prompts });
|
||||
}, [data, isLoading, onChange, state, view]);
|
||||
|
||||
return (
|
||||
<Flex gap={2} flexDir="column">
|
||||
|
||||
Reference in New Issue
Block a user