Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: change the klona strategy of setting of values to evalTree and evalActionBindings #38033

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Changes from 1 commit
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
10 changes: 5 additions & 5 deletions app/client/src/workers/common/DataTreeEvaluator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,7 @@ export default class DataTreeEvaluator {
);

set(contextTree, fullPropertyPath, parsedValue);
set(safeTree, fullPropertyPath, klona(parsedValue));
set(safeTree, fullPropertyPath, klonaJSON(parsedValue));

staleMetaIds = staleMetaIds.concat(
getStaleMetaStateIds({
Expand Down Expand Up @@ -1253,7 +1253,7 @@ export default class DataTreeEvaluator {
if (!requiresEval) continue;

set(contextTree, fullPropertyPath, evalPropertyValue);
set(safeTree, fullPropertyPath, klona(evalPropertyValue));
set(safeTree, fullPropertyPath, klonaJSON(evalPropertyValue));
break;
}
case ENTITY_TYPE.JSACTION: {
Expand Down Expand Up @@ -1290,7 +1290,7 @@ export default class DataTreeEvaluator {
* Their evaluated values need to be reset only when the variable is modified by the user.
* When uneval value of a js variable hasn't changed, it means that the previously evaluated values are in both trees already */
if (!skipVariableValueAssignment) {
const valueForSafeTree = klona(evalValue);
const valueForSafeTree = klonaJSON(evalValue);
Copy link
Contributor

Choose a reason for hiding this comment

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

@rishabhrathod01 What are the allowed dataTypes for jsobject variables? We need to check if all these datatypes are supported by klonaJSON.

Copy link
Contributor

Choose a reason for hiding this comment

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

string, boolean, number, object, array, map and set are the main dataTypes that are supposed to be supported.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we please test for map, set and date object @vsvamsi1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure can you suggest some test scenarios for this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Create all types variables in jsobject and try to read and update them through the app. Check if you see anomalies.


set(contextTree, fullPropertyPath, evalValue);
set(safeTree, fullPropertyPath, valueForSafeTree);
Expand All @@ -1305,7 +1305,7 @@ export default class DataTreeEvaluator {
}
default:
set(contextTree, fullPropertyPath, evalPropertyValue);
set(safeTree, fullPropertyPath, klona(evalPropertyValue));
set(safeTree, fullPropertyPath, klonaJSON(evalPropertyValue));
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Ensure fallback handling for non-JSON types

The default case now uses klonaJSON which may fail for non-JSON types. Consider adding error handling or fallback to klona for unsupported types.

- set(safeTree, fullPropertyPath, klonaJSON(evalPropertyValue));
+ try {
+   set(safeTree, fullPropertyPath, klonaJSON(evalPropertyValue));
+ } catch (e) {
+   set(safeTree, fullPropertyPath, klona(evalPropertyValue));
+ }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
set(safeTree, fullPropertyPath, klonaJSON(evalPropertyValue));
try {
set(safeTree, fullPropertyPath, klonaJSON(evalPropertyValue));
} catch (e) {
set(safeTree, fullPropertyPath, klona(evalPropertyValue));
}

}
}
} catch (error) {
Expand Down Expand Up @@ -1793,7 +1793,7 @@ export default class DataTreeEvaluator {
bindings: string[],
executionParams?: Record<string, unknown> | string,
) {
const dataTree = klona(this.evalTree);
const dataTree = klonaJSON(this.evalTree);
// We might get execution params as an object or as a string.
// If the user has added a proper object (valid case) it will be an object
// If they have not added any execution params or not an object
Expand Down
Loading