Skip to content

Commit 0b7368e

Browse files
refactor: prevent disconnected handles from executing when input template 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 <otavio2204@gmail.com>
1 parent fdad497 commit 0b7368e

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/frontend/src/utils/reactflowUtils.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,36 @@ export function cleanEdges(nodes: AllNodeType[], edges: EdgeType[]) {
133133
}
134134
}
135135
}
136+
137+
newEdges = filterHiddenFieldsEdges(edge, newEdges, targetNode);
136138
});
137139
return newEdges;
138140
}
139141

142+
export function filterHiddenFieldsEdges(
143+
edge: EdgeType,
144+
newEdges: EdgeType[],
145+
targetNode: AllNodeType,
146+
) {
147+
if (targetNode) {
148+
const nodeInputType = edge.data?.targetHandle?.inputTypes;
149+
const nodeTemplates = targetNode.data.node!.template;
150+
151+
Object.keys(nodeTemplates).forEach((key) => {
152+
if (!nodeTemplates[key]?.input_types) return;
153+
if (
154+
nodeTemplates[key]?.input_types?.some((type) =>
155+
nodeInputType?.includes(type),
156+
) &&
157+
!nodeTemplates[key].show
158+
) {
159+
newEdges = newEdges.filter((e) => e.id !== edge.id);
160+
}
161+
});
162+
}
163+
return newEdges;
164+
}
165+
140166
export function detectBrokenEdgesEdges(nodes: AllNodeType[], edges: Edge[]) {
141167
function generateAlertObject(sourceNode, targetNode, edge) {
142168
const targetHandleObject: targetHandleType = scapeJSONParse(

0 commit comments

Comments
 (0)