fix: 处理频繁更新导致节点闪烁的问题

master
钟良源 4 weeks ago
parent 406b88e0cf
commit 294894ea56

@ -548,8 +548,13 @@ export const useFlowCallbacks = (
// 实时更新 canvasDataMap // 实时更新 canvasDataMap
const updateCanvasDataMapEffect = useCallback(() => { const updateCanvasDataMapEffect = useCallback(() => {
const appKey = getCurrentFlowAppKey(); const appKey = getCurrentFlowAppKey();
const { appRuntimeData } = store.getState().ideContainer;
const isCurrentAppRunning =
appKey && appRuntimeData[appKey]?.isRunning;
if ( if (
appKey && appKey &&
!isCurrentAppRunning &&
shouldPersistCanvas({ nodes, edges }) shouldPersistCanvas({ nodes, edges })
) { ) {
updateCanvasDataMapDebounced( updateCanvasDataMapDebounced(

@ -61,7 +61,9 @@ export const useFlowEditorState = (initialData?: any, readOnly?: boolean) => {
Object.values(initialData.components).some((comp: any) => comp.status); Object.values(initialData.components).some((comp: any) => comp.status);
setNodes((prevNodes) => { setNodes((prevNodes) => {
return prevNodes.map((node) => { let hasChanges = false;
const nextNodes = prevNodes.map((node) => {
// 如果是只读模式(历史实例查看),优先使用节点自身的历史状态 // 如果是只读模式(历史实例查看),优先使用节点自身的历史状态
// 如果是正常运行模式,只使用运行时状态 // 如果是正常运行模式,只使用运行时状态
let nodeStatus = 'waiting'; let nodeStatus = 'waiting';
@ -80,6 +82,14 @@ export const useFlowEditorState = (initialData?: any, readOnly?: boolean) => {
showStatus = currentAppIsRunning; showStatus = currentAppIsRunning;
} }
if (
node.data.status === nodeStatus &&
node.data.isStatusVisible === showStatus
) {
return node;
}
hasChanges = true;
return { return {
...node, ...node,
data: { data: {
@ -89,6 +99,8 @@ export const useFlowEditorState = (initialData?: any, readOnly?: boolean) => {
}, },
}; };
}); });
return hasChanges ? nextNodes : prevNodes;
}); });
}, [ }, [
appRuntimeData, appRuntimeData,

@ -4,7 +4,6 @@ import {
updateSocketId, updateSocketId,
updateNodeStatus, updateNodeStatus,
updateEventListOld, updateEventListOld,
resetNodeStatus,
updateRuntimeId, updateRuntimeId,
updateIsRunning updateIsRunning
} from '@/store/ideContainer'; } from '@/store/ideContainer';
@ -149,7 +148,6 @@ function IDEContainer() {
const reconnectRuntime = async () => { const reconnectRuntime = async () => {
try { try {
dispatch(resetNodeStatus());
dispatch(updateRuntimeId(reconnectRequest.instanceId)); dispatch(updateRuntimeId(reconnectRequest.instanceId));
dispatch(updateIsRunning(true)); dispatch(updateIsRunning(true));

Loading…
Cancel
Save