Skip to content

fix: CanvasCoreInner 핸들러 코드에서 old closure, 스냅샷 문제 #8

Description

@Ospac

문제

드롭 판정에서 stageoccupancy가 서로 다른 스냅샷을 볼 수 있습니다.

currentStage는 updater에서 읽지만 occupancyvisibleStage는 렌더 시점 클로저 값을 그대로 사용합니다. 직전 onNodeDrag가 stage 확장을 큐에 넣은 상태라면 여기서는 stage=7인데 occupancy는 이전 stage 기준일 수 있습니다. src/features/diagram/lib/grid.ts Line 116-117처럼 전달된 stage 밖 노드는 occupancy에서 빠지므로, 새로 열린 셀의 충돌을 놓치고 겹침 드롭이 통과할 수 있습니다.

수정 방향 예시
 		setVisibleStage((currentStage) => {
+			const currentOccupancy = getGridOccupancy(nodes, currentStage);
 			const currentDockingState =
 				nodeDockingState[node.id] ??
-				createDockedNodeState(node.position, visibleStage);
+				createDockedNodeState(node.position, currentStage);
 			const resolution = resolveDropPosition({
 				position: node.position,
 				stage: currentStage,
-				occupancy,
+				occupancy: currentOccupancy,
 				ignoreNodeId: node.id,
 				lastValidDock: currentDockingState.lastValidDock,
 			});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/features/diagram/ui/CanvasCore/CanvasCoreInner.tsx` around lines 149 -
160, The drop check uses currentStage from the setVisibleStage updater but still
reads the stale closure values visibleStage/occupancy, which can miss
collisions; inside the setVisibleStage updater in handleNodeDragStop, obtain the
occupancy snapshot that matches the updater's currentStage (e.g., call whatever
helper provides occupancy for a given stage such as
compute/getOccupancyForStage) and use that fresh occupancy (and derive
currentDockingState based on that same stage) when calling resolveDropPosition;
ensure resolveDropPosition receives the occupancy tied to currentStage rather
than the outer-scoped occupancy/visibleStage.

Originally posted by @coderabbitai[bot] in #7 (comment)

할일

최신의 스냅샷을 참조하기 위해, 중첩된 setState를 구현하기 보다는, useReducer로 상태 업데이트, 파생 상태 업데이트 코드를 모두 통합하여 핸들러 내부는 선언적으로 유지하는게 좋을 것 같음!

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions