Skip to content

Commit

Permalink
refactor: prevent disconnected handles from executing when input temp…
Browse files Browse the repository at this point in the history
…late edge is hidden (#6132)

* ✨ (reactflowUtils.ts): add new function filterHiddenFieldsEdges to filter out edges based on hidden fields in node templates

* ♻️ (reactflowUtils.ts): refactor filterHiddenFieldsEdges function to accept targetNode directly instead of nodes array to improve code readability and maintainability

* 🐛 (reactflowUtils.ts): fix a bug where nodeInputType is accessed without null check, causing potential runtime error

---------

Co-authored-by: anovazzi1 <[email protected]>
  • Loading branch information
Cristhianzl and anovazzi1 authored Feb 6, 2025
1 parent fdad497 commit 0b7368e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/frontend/src/utils/reactflowUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,36 @@ export function cleanEdges(nodes: AllNodeType[], edges: EdgeType[]) {
}
}
}

newEdges = filterHiddenFieldsEdges(edge, newEdges, targetNode);
});
return newEdges;
}

export function filterHiddenFieldsEdges(
edge: EdgeType,
newEdges: EdgeType[],
targetNode: AllNodeType,
) {
if (targetNode) {
const nodeInputType = edge.data?.targetHandle?.inputTypes;
const nodeTemplates = targetNode.data.node!.template;

Object.keys(nodeTemplates).forEach((key) => {
if (!nodeTemplates[key]?.input_types) return;
if (
nodeTemplates[key]?.input_types?.some((type) =>
nodeInputType?.includes(type),
) &&
!nodeTemplates[key].show
) {
newEdges = newEdges.filter((e) => e.id !== edge.id);
}
});
}
return newEdges;
}

export function detectBrokenEdgesEdges(nodes: AllNodeType[], edges: Edge[]) {
function generateAlertObject(sourceNode, targetNode, edge) {
const targetHandleObject: targetHandleType = scapeJSONParse(
Expand Down

0 comments on commit 0b7368e

Please sign in to comment.