Skip to content

Commit

Permalink
fix: Cyclic dependency not resolving in JS Editor (appsmithorg#8003)
Browse files Browse the repository at this point in the history
  • Loading branch information
hetunandu authored Oct 1, 2021
1 parent 70c282d commit 72f6ad8
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions app/client/src/workers/evaluation.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,22 +235,28 @@ ctx.addEventListener(
}
case EVAL_WORKER_ACTIONS.PARSE_JS_FUNCTION_BODY: {
const { body, jsAction } = requestData;

if (!dataTreeEvaluator) {
return true;
}
/**
* In case of a cyclical dependency, the dataTreeEvaluator will not
* be present. This causes an issue because evalTree is needed to resolve
* the cyclical dependency in a JS Collection
*
* By setting evalTree to an empty object, the parsing can still take place
* and it would resolve the cyclical dependency
* **/
const currentEvalTree = dataTreeEvaluator
? dataTreeEvaluator.evalTree
: {};
try {
const { evalTree, result } = parseJSCollection(
body,
jsAction,
dataTreeEvaluator.evalTree,
currentEvalTree,
);
return {
evalTree,
result,
};
} catch (e) {
const evalTree = dataTreeEvaluator.evalTree;
const errors = [
{
errorType: PropertyEvaluationErrorType.PARSE,
Expand All @@ -259,9 +265,13 @@ ctx.addEventListener(
errorMessage: e.message,
},
];
_.set(evalTree, `${jsAction.name}.${EVAL_ERROR_PATH}.body`, errors);
_.set(
currentEvalTree,
`${jsAction.name}.${EVAL_ERROR_PATH}.body`,
errors,
);
return {
evalTree,
currentEvalTree,
};
}
}
Expand Down

0 comments on commit 72f6ad8

Please sign in to comment.