Skip to content
This repository was archived by the owner on Mar 18, 2026. It is now read-only.

Commit 7652535

Browse files
authored
Merge pull request #260 from X2bee/main
fix: Xgen Node
2 parents 92926f1 + cce7be8 commit 7652535

File tree

1 file changed

+33
-10
lines changed

1 file changed

+33
-10
lines changed

src/app/canvas/components/SpecialNode/AgentXgenNode.tsx

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { memo, useState, useMemo, useEffect } from 'react';
1+
import React, { memo, useState, useMemo, useEffect, useRef } from 'react';
22
import styles from '@/app/canvas/assets/Node.module.scss';
33
import type { NodeProps, Port } from '@/app/canvas/types';
44
import { useNodeEditing } from '@/app/canvas/components/Node/hooks/useNodeEditing';
@@ -19,6 +19,11 @@ import { NodeParameters } from '@/app/canvas/components/Node/components/NodePara
1919
* streaming 파라미터 값에 따라 output을 동적으로 변경합니다.
2020
* - streaming = true: {"id": "stream", "name": "Stream", "type": "STREAM STR", "stream": true}
2121
* - streaming = false: {"id": "result", "name": "Result", "type": "STR"}
22+
*
23+
* 프로덕션 환경 호환성:
24+
* - useRef를 사용하여 onOutputsUpdate 함수의 최신 참조 유지
25+
* - streamingValue만 의존성으로 사용하여 불필요한 재렌더링 방지
26+
* - outputs 업데이트는 실제 값 변경 시에만 실행
2227
*/
2328
const AgentXgenNode: React.FC<NodeProps & {
2429
onOutputsUpdate?: (nodeId: string, outputs: Port[]) => void;
@@ -55,16 +60,24 @@ const AgentXgenNode: React.FC<NodeProps & {
5560
const { nodeName, inputs, parameters, outputs, functionId } = data;
5661
const [showAdvanced, setShowAdvanced] = useState<boolean>(false);
5762

63+
// Ref to store the latest onOutputsUpdate function
64+
const onOutputsUpdateRef = useRef(onOutputsUpdate);
65+
useEffect(() => {
66+
onOutputsUpdateRef.current = onOutputsUpdate;
67+
}, [onOutputsUpdate]);
68+
5869
// Custom hooks
5970
const nodeEditingHook = useNodeEditing(nodeName);
6071

61-
// streaming 파라미터 값에 따라 outputs를 동적으로 생성
62-
const dynamicOutputs = useMemo((): Port[] => {
63-
// streaming 파라미터 찾기
72+
// streaming 파라미터의 값만 추출 (안정적인 값 비교를 위해)
73+
const streamingValue = useMemo(() => {
6474
const streamingParam = parameters?.find(p => p.id === 'streaming');
65-
const isStreaming = streamingParam?.value ?? true; // 기본값 true
75+
return streamingParam?.value ?? true; // 기본값 true
76+
}, [parameters]);
6677

67-
if (isStreaming) {
78+
// streaming 파라미터 값에 따라 outputs를 동적으로 생성
79+
const dynamicOutputs = useMemo((): Port[] => {
80+
if (streamingValue) {
6881
return [
6982
{
7083
id: 'stream',
@@ -82,18 +95,28 @@ const AgentXgenNode: React.FC<NodeProps & {
8295
}
8396
];
8497
}
85-
}, [parameters]);
98+
}, [streamingValue]);
8699

87100
// streaming 파라미터 변경 시 실제 노드 데이터의 outputs 업데이트
88101
useEffect(() => {
102+
const updateFn = onOutputsUpdateRef.current;
103+
if (!updateFn) return;
104+
89105
// outputs가 실제로 변경되었는지 확인
90106
const currentOutputId = outputs?.[0]?.id;
91107
const newOutputId = dynamicOutputs[0]?.id;
92108

93-
if (currentOutputId !== newOutputId && onOutputsUpdate) {
94-
onOutputsUpdate(id, dynamicOutputs);
109+
// 현재 outputs와 새로운 outputs가 다를 때만 업데이트
110+
if (currentOutputId !== newOutputId) {
111+
console.log('[AgentXgenNode] Updating outputs:', {
112+
nodeId: id,
113+
from: currentOutputId,
114+
to: newOutputId,
115+
streaming: streamingValue
116+
});
117+
updateFn(id, dynamicOutputs);
95118
}
96-
}, [dynamicOutputs, outputs, id, onOutputsUpdate]);
119+
}, [streamingValue, id, dynamicOutputs, outputs]);
97120

98121
// Event handlers
99122
const handleMouseDown = (e: React.MouseEvent): void => {

0 commit comments

Comments
 (0)