Skip to content

Commit

Permalink
Avoid re-rendering nodes on click
Browse files Browse the repository at this point in the history
  • Loading branch information
jain-sachin committed Sep 29, 2024
1 parent e2a1776 commit cd4eb60
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/core/src/components/DndContext/DndContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ export const DndContext = memo(function DndContext({
activeNodeRect
);

const activeSensorRef = useRef<SensorInstance | null>(null);
const activatorEventRef = useRef<Event | null>(null);
const instantiateSensor = useCallback(
(
event: React.SyntheticEvent,
Expand Down Expand Up @@ -371,6 +373,8 @@ export const DndContext = memo(function DndContext({
active: id,
});
dispatchMonitorEvent({type: 'onDragStart', event});
setActiveSensor(activeSensorRef.current);
setActivatorEvent(activatorEventRef.current);
});
},
onMove(coordinates) {
Expand All @@ -383,10 +387,8 @@ export const DndContext = memo(function DndContext({
onCancel: createHandler(Action.DragCancel),
});

unstable_batchedUpdates(() => {
setActiveSensor(sensorInstance);
setActivatorEvent(event.nativeEvent);
});
activeSensorRef.current = sensorInstance;
activatorEventRef.current = event.nativeEvent;

function createHandler(type: Action.DragEnd | Action.DragCancel) {
return async function handler() {
Expand Down Expand Up @@ -422,6 +424,8 @@ export const DndContext = memo(function DndContext({
setOver(null);
setActiveSensor(null);
setActivatorEvent(null);
activeSensorRef.current = null;
activatorEventRef.current = null;

const eventName =
type === Action.DragEnd ? 'onDragEnd' : 'onDragCancel';
Expand Down

0 comments on commit cd4eb60

Please sign in to comment.