1- import { useEffect } from "react" ;
1+ import { useEffect , useRef } from "react" ;
22
33import { useDebounce } from "@/hooks/use-debounce" ;
44import {
@@ -41,6 +41,9 @@ const stickerStyle = {
4141export default function CustomNode ( props : CustomNodeProps ) {
4242 const nodeData = props . data as unknown as NodeData ;
4343
44+ const previousPositionRef = useRef < { posX : number ; posY : number } | null > ( null ) ;
45+ const previousSizeRef = useRef < { width : number ; height : number } | null > ( null ) ;
46+
4447 const connection = useConnection ( ) ;
4548
4649 // 콘텐츠 위치, 크기 변경 시 호출
@@ -64,11 +67,32 @@ export default function CustomNode(props: CustomNodeProps) {
6467
6568 // 위치 변경 시 updateContentPosition 호출
6669 useEffect ( ( ) => {
67- const body = {
68- topicId : props . topicId ,
70+ const currentPosition = {
6971 posX : debouncedProps . positionAbsoluteX ,
7072 posY : debouncedProps . positionAbsoluteY ,
7173 } ;
74+
75+ // 초기 마운트 시에는 이전 위치를 저장하고 API 호출하지 않음
76+ if ( previousPositionRef . current === null ) {
77+ previousPositionRef . current = currentPosition ;
78+ return ;
79+ }
80+
81+ // 위치가 실제로 변경되지 않았으면 API 호출하지 않음
82+ if (
83+ previousPositionRef . current . posX === currentPosition . posX &&
84+ previousPositionRef . current . posY === currentPosition . posY
85+ ) {
86+ return ;
87+ }
88+
89+ previousPositionRef . current = currentPosition ;
90+
91+ const body = {
92+ topicId : props . topicId ,
93+ ...currentPosition ,
94+ } ;
95+
7296 const updatePosition = async ( ) => {
7397 switch ( nodeData . nodeContent ) {
7498 case "topic" :
@@ -90,16 +114,40 @@ export default function CustomNode(props: CustomNodeProps) {
90114 return ;
91115 }
92116 } ;
117+
93118 updatePosition ( ) ;
119+
120+ // eslint-disable-next-line react-hooks/exhaustive-deps
94121 } , [ debouncedProps . positionAbsoluteX , debouncedProps . positionAbsoluteY ] ) ;
95122
96123 // 크기 변경 시 updateContentSize 호출
97124 useEffect ( ( ) => {
98- const body = {
99- topicId : props . topicId ,
125+ const currentSize = {
100126 width : debouncedProps . width ?? 350 ,
101127 height : debouncedProps . height ?? 220 ,
102128 } ;
129+
130+ // 초기 마운트 시에는 이전 크기를 저장하고 API 호출하지 않음
131+ if ( previousSizeRef . current === null ) {
132+ previousSizeRef . current = currentSize ;
133+ return ;
134+ }
135+
136+ // 크기가 실제로 변경되지 않았으면 API 호출하지 않음
137+ if (
138+ previousSizeRef . current . width === currentSize . width &&
139+ previousSizeRef . current . height === currentSize . height
140+ ) {
141+ return ;
142+ }
143+
144+ previousSizeRef . current = currentSize ;
145+
146+ const body = {
147+ topicId : props . topicId ,
148+ ...currentSize ,
149+ } ;
150+
103151 const updateSize = async ( ) => {
104152 switch ( nodeData . nodeContent ) {
105153 case "topic" :
@@ -121,7 +169,10 @@ export default function CustomNode(props: CustomNodeProps) {
121169 return ;
122170 }
123171 } ;
172+
124173 updateSize ( ) ;
174+
175+ // eslint-disable-next-line react-hooks/exhaustive-deps
125176 } , [ debouncedProps . width , debouncedProps . height ] ) ;
126177
127178 return (
0 commit comments