Skip to content
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 50 additions & 12 deletions app/client/src/sagas/EvaluationsSaga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
delay,
fork,
put,
race,
select,
spawn,
take,
Expand Down Expand Up @@ -58,7 +59,7 @@ import {
import type { JSAction, JSCollection } from "entities/JSCollection";
import { getAppMode } from "ee/selectors/applicationSelectors";
import { APP_MODE } from "entities/App";
import { get, isEmpty } from "lodash";
import { get, isEmpty, isEqual } from "lodash";
import type { TriggerMeta } from "ee/sagas/ActionExecution/ActionExecutionSagas";
import { executeActionTriggers } from "ee/sagas/ActionExecution/ActionExecutionSagas";
import {
Expand Down Expand Up @@ -753,24 +754,61 @@ function* evaluationChangeListenerSaga(): any {
EVAL_AND_LINT_REDUX_ACTIONS,
evalQueueBuffer(),
);
let hasTriggerAction = false;

while (true) {
const action: EvaluationReduxAction<unknown | unknown[]> =
yield take(evtActionChannel);
const { action, timeout } = yield race({
action: take(evtActionChannel),
timeout: delay(1000),
});

// We are dequing actions from the buffer and inferring the JS actions affected by each
// action. Through this we know ahead the nodes we need to specifically diff, thereby improving performance.
const affectedJSObjects = getAffectedJSObjectIdsFromAction(action);
if (
action?.type === ReduxActionTypes.TRIGGER_EVAL ||
isEqual(action, bufferedAction)
) {
hasTriggerAction = true;
continue;
}

yield call(evalAndLintingHandler, true, action, {
shouldReplay: get(action, "payload.shouldReplay"),
forceEvaluation: shouldForceEval(action),
requiresLogging: shouldLog(action),
affectedJSObjects,
});
if (timeout) {
if (hasTriggerAction) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const action = bufferedAction as any;
const affectedJSObjects = getAffectedJSObjectIdsFromAction(action);

yield call(evalAndLintingHandler, true, action, {
shouldReplay: get(action, "payload.shouldReplay"),
forceEvaluation: shouldForceEval(action),
requiresLogging: shouldLog(action),
affectedJSObjects,
});
}
} else {
// We are dequing actions from the buffer and inferring the JS actions affected by each
// action. Through this we know ahead the nodes we need to specifically diff, thereby improving performance.
const affectedJSObjects = getAffectedJSObjectIdsFromAction(action);

yield call(evalAndLintingHandler, true, action, {
shouldReplay: get(action, "payload.shouldReplay"),
forceEvaluation: shouldForceEval(action),
requiresLogging: shouldLog(action),
affectedJSObjects,
});
}

hasTriggerAction = false;
Comment on lines +760 to +800

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix usage of 'bufferedAction' before its declaration

The variable bufferedAction is used before its declaration at line 803, which will cause a ReferenceError. Move the declaration of bufferedAction before its usage.

Apply this diff to fix the issue:

+ const bufferedAction = {
+   postEvalActions: [],
+   affectedJSObjects: {
+     isAllAffected: false,
+     ids: [],
+   },
+   type: "BUFFERED_ACTION",
+ };

 while (true) {
   const { action, timeout } = yield race({
     action: take(evtActionChannel),
     timeout: delay(1000),
   });

Committable suggestion skipped: line range outside the PR's diff.

}
}

const bufferedAction = {
postEvalActions: [],
affectedJSObjects: {
isAllAffected: false,
ids: [],
},
type: "BUFFERED_ACTION",
};

// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function* evaluateActionSelectorFieldSaga(action: any) {
Expand Down