## Description
- Added logic to replace async function undefined error with
"{{actionName}} cannot be used in this field".
- This change improves performance for
- ParseJSActions
- Triggers execution
- Each Appsmith framework action execution.
- This change adds all platform functions to evalContext permanently.
Fixes #12179
Fixes #13273
Internal discussion for error message :-
https://theappsmith.slack.com/archives/C02K0SZQ7V3/p1667457021297869?thread_ts=1667385039.225229&cid=C02K0SZQ7V3
## Type of change
- Bug fix (non-breaking change which fixes an issue)
- Performance improvement
## How Has This Been Tested?
- Manual
- Jest
- Cypress
### Test Plan
- [ ] https://github.com/appsmithorg/TestSmith/issues/2086
### 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
- [ ] My code follows the style guidelines of this project
- [ ] 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
- [ ] 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
Co-authored-by: Aishwarya UR <aishwarya@appsmith.com>
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import { ActionCalledInSyncFieldError } from "./errorModifier";
|
|
import { createEvaluationContext } from "./evaluate";
|
|
import { dataTreeEvaluator } from "./handlers/evalTree";
|
|
|
|
export const _internalSetTimeout = self.setTimeout;
|
|
export const _internalClearTimeout = self.clearTimeout;
|
|
|
|
export default function overrideTimeout() {
|
|
Object.defineProperty(self, "setTimeout", {
|
|
writable: true,
|
|
configurable: true,
|
|
value: function(cb: (...args: any) => any, delay: number, ...args: any) {
|
|
if (!self.ALLOW_ASYNC) {
|
|
self.IS_ASYNC = true;
|
|
throw new ActionCalledInSyncFieldError("setTimeout");
|
|
}
|
|
const evalContext = createEvaluationContext({
|
|
dataTree: dataTreeEvaluator?.evalTree || {},
|
|
resolvedFunctions: dataTreeEvaluator?.resolvedFunctions || {},
|
|
isTriggerBased: true,
|
|
});
|
|
return _internalSetTimeout(
|
|
function(...args: any) {
|
|
self.ALLOW_ASYNC = true;
|
|
Object.assign(self, evalContext);
|
|
cb(...args);
|
|
},
|
|
delay,
|
|
...args,
|
|
);
|
|
},
|
|
});
|
|
|
|
Object.defineProperty(self, "clearTimeout", {
|
|
writable: true,
|
|
configurable: true,
|
|
value: function(timerId: number) {
|
|
if (!self.ALLOW_ASYNC) {
|
|
self.IS_ASYNC = true;
|
|
throw new ActionCalledInSyncFieldError("clearTimeout");
|
|
}
|
|
return _internalClearTimeout(timerId);
|
|
},
|
|
});
|
|
}
|