From 7b9b63ba0b6040da3d17c8a35260689b57706380 Mon Sep 17 00:00:00 2001 From: Rishabh Rathod Date: Tue, 25 Apr 2023 16:11:25 +0530 Subject: [PATCH] fix: crash issue when replayMap is undefined (#22515) ## Description Fix the type of `replayMap` and accordingly modify the code to handle `undefined` cases. Fixes https://github.com/appsmithorg/appsmith/issues/22514 ## Type of change - Bug fix (non-breaking change which fixes an issue) ## How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Provide instructions, so we can reproduce. > Please also list any relevant details for your test configuration. > Delete anything that is not important - Manual - Jest - Cypress ### Test Plan > Add Testsmith test cases links that relate to this PR ### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) ## Checklist: ### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag ### QA activity: - [ ] Test plan has been approved by relevant developers - [ ] Test plan has been peer reviewed by QA - [ ] Cypress test cases have been added and approved by either SDET or manual QA - [ ] Organized project review call with relevant stakeholders after Round 1/2 of QA - [ ] Added Test Plan Approved label after reveiwing all Cypress test --- app/client/src/workers/Evaluation/handlers/evalTree.ts | 8 ++++---- app/client/src/workers/Evaluation/handlers/replay.ts | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/client/src/workers/Evaluation/handlers/evalTree.ts b/app/client/src/workers/Evaluation/handlers/evalTree.ts index 74430a9b6b..a511317bb7 100644 --- a/app/client/src/workers/Evaluation/handlers/evalTree.ts +++ b/app/client/src/workers/Evaluation/handlers/evalTree.ts @@ -27,7 +27,7 @@ import { asyncJsFunctionInDataFields } from "../JSObject/asyncJSFunctionBoundToD import type { LintTreeSagaRequestData } from "workers/Linting/types"; import { WorkerMessenger } from "../fns/utils/Messenger"; import { MAIN_THREAD_ACTION } from "@appsmith/workers/Evaluation/evalWorkerActions"; -export let replayMap: Record>; +export let replayMap: Record> | undefined; export let dataTreeEvaluator: DataTreeEvaluator | undefined; export const CANVAS = "canvas"; @@ -112,7 +112,7 @@ export default function (request: EvalWorkerSyncRequest) { allActionValidationConfig, ); } - if (shouldReplay) { + if (shouldReplay && replayMap) { replayMap[CANVAS]?.update({ widgets, theme }); } dataTreeEvaluator = new DataTreeEvaluator( @@ -169,7 +169,7 @@ export default function (request: EvalWorkerSyncRequest) { ); } isCreateFirstTree = false; - if (shouldReplay) { + if (shouldReplay && replayMap) { replayMap[CANVAS]?.update({ widgets, theme }); } const setupUpdateTreeResponse = dataTreeEvaluator.setupUpdateTree( @@ -231,7 +231,7 @@ export default function (request: EvalWorkerSyncRequest) { errors = dataTreeEvaluator.errors; dataTreeEvaluator.clearErrors(); logs = dataTreeEvaluator.logs; - if (shouldReplay) { + if (shouldReplay && replayMap) { if (replayMap[CANVAS]?.logs) logs = logs.concat(replayMap[CANVAS]?.logs); replayMap[CANVAS]?.clearLogs(); } diff --git a/app/client/src/workers/Evaluation/handlers/replay.ts b/app/client/src/workers/Evaluation/handlers/replay.ts index 79ff639740..33aafdd322 100644 --- a/app/client/src/workers/Evaluation/handlers/replay.ts +++ b/app/client/src/workers/Evaluation/handlers/replay.ts @@ -5,6 +5,7 @@ import { CANVAS, replayMap } from "./evalTree"; export function undo(request: EvalWorkerSyncRequest) { const { data } = request; const { entityId } = data; + if (!replayMap) return; if (!replayMap[entityId || CANVAS]) return; const replayResult = replayMap[entityId || CANVAS].replay("UNDO"); replayMap[entityId || CANVAS].clearLogs(); @@ -14,6 +15,7 @@ export function undo(request: EvalWorkerSyncRequest) { export function redo(request: EvalWorkerSyncRequest) { const { data } = request; const { entityId } = data; + if (!replayMap) return; if (!replayMap[entityId ?? CANVAS]) return; const replayResult = replayMap[entityId ?? CANVAS].replay("REDO"); replayMap[entityId ?? CANVAS].clearLogs(); @@ -23,6 +25,7 @@ export function redo(request: EvalWorkerSyncRequest) { export function updateReplayObject(request: EvalWorkerSyncRequest) { const { data } = request; const { entity, entityId, entityType } = data; + if (!replayMap) return false; const replayObject = replayMap[entityId]; if (replayObject) { replayObject.update(entity);