diff --git a/app/client/cypress/e2e/Regression/ClientSide/BugTests/Bug29131_spec.ts b/app/client/cypress/e2e/Regression/ClientSide/BugTests/Bug29131_spec.ts new file mode 100644 index 0000000000..e6272c5115 --- /dev/null +++ b/app/client/cypress/e2e/Regression/ClientSide/BugTests/Bug29131_spec.ts @@ -0,0 +1,57 @@ +import { + agHelper, + locators, + entityExplorer, + jsEditor, +} from "../../../../support/Objects/ObjectsCore"; +import { EntityItems } from "../../../../support/Pages/AssertHelper"; + +const jsObjectBody = `export default { + myVar1: [], + myVar2: {}, + myFun1(){ + + }, + myFun2: async () => { + //use async-await or promises + } +}`; + +describe("Verifies JS object rename bug", () => { + it("Verify that a JS Object name is up for taking after it is deleted", () => { + jsEditor.CreateJSObject(jsObjectBody, { + paste: true, + completeReplace: true, + toRun: false, + shouldCreateNewJSObj: true, + prettify: false, + }); + + jsEditor.CreateJSObject(jsObjectBody, { + paste: true, + completeReplace: true, + toRun: false, + shouldCreateNewJSObj: true, + prettify: false, + }); + + jsEditor.RenameJSObjFromPane("JSObj2"); + + agHelper.ActionContextMenuWithInPane({ + action: "Delete", + entityType: EntityItems.JSObject, + }); + + jsEditor.CreateJSObject(jsObjectBody, { + paste: true, + completeReplace: true, + toRun: false, + shouldCreateNewJSObj: true, + prettify: false, + }); + + jsEditor.RenameJSObjFromPane("JSObj2"); + + entityExplorer.AssertEntityPresenceInExplorer("JSObj2"); + }); +}); diff --git a/app/client/src/ce/sagas/JSActionSagas.ts b/app/client/src/ce/sagas/JSActionSagas.ts index b7a9b6ddee..a416494a80 100644 --- a/app/client/src/ce/sagas/JSActionSagas.ts +++ b/app/client/src/ce/sagas/JSActionSagas.ts @@ -377,19 +377,19 @@ export function* refactorJSObjectName( getJSCollection(state, id), ); const functions = jsObject.actions; - yield put( - updateActionData( - functions.map((f) => ({ - entityName: newName, - data: undefined, - dataPath: `${f.name}.data`, - dataPathRef: `${oldName}.${f.name}.data`, - })), - ), - ); if (currentPageId === pageId) { // @ts-expect-error: refactorResponse.data is of type unknown yield updateCanvasWithDSL(refactorResponse.data, pageId, layoutId); + yield put( + updateActionData( + functions.map((f) => ({ + entityName: newName, + data: undefined, + dataPath: `${f.name}.data`, + dataPathRef: `${oldName}.${f.name}.data`, + })), + ), + ); } else { yield put(fetchJSCollectionsForPage(pageId)); } diff --git a/app/client/src/sagas/ActionSagas.ts b/app/client/src/sagas/ActionSagas.ts index dca0ed5015..7d7703942f 100644 --- a/app/client/src/sagas/ActionSagas.ts +++ b/app/client/src/sagas/ActionSagas.ts @@ -748,19 +748,19 @@ export function* refactorActionName( actionId: id, }, }); - yield put( - updateActionData([ - { - entityName: newName, - dataPath: "data", - data: undefined, - dataPathRef: `${oldName}.data`, - }, - ]), - ); if (currentPageId === pageId) { // @ts-expect-error: refactorResponse is of type unknown yield updateCanvasWithDSL(refactorResponse.data, pageId, layoutId); + yield put( + updateActionData([ + { + entityName: newName, + dataPath: "data", + data: undefined, + dataPathRef: `${oldName}.data`, + }, + ]), + ); } else { yield put(fetchActionsForPage(pageId)); } diff --git a/app/client/src/workers/Evaluation/JSObject/index.ts b/app/client/src/workers/Evaluation/JSObject/index.ts index 56ac11224f..f702ee125b 100644 --- a/app/client/src/workers/Evaluation/JSObject/index.ts +++ b/app/client/src/workers/Evaluation/JSObject/index.ts @@ -1,4 +1,4 @@ -import { get, isEmpty, merge, set } from "lodash"; +import { get, isEmpty, set } from "lodash"; import type { JSActionEntity } from "@appsmith/entities/DataTree/types"; import type { ConfigTree, DataTree } from "entities/DataTree/dataTreeTypes"; import { EvalErrorTypes, getEvalValuePath } from "utils/DynamicBindingUtils"; @@ -297,22 +297,12 @@ export function getJSEntities(dataTree: DataTree) { return jsCollections; } -export function updateEvalTreeWithJSCollectionState( - evalTree: DataTree, - oldUnEvalTree: DataTree, -) { +export function updateEvalTreeWithJSCollectionState(evalTree: DataTree) { // loop through jsCollectionState and set all values to evalTree const jsCollections = JSObjectCollection.getVariableState(); const jsCollectionEntries = Object.entries(jsCollections); for (const [jsObjectName, variableState] of jsCollectionEntries) { - if (!evalTree[jsObjectName]) { - evalTree[jsObjectName] = merge( - {}, - oldUnEvalTree[jsObjectName], - variableState, - ); - continue; - } + if (!evalTree[jsObjectName]) continue; evalTree[jsObjectName] = Object.assign( evalTree[jsObjectName], variableState, diff --git a/app/client/src/workers/common/DataTreeEvaluator/index.ts b/app/client/src/workers/common/DataTreeEvaluator/index.ts index 95087fc9bb..97adcb37af 100644 --- a/app/client/src/workers/common/DataTreeEvaluator/index.ts +++ b/app/client/src/workers/common/DataTreeEvaluator/index.ts @@ -714,7 +714,7 @@ export default class DataTreeEvaluator { updateDependencyMapTime = "0", } = extraParams; - updateEvalTreeWithJSCollectionState(this.evalTree, this.oldUnEvalTree); + updateEvalTreeWithJSCollectionState(this.evalTree); const calculateSortOrderStartTime = performance.now(); const subTreeSortOrder: string[] = this.calculateSubTreeSortOrder(