Merge pull request #4718 from xyflow/fix/use-nodes-data

fix useNodesData returning undefined in svelte flow
This commit is contained in:
Moritz Klack
2024-10-09 17:32:19 +02:00
committed by GitHub
4 changed files with 10 additions and 3 deletions
@@ -22,6 +22,7 @@ export function useNodesData(nodeIds: any): any {
const { nodes, nodeLookup } = useStore();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let prevNodesData: any[] = [];
let initialRun = true;
return derived([nodes, nodeLookup], ([, nodeLookup], set) => {
const nextNodesData = [];
@@ -39,9 +40,10 @@ export function useNodesData(nodeIds: any): any {
}
}
if (!shallowNodeData(nextNodesData, prevNodesData)) {
if (!shallowNodeData(nextNodesData, prevNodesData) || initialRun) {
prevNodesData = nextNodesData;
set(isArrayOfIds ? nextNodesData : nextNodesData[0] ?? null);
initialRun = false;
}
});
}