fix(ui): dynamic prompts infinite recursion (wip)

This commit is contained in:
psychedelicious
2025-01-21 08:06:33 +11:00
parent 2a9f2b2fe2
commit 6e1388f4fc
2 changed files with 24 additions and 17 deletions

View File

@@ -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">

View File

@@ -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">