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: update local uneval tree only for jsObjects and exit early for other entities #34524

Merged
merged 3 commits into from
Jul 4, 2024

Conversation

ashit-rath
Copy link
Contributor

@ashit-rath ashit-rath commented Jun 27, 2024

Description

When a new evaluation cycle starts the uneval tree goes through a processing for updating the js objects in the right format. But the update condition depends on values present in JSObjectCollection.
Due to the nature of evaluation for modules; when a JSModule is opened in an editor then the JSModule in evaluation is treated as a jsobject but when a different JSModule is opened then the previously opened JSModule is treated as a JSModule instance. Since in one of the eval cycle the first JSModule was treated as an JSObject so it's functions made it's way into the JSObjectCollection and now when it was treated as JSModuleInstance, due to it's functions present in JSObjectCollection during previous eval cycles; it's values gets altered which is undesirable.

The change here dictates that if an entity is a JSObject, then only proceed for any alteration else the dataTree for the entity stays intact.

PR for https://github.com/appsmithorg/appsmith-ee/pull/4547

Automation

/ok-to-test tags="@tag.All"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/9707356261
Commit: f242dfa
Cypress dashboard.
Tags: ``

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced stability and control flow in the DataTreeEvaluator to prevent issues when processing non-JSAction entities.

@ashit-rath ashit-rath added Frontend This label marks the issue or pull request to reference client code Task A simple Todo Package Issues related to packages labels Jun 27, 2024
@ashit-rath ashit-rath self-assigned this Jun 27, 2024
Copy link
Contributor

coderabbitai bot commented Jun 27, 2024

Walkthrough

A conditional check for isJSAction(entity) was added in the DataTreeEvaluator class in the index.ts file. If the entity does not pass this check, the method will return immediately, modifying the control flow to ensure only JavaScript actions are processed.

Changes

File Change Summary
.../DataTreeEvaluator/index.ts In the DataTreeEvaluator class, added a conditional if (!isJSAction(entity)) return; within a method.

Poem

In the realm of code where data trees sprout,
A small new check now dances about. 🌲
If not a JSAction, we swiftly depart,
Streamlining the flow with a coder's art. 🎨
With nimble hops, we debug and play,
A rabbit's touch makes the code okay! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Jun 27, 2024
@ashit-rath ashit-rath removed the request for review from ApekshaBhosale June 27, 2024 04:23
@ashit-rath ashit-rath added the ok-to-test Required label for CI label Jun 27, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range and nitpick comments (4)
app/client/src/workers/common/DataTreeEvaluator/index.ts (4)

Line range hint 1014-1022: Reorder parameters to place default parameters last.

This change ensures that default parameters are correctly utilized and follow conventional patterns.

- function example(param1 = "default", param2) {
+ function example(param2, param1 = "default") {
Tools
Biome

[error] 475-475: Avoid redundant double-negation.

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation

(lint/complexity/noExtraBooleanCast)


Line range hint 1283-1288: Avoid 'return' in 'finally' block to prevent overriding 'try' and 'catch'.

Using 'return' in a 'finally' block can lead to unexpected behavior by overriding error handling or other logic in 'try' and 'catch' blocks.

try {
  // some logic
} catch (error) {
  // handle error
} finally {
  // cleanup
  // remove the return statement
}
Tools
Biome

[error] 475-475: Avoid redundant double-negation.

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation

(lint/complexity/noExtraBooleanCast)


Line range hint 1320-1356: Remove unnecessary 'else' clauses to simplify control flow.

After 'break', 'continue', 'throw', or 'return' statements, 'else' clauses are redundant and can be removed to simplify the control flow.

if (condition) {
  return value;
}
// remove else, just continue with the next block of code

Also applies to: 1431-1433

Tools
Biome

[error] 475-475: Avoid redundant double-negation.

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation

(lint/complexity/noExtraBooleanCast)


Line range hint 1579-1579: Utilize optional chaining for safer and cleaner code.

Optional chaining (?.) allows for safer access to deeply nested properties and can prevent runtime errors due to undefined or null values.

- const value = object && object.property;
+ const value = object?.property;

Also applies to: 1684-1685

Tools
Biome

[error] 475-475: Avoid redundant double-negation.

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation

(lint/complexity/noExtraBooleanCast)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6f67dbd and 05da1cf.

Files selected for processing (1)
  • app/client/src/workers/common/DataTreeEvaluator/index.ts (1 hunks)
Additional context used
Biome
app/client/src/workers/common/DataTreeEvaluator/index.ts

[error] 3-3: Do not shadow the global "EvalError" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)


[error] 475-475: Avoid redundant double-negation.

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation

(lint/complexity/noExtraBooleanCast)


[error] 1014-1022: This default parameter should follow the last required parameter or should be a required parameter.

The last required parameter is here:

A default parameter that precedes a required parameter cannot be omitted at call site.
Unsafe fix: Turn the parameter into a required parameter.

(lint/style/useDefaultParameterLast)


[error] 1283-1288: Unsafe usage of 'return'.

'return' in 'finally' overwrites the control flow statements inside 'try' and 'catch'.

(lint/correctness/noUnsafeFinally)


[error] 1320-1356: This else clause can be omitted because previous branches break early.

Unsafe fix: Omit the else clause.

(lint/style/noUselessElse)


[error] 1431-1433: This else clause can be omitted because previous branches break early.

Unsafe fix: Omit the else clause.

(lint/style/noUselessElse)


[error] 1579-1579: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 1684-1685: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Additional comments not posted (2)
app/client/src/workers/common/DataTreeEvaluator/index.ts (2)

470-472: Consider early return to simplify logic.

The current implementation uses if (!isJSAction(entity)) return; which effectively filters out non-JSAction entities. This aligns with the PR's objective to only process JSObjects.


Line range hint 3-3: Rename the EvalError type to avoid shadowing global property.

Using a name that shadows a global JavaScript object can lead to confusion and bugs. Consider renaming EvalError to EvaluationError or another distinct name.
[ISSMUE]

- import type { EvalError, EvaluationError } from "utils/DynamicBindingUtils";
+ import type { EvaluationError as AppsmithEvaluationError, EvaluationError } from "utils/DynamicBindingUtils";
Tools
Biome

[error] 475-475: Avoid redundant double-negation.

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation

(lint/complexity/noExtraBooleanCast)

app/client/src/workers/common/DataTreeEvaluator/index.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@rishabhrathod01 rishabhrathod01 left a comment

Choose a reason for hiding this comment

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

LGTM

@ashit-rath ashit-rath added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jun 28, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range and nitpick comments (1)
app/client/src/workers/common/DataTreeEvaluator/index.ts (1)

Line range hint 481-488: Consider optimizing the method for clarity and performance.

The method iterates over keys and performs checks and updates. Consider refactoring to improve clarity and reduce potential performance overhead, especially in scenarios with a large number of entities.

- Object.keys(unEvalJSCollection).forEach((entityName) => {
+ for (const entityName of Object.keys(unEvalJSCollection)) {

This change uses a for...of loop, which can be more performant and clearer in this context.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 05da1cf and f242dfa.

Files selected for processing (1)
  • app/client/src/workers/common/DataTreeEvaluator/index.ts (1 hunks)
Additional context used
Biome
app/client/src/workers/common/DataTreeEvaluator/index.ts

[error] 990-998: This default parameter should follow the last required parameter or should be a required parameter.

The last required parameter is here:

A default parameter that precedes a required parameter cannot be omitted at call site.
Unsafe fix: Turn the parameter into a required parameter.

(lint/style/useDefaultParameterLast)


[error] 1259-1264: Unsafe usage of 'return'.

'return' in 'finally' overwrites the control flow statements inside 'try' and 'catch'.

(lint/correctness/noUnsafeFinally)


[error] 1296-1332: This else clause can be omitted because previous branches break early.

Unsafe fix: Omit the else clause.

(lint/style/noUselessElse)


[error] 1548-1548: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Additional comments not posted (1)
app/client/src/workers/common/DataTreeEvaluator/index.ts (1)

483-483: Ensure early exit condition is correctly implemented.

The addition of the conditional check if (!isJSAction(entity)) return; is intended to prevent unwanted modifications by exiting early if the entity is not a JSAction. This change aligns with the PR's objectives and should improve performance by reducing unnecessary processing.

@ashit-rath ashit-rath merged commit 4bbe28a into release Jul 4, 2024
84 checks passed
@ashit-rath ashit-rath deleted the chore/update-uneval-for-jsaction branch July 4, 2024 07:00
Shivam-z pushed a commit to Shivam-z/appsmith that referenced this pull request Jul 10, 2024
… other entities (appsmithorg#34524)

## Description
When a new evaluation cycle starts the uneval tree goes through a
processing for updating the js objects in the right format. But the
update condition depends on values present in `JSObjectCollection`.
Due to the nature of evaluation for modules; when a JSModule is opened
in an editor then the JSModule in evaluation is treated as a jsobject
but when a different JSModule is opened then the previously opened
JSModule is treated as a JSModule instance. Since in one of the eval
cycle the first JSModule was treated as an JSObject so it's functions
made it's way into the `JSObjectCollection` and now when it was treated
as `JSModuleInstance`, due to it's functions present in
`JSObjectCollection` during previous eval cycles; it's values gets
altered which is undesirable.

The change here dictates that if an entity is a JSObject, then only
proceed for any alteration else the dataTree for the entity stays
intact.


PR for https://github.com/appsmithorg/appsmith-ee/pull/4547

## Automation

/ok-to-test tags="@tag.All"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/9707356261>
> Commit: f242dfa
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=9707356261&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: ``

<!-- end of auto-generated comment: Cypress test results  -->






## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Bug Fixes**
- Enhanced stability and control flow in the `DataTreeEvaluator` to
prevent issues when processing non-JSAction entities.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Frontend This label marks the issue or pull request to reference client code ok-to-test Required label for CI Package Issues related to packages skip-changelog Adding this label to a PR prevents it from being listed in the changelog Task A simple Todo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants