mirror of
https://github.com/langgenius/dify.git
synced 2026-05-05 01:48:04 +08:00
fix: can not save when switch to skill
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import {
|
||||
useCallback,
|
||||
useEffect,
|
||||
useRef,
|
||||
} from 'react'
|
||||
|
||||
@ -8,15 +9,25 @@ export const useSerialAsyncCallback = <Args extends any[], Result = void>(
|
||||
shouldSkip?: () => boolean,
|
||||
) => {
|
||||
const queueRef = useRef<Promise<unknown>>(Promise.resolve())
|
||||
const fnRef = useRef(fn)
|
||||
const shouldSkipRef = useRef(shouldSkip)
|
||||
|
||||
useEffect(() => {
|
||||
fnRef.current = fn
|
||||
}, [fn])
|
||||
|
||||
useEffect(() => {
|
||||
shouldSkipRef.current = shouldSkip
|
||||
}, [shouldSkip])
|
||||
|
||||
return useCallback((...args: Args) => {
|
||||
if (shouldSkip?.())
|
||||
if (shouldSkipRef.current?.())
|
||||
return Promise.resolve(undefined as Result)
|
||||
|
||||
const lastPromise = queueRef.current.catch(() => undefined)
|
||||
const nextPromise = lastPromise.then(() => fn(...args))
|
||||
const nextPromise = lastPromise.then(() => fnRef.current(...args))
|
||||
queueRef.current = nextPromise
|
||||
|
||||
return nextPromise
|
||||
}, [fn, shouldSkip])
|
||||
}, [])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user