mirror of
https://github.com/langgenius/dify.git
synced 2026-05-01 07:58:02 +08:00
When switching from graph view to skill view during an active preview run, SSE callbacks continue executing and attempt to update ReactFlow node/edge states. This could cause errors since the component is unmounted. Add optional `isMountedRef` parameter to `useNodesInteractionsWithoutSync` and `useEdgesInteractionsWithoutSync` hooks. When provided, operations are skipped if the component has unmounted, preventing potential errors while allowing the SSE connection to continue running in the background. BREAKING CHANGE: `useNodesInteractionsWithoutSync` and `useEdgesInteractionsWithoutSync` now accept an optional `isMountedRef` parameter. Existing callers are unaffected as the parameter is optional.
32 lines
805 B
TypeScript
32 lines
805 B
TypeScript
import type { RefObject } from 'react'
|
|
import { produce } from 'immer'
|
|
import { useCallback } from 'react'
|
|
import { useStoreApi } from 'reactflow'
|
|
|
|
export const useEdgesInteractionsWithoutSync = (isMountedRef?: RefObject<boolean>) => {
|
|
const store = useStoreApi()
|
|
|
|
const handleEdgeCancelRunningStatus = useCallback(() => {
|
|
if (isMountedRef && isMountedRef.current === false)
|
|
return
|
|
|
|
const {
|
|
edges,
|
|
setEdges,
|
|
} = store.getState()
|
|
|
|
const newEdges = produce(edges, (draft) => {
|
|
draft.forEach((edge) => {
|
|
edge.data._sourceRunningStatus = undefined
|
|
edge.data._targetRunningStatus = undefined
|
|
edge.data._waitingRun = false
|
|
})
|
|
})
|
|
setEdges(newEdges)
|
|
}, [store, isMountedRef])
|
|
|
|
return {
|
|
handleEdgeCancelRunningStatus,
|
|
}
|
|
}
|