diff --git a/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/chart-view.tsx b/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/chart-view.tsx index b6e902f456..8d0e67be1c 100644 --- a/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/chart-view.tsx +++ b/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/chart-view.tsx @@ -37,7 +37,7 @@ export default function ChartView({ appId, headerRight }: IChartViewProps) { const appDetail = useAppStore(state => state.appDetail) const isChatApp = appDetail?.mode !== 'completion' && appDetail?.mode !== 'workflow' const isWorkflow = appDetail?.mode === 'workflow' - const [period, setPeriod] = useState(IS_CLOUD_EDITION + const [period, setPeriod] = useState(() => IS_CLOUD_EDITION ? { name: t('filter.period.today', { ns: 'appLog' }), query: { start: today.startOf('day').format(queryDateFormat), end: today.endOf('day').format(queryDateFormat) } } : { name: t('filter.period.last7days', { ns: 'appLog' }), query: { start: today.subtract(7, 'day').startOf('day').format(queryDateFormat), end: today.endOf('day').format(queryDateFormat) } }, ) diff --git a/web/app/components/app/configuration/index.tsx b/web/app/components/app/configuration/index.tsx index aa1bbe0a16..1652195030 100644 --- a/web/app/components/app/configuration/index.tsx +++ b/web/app/components/app/configuration/index.tsx @@ -180,7 +180,7 @@ const Configuration: FC = () => { doSetCompletionParams(params) } - const [modelConfig, doSetModelConfig] = useState({ + const [modelConfig, doSetModelConfig] = useState(() => ({ provider: 'langgenius/openai/openai', model_id: 'gpt-3.5-turbo', mode: ModelModeType.unset, @@ -210,7 +210,7 @@ const Configuration: FC = () => { }, dataSets: [], agentConfig: DEFAULT_AGENT_SETTING, - }) + })) const isAgent = mode === AppModeEnum.AGENT_CHAT const isOpenAI = modelConfig.provider === 'langgenius/openai/openai' diff --git a/web/app/components/app/workflow-log/filter.spec.tsx b/web/app/components/app/workflow-log/filter.spec.tsx index 488b8856b7..272d1c9ebe 100644 --- a/web/app/components/app/workflow-log/filter.spec.tsx +++ b/web/app/components/app/workflow-log/filter.spec.tsx @@ -295,7 +295,7 @@ describe('Filter', () => { const setQueryParams = vi.fn() const Wrapper = () => { - const [queryParams, updateQueryParams] = useState(createDefaultQueryParams()) + const [queryParams, updateQueryParams] = useState(() => createDefaultQueryParams()) const handleSetQueryParams = (next: QueryParam) => { updateQueryParams(next) setQueryParams(next) diff --git a/web/app/components/base/error-boundary/index.tsx b/web/app/components/base/error-boundary/index.tsx index 9cb4b70cf5..27793bece5 100644 --- a/web/app/components/base/error-boundary/index.tsx +++ b/web/app/components/base/error-boundary/index.tsx @@ -210,8 +210,8 @@ const ErrorBoundary: React.FC = (props) => { return ( diff --git a/web/app/components/base/toast/index.tsx b/web/app/components/base/toast/index.tsx index 0cb14f3f11..b989975d9c 100644 --- a/web/app/components/base/toast/index.tsx +++ b/web/app/components/base/toast/index.tsx @@ -99,9 +99,10 @@ export const ToastProvider = ({ useEffect(() => { if (mounted) { - setTimeout(() => { + const timer = setTimeout(() => { setMounted(false) }, params.duration || defaultDuring) + return () => clearTimeout(timer) } }, [defaultDuring, mounted, params.duration]) diff --git a/web/app/components/plugins/install-plugin/install-from-github/index.tsx b/web/app/components/plugins/install-plugin/install-from-github/index.tsx index 91425031cf..a047794a6e 100644 --- a/web/app/components/plugins/install-plugin/install-from-github/index.tsx +++ b/web/app/components/plugins/install-plugin/install-from-github/index.tsx @@ -41,7 +41,7 @@ const InstallFromGitHub: React.FC = ({ updatePayload, on handleStartToInstall, } = useHideLogic(onClose) - const [state, setState] = useState({ + const [state, setState] = useState(() => ({ step: updatePayload ? InstallStepFromGitHub.selectPackage : InstallStepFromGitHub.setUrl, repoUrl: updatePayload?.originalPackageInfo?.repo ? convertRepoToUrl(updatePayload.originalPackageInfo.repo) @@ -49,7 +49,7 @@ const InstallFromGitHub: React.FC = ({ updatePayload, on selectedVersion: '', selectedPackage: '', releases: updatePayload ? updatePayload.originalPackageInfo.releases : [], - }) + })) const [uniqueIdentifier, setUniqueIdentifier] = useState(null) const [manifest, setManifest] = useState(null) const [errorMsg, setErrorMsg] = useState(null) diff --git a/web/app/components/plugins/plugin-detail-panel/subscription-list/log-viewer.tsx b/web/app/components/plugins/plugin-detail-panel/subscription-list/log-viewer.tsx index 3b4edd1b85..e802a68db1 100644 --- a/web/app/components/plugins/plugin-detail-panel/subscription-list/log-viewer.tsx +++ b/web/app/components/plugins/plugin-detail-panel/subscription-list/log-viewer.tsx @@ -28,7 +28,7 @@ enum LogTypeEnum { const LogViewer = ({ logs, className }: Props) => { const { t } = useTranslation() - const [expandedLogs, setExpandedLogs] = useState>(new Set()) + const [expandedLogs, setExpandedLogs] = useState>(() => new Set()) const toggleLogExpansion = (logId: string) => { const newExpanded = new Set(expandedLogs) diff --git a/web/app/components/workflow/nodes/agent/node.tsx b/web/app/components/workflow/nodes/agent/node.tsx index 9f5d7a3ca1..7c6a4b6e0a 100644 --- a/web/app/components/workflow/nodes/agent/node.tsx +++ b/web/app/components/workflow/nodes/agent/node.tsx @@ -105,8 +105,8 @@ const AgentNode: FC> = (props) => { {models.map((model) => { return ( ) })} @@ -120,7 +120,7 @@ const AgentNode: FC> = (props) => { )} >
- {tools.map((tool, i) => )} + {tools.map((tool, i) => )}
)} diff --git a/web/app/components/workflow/note-node/note-editor/plugins/link-editor-plugin/hooks.ts b/web/app/components/workflow/note-node/note-editor/plugins/link-editor-plugin/hooks.ts index 511940d142..94f6fd673b 100644 --- a/web/app/components/workflow/note-node/note-editor/plugins/link-editor-plugin/hooks.ts +++ b/web/app/components/workflow/note-node/note-editor/plugins/link-editor-plugin/hooks.ts @@ -24,9 +24,12 @@ export const useOpenLink = () => { const noteEditorStore = useNoteEditorStore() useEffect(() => { - return mergeRegister( + let updateTimer: ReturnType + let clickTimer: ReturnType + + const unregister = mergeRegister( editor.registerUpdateListener(() => { - setTimeout(() => { + updateTimer = setTimeout(() => { const { selectedLinkUrl, selectedIsLink, @@ -51,7 +54,7 @@ export const useOpenLink = () => { editor.registerCommand( CLICK_COMMAND, (payload) => { - setTimeout(() => { + clickTimer = setTimeout(() => { const { selectedLinkUrl, selectedIsLink, @@ -81,6 +84,12 @@ export const useOpenLink = () => { COMMAND_PRIORITY_LOW, ), ) + + return () => { + clearTimeout(updateTimer) + clearTimeout(clickTimer) + unregister() + } }, [editor, noteEditorStore]) } diff --git a/web/app/signup/check-code/page.tsx b/web/app/signup/check-code/page.tsx index f4cc272e5a..615b174288 100644 --- a/web/app/signup/check-code/page.tsx +++ b/web/app/signup/check-code/page.tsx @@ -16,7 +16,7 @@ export default function CheckCode() { const router = useRouter() const searchParams = useSearchParams() const email = decodeURIComponent(searchParams.get('email') as string) - const [token, setToken] = useState(decodeURIComponent(searchParams.get('token') as string)) + const [token, setToken] = useState(() => decodeURIComponent(searchParams.get('token') as string)) const [code, setVerifyCode] = useState('') const [loading, setIsLoading] = useState(false) const locale = useLocale()