From 408ef81a5bed114a41b5500dc0c61043890a3dd2 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Wed, 9 Aug 2023 20:46:50 -0300 Subject: [PATCH] chore(constants.ts): add missing newline at the end of the file feat(tabsContext.tsx): add support for skipping node updates based on node type defined in the skipNodeUpdate constant to improve performance and prevent unnecessary updates --- src/frontend/src/constants/constants.ts | 2 ++ src/frontend/src/contexts/tabsContext.tsx | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/frontend/src/constants/constants.ts b/src/frontend/src/constants/constants.ts index c554fb9a4..3f698c64e 100644 --- a/src/frontend/src/constants/constants.ts +++ b/src/frontend/src/constants/constants.ts @@ -509,3 +509,5 @@ export const URL_EXCLUDED_FROM_ERROR_RETRIES = [ "/api/v1/custom_component", "/api/v1/validate/prompt", ]; + +export const skipNodeUpdate = ["CustomComponent"]; diff --git a/src/frontend/src/contexts/tabsContext.tsx b/src/frontend/src/contexts/tabsContext.tsx index 5ea8c11c0..5f463c2c1 100644 --- a/src/frontend/src/contexts/tabsContext.tsx +++ b/src/frontend/src/contexts/tabsContext.tsx @@ -9,6 +9,7 @@ import { } from "react"; import { addEdge } from "reactflow"; import ShortUniqueId from "short-unique-id"; +import { skipNodeUpdate } from "../constants/constants"; import { deleteFlowFromDatabase, downloadFlowsFromDatabase, @@ -163,6 +164,7 @@ export function TabsProvider({ children }: { children: ReactNode }) { function processFlowNodes(flow) { if (!flow.data || !flow.data.nodes) return; flow.data.nodes.forEach((node: NodeType) => { + if (skipNodeUpdate.includes(node.data.type)) return; const template = templates[node.data.type]; if (!template) { setErrorData({ title: `Unknown node type: ${node.data.type}` }); @@ -506,6 +508,7 @@ export function TabsProvider({ children }: { children: ReactNode }) { const updateNodes = (nodes, edges) => { nodes.forEach((node) => { + if (skipNodeUpdate.includes(node.data.type)) return; const template = templates[node.data.type]; if (!template) { setErrorData({ title: `Unknown node type: ${node.data.type}` });