diff --git a/app/client/src/workers/DataTreeEvaluator.ts b/app/client/src/workers/DataTreeEvaluator.ts index 6fe0f04ffc..45d3d85cc9 100644 --- a/app/client/src/workers/DataTreeEvaluator.ts +++ b/app/client/src/workers/DataTreeEvaluator.ts @@ -243,13 +243,27 @@ export default class DataTreeEvaluator { // Remove duplicates from this list. Since we explicitly walk down the tree and implicitly (by fetching parents) walk // up the tree, there are bound to be many duplicates. - const uniqueKeysInSortOrder = [...new Set(finalSortOrder)]; + const uniqueKeysInSortOrder = new Set(finalSortOrder); - const sortOrderPropertyPaths = Array.from(uniqueKeysInSortOrder); + // if a property path evaluation gets triggered by diff top order changes + // this could lead to incorrect sort order in spite of the bfs traversal + const sortOrderPropertyPaths: string[] = []; + this.sortedDependencies.forEach((path) => { + if (uniqueKeysInSortOrder.has(path)) { + sortOrderPropertyPaths.push(path); + // remove from the uniqueKeysInSortOrder + uniqueKeysInSortOrder.delete(path); + } + }); + // Add any remaining paths in the uniqueKeysInSortOrder + const completeSortOrder = [ + ...Array.from(uniqueKeysInSortOrder), + ...sortOrderPropertyPaths, + ]; //Trim this list to now remove the property paths which are simply entity names const finalSortOrderArray: Array = []; - sortOrderPropertyPaths.forEach((propertyPath) => { + completeSortOrder.forEach((propertyPath) => { const lastIndexOfDot = propertyPath.lastIndexOf("."); // Only do this for property paths and not the entity themselves if (lastIndexOfDot !== -1) {