## Description
Current evaluation architecture has 2 natures of evaluation
- sync evaluation ( evaluation for data fields )
- async evaluation ( evaluation for trigger events )
For every evaluation, this nature needs to be set according to the field
being evaluated.
It was noticed that for async code evaluation where a code block
executes only after the resolution of promise, for example,
`fetch().then((res) => { showAlert("fetched") });`
Here, the `showAlert` only executes when the fetch is completed and
before that, it could be possible that we have switched to sync
evaluation in the worker. This would lead to a `showAlert` throwing
error.
Hence, we resolve this issue by making `async evaluation` as the default
nature of evaluation.
Fixes https://github.com/appsmithorg/appsmith/issues/19733
## Type of change
- Bug fix (non-breaking change which fixes an issue)
## How Has This Been Tested?
- Manual
1. Validated Supabse app to check the error and JSPDF
2. Validated sync data field with sync function and framework function -
verify that error for async function is displayed properly
3. Validated older apps(Automation app/Silly string) to verify the Async
error is not displayed
4. .then and catch block in async function -
- Jest
- Cypress
### Test Plan
### Issues raised during DP testing
---------
Co-authored-by: Aishwarya UR <aishwarya@appsmith.com>
17 lines
436 B
TypeScript
17 lines
436 B
TypeScript
const _originalFetch = self.fetch;
|
|
|
|
export default function interceptAndOverrideHttpRequest() {
|
|
Object.defineProperty(self, "fetch", {
|
|
writable: false,
|
|
configurable: false,
|
|
value: function(...args: any) {
|
|
if (self.ALLOW_SYNC) {
|
|
self.IS_SYNC = false;
|
|
return;
|
|
}
|
|
const request = new Request(args[0], { ...args[1], credentials: "omit" });
|
|
return _originalFetch(request);
|
|
},
|
|
});
|
|
}
|