diff --git a/app/client/src/components/editorComponents/Debugger/helpers.tsx b/app/client/src/components/editorComponents/Debugger/helpers.tsx index 8378e930b6..1ac95392f8 100644 --- a/app/client/src/components/editorComponents/Debugger/helpers.tsx +++ b/app/client/src/components/editorComponents/Debugger/helpers.tsx @@ -179,26 +179,35 @@ export function getDependencyChain( propertyPath: string, inverseMap: DependencyMap, ) { - let currentChain: string[] = []; - const dependents = inverseMap[propertyPath]; + const visited = new Set(); - if (!dependents || !dependents.length) return currentChain; + return getDependencyChainHelper(propertyPath); - const { entityName } = getEntityNameAndPropertyPath(propertyPath); + function getDependencyChainHelper(propertyPath: string): string[] { + let currentChain: string[] = []; + const dependents = inverseMap[propertyPath]; - dependents.map((dependentPath) => { - if (!isChildPropertyPath(entityName, dependentPath)) { - currentChain.push(dependentPath); + if (!dependents || !dependents.length) return currentChain; + + if (visited.has(propertyPath)) return currentChain; + + const { entityName } = getEntityNameAndPropertyPath(propertyPath); + + visited.add(propertyPath); + + for (const dependentPath of dependents) { + if (!isChildPropertyPath(entityName, dependentPath)) { + currentChain.push(dependentPath); + } + if (dependentPath !== entityName) { + currentChain = union( + currentChain, + getDependencyChain(dependentPath, inverseMap), + ); + } } - - if (dependentPath !== entityName) { - currentChain = union( - currentChain, - getDependencyChain(dependentPath, inverseMap), - ); - } - }); - return currentChain; + return currentChain; + } } export const doesEntityHaveErrors = (