refactor(updates): only trigger dim updates when dim changed
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { useCallback } from 'react';
|
||||
import type { UpdateNodeInternals, NodeDimensionUpdate } from '@xyflow/system';
|
||||
import type { UpdateNodeInternals, InternalNodeUpdate } from '@xyflow/system';
|
||||
|
||||
import { useStoreApi } from '../hooks/useStore';
|
||||
|
||||
@@ -13,9 +13,9 @@ export function useUpdateNodeInternals(): UpdateNodeInternals {
|
||||
const store = useStoreApi();
|
||||
|
||||
return useCallback<UpdateNodeInternals>((id: string | string[]) => {
|
||||
const { domNode, updateNodeDimensions } = store.getState();
|
||||
const { domNode, updateNodeInternals } = store.getState();
|
||||
const updateIds = Array.isArray(id) ? id : [id];
|
||||
const updates = new Map<string, NodeDimensionUpdate>();
|
||||
const updates = new Map<string, InternalNodeUpdate>();
|
||||
|
||||
updateIds.forEach((updateId) => {
|
||||
const nodeElement = domNode?.querySelector(`.react-flow__node[data-id="${updateId}"]`) as HTMLDivElement;
|
||||
@@ -25,6 +25,6 @@ export function useUpdateNodeInternals(): UpdateNodeInternals {
|
||||
}
|
||||
});
|
||||
|
||||
requestAnimationFrame(() => updateNodeDimensions(updates));
|
||||
requestAnimationFrame(() => updateNodeInternals(updates));
|
||||
}, []);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user