From 682ebc5f64d068c8add634ec513b41ef8d6cf2ab Mon Sep 17 00:00:00 2001 From: Wood Date: Sat, 4 Jan 2025 11:55:55 +0800 Subject: [PATCH] Fix the issue where `TextGeneration` component does not correctly clear input data. (#12351) --- web/app/components/share/text-generation/index.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/web/app/components/share/text-generation/index.tsx b/web/app/components/share/text-generation/index.tsx index 27ea46cbff12da..16571b64519cb4 100644 --- a/web/app/components/share/text-generation/index.tsx +++ b/web/app/components/share/text-generation/index.tsx @@ -1,6 +1,6 @@ 'use client' import type { FC } from 'react' -import React, { useEffect, useRef, useState } from 'react' +import React, { useCallback, useEffect, useRef, useState } from 'react' import { useTranslation } from 'react-i18next' import { RiErrorWarningFill, @@ -93,8 +93,12 @@ const TextGeneration: FC = ({ // Notice this situation isCallBatchAPI but not in batch tab const [isCallBatchAPI, setIsCallBatchAPI] = useState(false) const isInBatchTab = currentTab === 'batch' - const [inputs, setInputs] = useState>({}) + const [inputs, doSetInputs] = useState>({}) const inputsRef = useRef(inputs) + const setInputs = useCallback((newInputs: Record) => { + doSetInputs(newInputs) + inputsRef.current = newInputs + }, []) const [appId, setAppId] = useState('') const [siteInfo, setSiteInfo] = useState(null) const [canReplaceLogo, setCanReplaceLogo] = useState(false)