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
This commit is contained in:
Rishabh Rathod 2023-04-25 16:11:25 +05:30 committed by GitHub
parent 7e8ade0a85
commit 7b9b63ba0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -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<string, ReplayEntity<any>>;
export let replayMap: Record<string, ReplayEntity<any>> | 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();
}

View File

@ -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);