diff --git a/src/frontend/src/components/promptComponent/index.tsx b/src/frontend/src/components/promptComponent/index.tsx index 3f0742407..5cea7008c 100644 --- a/src/frontend/src/components/promptComponent/index.tsx +++ b/src/frontend/src/components/promptComponent/index.tsx @@ -6,6 +6,8 @@ import { TypeModal } from "../../utils"; import { INPUT_STYLE } from "../../constants"; import { ExternalLink } from "lucide-react"; import { postValidatePrompt } from "../../controllers/API"; +import { typesContext } from "../../contexts/typesContext"; +import * as _ from "lodash"; export default function PromptAreaComponent({ setNodeClass, @@ -15,8 +17,10 @@ export default function PromptAreaComponent({ disabled, editNode = false, }: TextAreaComponentType) { - const [myValue, setMyValue] = useState(value); + const [myValue, setMyValue] = useState(""); const { openPopUp } = useContext(PopUpContext); + const { reactFlowInstance } = useContext(typesContext); + useEffect(() => { if (disabled) { setMyValue(""); @@ -25,20 +29,21 @@ export default function PromptAreaComponent({ }, [disabled, onChange]); useEffect(() => { - if (value) { - postValidatePrompt(myValue, nodeClass) + if (value !== "") { // only executed once + setMyValue(value); + postValidatePrompt(value, nodeClass) .then((apiReturn) => { if (apiReturn.data) { setNodeClass(apiReturn.data.frontend_node); + if(reactFlowInstance){ + // need to update reactFlowInstance to re-render the nodes. + reactFlowInstance.setEdges(_.cloneDeep(reactFlowInstance.getEdges())); + } } }) .catch((error) => {}); } - }, [value]); - - useEffect(() => { - setMyValue(value); - }, [value]); + }, [reactFlowInstance]); return (