refactor(web): avoid setState in website crawler effects (#39237)

Co-authored-by: Wu Tianwei <30284043+WTW0313@users.noreply.github.com>
This commit is contained in:
Wan Xiankai 2026-07-20 14:26:50 +08:00 committed by GitHub
parent 15674a9db6
commit 605c0fe02b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 15 deletions

View File

@ -2474,9 +2474,6 @@
}
},
"web/app/components/datasets/create/website/firecrawl/index.tsx": {
"eslint-react/set-state-in-effect": {
"count": 1
},
"no-console": {
"count": 1
},
@ -2506,9 +2503,6 @@
}
},
"web/app/components/datasets/create/website/watercrawl/index.tsx": {
"eslint-react/set-state-in-effect": {
"count": 1
},
"no-console": {
"count": 1
},

View File

@ -33,6 +33,11 @@ const Step = {
finished: 'finished',
} as const
type Step = (typeof Step)[keyof typeof Step]
const STEP_CONTROL_FOLD_OPTIONS: Record<Step, number> = {
[Step.init]: 0,
[Step.running]: 1,
[Step.finished]: 2,
}
type CrawlState = {
current: number
total: number
@ -57,11 +62,8 @@ const FireCrawl: FC<Props> = ({
}) => {
const { t } = useTranslation()
const [step, setStep] = useState<Step>(Step.init)
const [controlFoldOptions, setControlFoldOptions] = useState<number>(0)
const controlFoldOptions = STEP_CONTROL_FOLD_OPTIONS[step]
const isMountedRef = useRef(true)
useEffect(() => {
if (step !== Step.init) setControlFoldOptions(Date.now())
}, [step])
useEffect(() => {
return () => {
isMountedRef.current = false

View File

@ -3,7 +3,7 @@ import type { FC } from 'react'
import type { CrawlOptions, CrawlResultItem } from '@/models/datasets'
import { toast } from '@langgenius/dify-ui/toast'
import * as React from 'react'
import { useCallback, useEffect, useState } from 'react'
import { useCallback, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { ACCOUNT_SETTING_TAB } from '@/app/components/header/account-setting/constants'
import { useIntegrationsSetting } from '@/app/components/header/account-setting/use-integrations-setting'
@ -33,6 +33,11 @@ const Step = {
finished: 'finished',
} as const
type Step = (typeof Step)[keyof typeof Step]
const STEP_CONTROL_FOLD_OPTIONS: Record<Step, number> = {
[Step.init]: 0,
[Step.running]: 1,
[Step.finished]: 2,
}
const WaterCrawl: FC<Props> = ({
onPreview,
checkedCrawlResult,
@ -43,10 +48,7 @@ const WaterCrawl: FC<Props> = ({
}) => {
const { t } = useTranslation()
const [step, setStep] = useState<Step>(Step.init)
const [controlFoldOptions, setControlFoldOptions] = useState<number>(0)
useEffect(() => {
if (step !== Step.init) setControlFoldOptions(Date.now())
}, [step])
const controlFoldOptions = STEP_CONTROL_FOLD_OPTIONS[step]
const openIntegrationsSetting = useIntegrationsSetting()
const handleSetting = useCallback(() => {
openIntegrationsSetting({