diff --git a/app/client/src/sagas/JSPaneSagas.ts b/app/client/src/sagas/JSPaneSagas.ts index 0955d27096..5e49d43b08 100644 --- a/app/client/src/sagas/JSPaneSagas.ts +++ b/app/client/src/sagas/JSPaneSagas.ts @@ -207,6 +207,12 @@ function* handleEachUpdateJSCollection(update: JSUpdate) { if (parsedBody && !!jsAction) { const jsActionTobeUpdated = JSON.parse(JSON.stringify(jsAction)); + + // Initialize actions array if undefined + if (!jsActionTobeUpdated.actions) { + jsActionTobeUpdated.actions = []; + } + const data = getDifferenceInJSCollection(parsedBody, jsAction); if (data.nameChangedActions.length) { diff --git a/app/client/src/utils/JSPaneUtils.tsx b/app/client/src/utils/JSPaneUtils.tsx index c20d867b7a..cc51033283 100644 --- a/app/client/src/utils/JSPaneUtils.tsx +++ b/app/client/src/utils/JSPaneUtils.tsx @@ -51,7 +51,9 @@ export const getDifferenceInJSCollection = ( if (parsedBody.actions && parsedBody.actions.length > 0) { for (let i = 0; i < parsedBody.actions.length; i++) { const action = parsedBody.actions[i]; - const preExisted = jsAction.actions.find((js) => js.name === action.name); + const preExisted = (jsAction.actions || []).find( + (js) => js.name === action.name, + ); if (preExisted) { if (preExisted.actionConfiguration.body !== action.body) { @@ -142,17 +144,6 @@ export const getDifferenceInJSCollection = ( } } - if (toBearchivedActions.length > 0) { - for (let i = 0; i < toBearchivedActions.length; i++) { - const action = toBearchivedActions[i]; - const deleteArchived = jsAction.actions.findIndex((js) => { - action.id === js.id; - }); - - jsAction.actions.splice(deleteArchived, 1); - } - } - //change in variables. In cases the variable list is not present, jsAction.variables will be undefined // we are setting to empty array to avoid undefined errors further in the code (especially in case of workflows main file) const varList = jsAction.variables || [];