diff --git a/src/pages/flowEditor/components/historyContext.tsx b/src/pages/flowEditor/components/historyContext.tsx index 35bb9ca..00ba4b3 100644 --- a/src/pages/flowEditor/components/historyContext.tsx +++ b/src/pages/flowEditor/components/historyContext.tsx @@ -1,4 +1,5 @@ import React, { createContext, useContext, useState, useCallback, useRef, useEffect } from 'react'; +import { debounce } from 'lodash'; import { Node, Edge } from '@xyflow/react'; interface HistoryContextType { @@ -147,11 +148,11 @@ const HistoryProvider: React.FC = ({ // 监听 takeSnapshot 事件 useEffect(() => { - const handleTakeSnapshot = ((event: CustomEvent) => { + const handleTakeSnapshot = debounce((event: CustomEvent) => { const { nodes, edges } = event.detail; updateCurrentState(nodes, edges); takeSnapshot(); - }) as EventListener; + }, 100) as EventListener; document.addEventListener('takeSnapshot', handleTakeSnapshot); return () => {