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

fix: function undefined error after resetWidget is called due to sync… #33600

Merged
merged 3 commits into from
May 21, 2024

Conversation

rishabhrathod01
Copy link
Contributor

@rishabhrathod01 rishabhrathod01 commented May 20, 2024

Description

Fixed the error of async function like Api.run being undefined after running resetWidget.

Context:-

we have 2 types of evaluation i.e., sync and async evaluation.

These are dependent on the field we are evaluating, for the data field we use sync evaluation and for the trigger field, we use async evaluation. In Async evaluation, we also define entity functions like Api.run.

  • In resetWidget code, internally we were switching to sync evaluation and we forgot to add code to switch back to async and due to this code that was after it was throwing an undefined error.

Fixes #33601

Steps to reproduce

  1. Import user’s application ( shared on slack )
  2. Go to JSObj_Main JSObject
  3. Check the onClickCopySheetTemplate function
  4. Comment the await Qry_C_CopySheetTemplate.run(); line and run the function.
  5. On release it will throw error for Qry_R_SheetTemplate.run(); not being defined but will work fine on DP.

Automation

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

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/9170093222
Commit: f9e8893
Cypress dashboard url: Click here!

Communication

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

  • Yes
  • No

Copy link
Contributor

coderabbitai bot commented May 20, 2024

Walkthrough

Walkthrough

The recent updates focus on enhancing the evaluation process in the Evaluation module of the application. Notable changes include introducing setEvalContext in resetWidget.ts to manage synchronous tasks effectively and adding new functions in Actions.ts for better context handling. Additionally, tests for entity functions and context evaluation have been added in index.test.ts.

Changes

File Path Change Summary
app/client/src/workers/Evaluation/fns/resetWidget.ts Imported setEvalContext from evaluate.ts and added code to switch back to async evaluation after sync tasks.
app/client/src/ce/workers/Evaluation/Actions.ts Updated addDataTreeToContext to skip platform functions if not trigger-based. Added addEntityFunctionsToEvalContext.
app/client/src/workers/Evaluation/fns/__tests__/index.test.ts Introduced tests for entity functions, setup data trees, and actions within worker evaluation context.

Assessment against linked issues

Objective Addressed Explanation
Bug: resetWidget function causes the next async method to be undefined (#33601)

Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between bdc827d and f9e8893.
Files selected for processing (1)
  • app/client/src/workers/Evaluation/fns/tests/index.test.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/client/src/workers/Evaluation/fns/tests/index.test.ts

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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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 Bug Something isn't working label May 20, 2024
@rishabhrathod01 rishabhrathod01 self-assigned this May 20, 2024
@github-actions github-actions bot added Javascript Product Issues related to users writing javascript in appsmith Integrations Product Issues related to a specific integration Integrations Pod General Issues related to the Integrations Pod that don't fit into other tags. JS Evaluation Issues related to JS evaluation on the platform Needs Triaging Needs attention from maintainers to triage labels May 20, 2024
@rishabhrathod01 rishabhrathod01 added the ok-to-test Required label for CI label May 20, 2024
@rishabhrathod01 rishabhrathod01 requested a review from sneha122 May 20, 2024 21:17
@rishabhrathod01 rishabhrathod01 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels May 20, 2024
@sneha122
Copy link
Contributor

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/9169204952.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 33600.
recreate: .

@github-actions github-actions bot added Query & JS Pod Issues related to the query & JS Pod High This issue blocks a user from building or impacts a lot of users labels May 21, 2024
@rishabhrathod01 rishabhrathod01 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels May 21, 2024
@rishabhrathod01
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/9170559529.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 33600.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-33600.dp.appsmith.com

@ApekshaBhosale
Copy link
Contributor

@rishabhrathod01 in the issue created you have written "resetWidget function causes the next async method to be undefined". so we need to switch it back to async for next method. why can't we do this before calling next async rather than depending on previous one to be in the right context?

@rishabhrathod01
Copy link
Contributor Author

in the issue created you have written "resetWidget function causes the next async method to be undefined". so we need to switch it back to async for next method. why can't we do this before calling next async rather than depending on previous one to be in the right context?

@ApekshaBhosale

  1. As the next async method will be undefined in the eval context, we won't be able to trigger the switch of sync to async evaluation as we won't know when the code got executed.

For example:-

resetWidget(WidgetName);
Api.run();

Here once the resetWidget is executed, we won't be able to switch back to async eval as Api.run() itself is not defined to let us know if this was called. Also, we want to default evaluation context to be always async this is because any async operation could be picked from the task queue.

  1. By design itself, an async method is not supposed to change the evaluation from async to sync, in the case of resetWidget it was a bug that internally it was doing a sync eval but we didn’t switch back.

@ApekshaBhosale
Copy link
Contributor

in the issue created you have written "resetWidget function causes the next async method to be undefined". so we need to switch it back to async for next method. why can't we do this before calling next async rather than depending on previous one to be in the right context?

@ApekshaBhosale

  1. As the next async method will be undefined in the eval context, we won't be able to trigger the switch of sync to async evaluation as we won't know when the code got executed.

For example:-

resetWidget(WidgetName);
Api.run();

Here once the resetWidget is executed, we won't be able to switch back to async eval as Api.run() itself is not defined to let us know if this was called. Also, we want to default evaluation context to be always async this is because any async operation could be picked from the task queue.

  1. By design itself, an async method is not supposed to change the evaluation from async to sync, in the case of resetWidget it was a bug that internally it was doing a sync eval but we didn’t switch back.

Understood! then reset Widget should be in async always isn't it? rather than setting it back. AFAIK we were treating all Appsmith platform functions as async and executing them in async context. @rishabhrathod01

@rishabhrathod01
Copy link
Contributor Author

Understood! then reset Widget should be in async always isn't it? rather than setting it back. AFAIK we were treating all Appsmith platform functions as async and executing them in async context. @rishabhrathod0

@ApekshaBhosale resetWidget is an async API as shown in below code screenshot.
image

We added an sync evaluation inside the resetWidget to fix bug explained in this comment https://github.com/appsmithorg/appsmith/pull/29151/files#r1607899227

@rishabhrathod01 rishabhrathod01 merged commit 263448c into release May 21, 2024
42 checks passed
@rishabhrathod01 rishabhrathod01 deleted the fix/resetWidgetIssue branch May 21, 2024 10:13
@coderabbitai coderabbitai bot mentioned this pull request Jan 9, 2025
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working High This issue blocks a user from building or impacts a lot of users Integrations Pod General Issues related to the Integrations Pod that don't fit into other tags. Integrations Product Issues related to a specific integration Javascript Product Issues related to users writing javascript in appsmith JS Evaluation Issues related to JS evaluation on the platform Needs Triaging Needs attention from maintainers to triage ok-to-test Required label for CI Query & JS Pod Issues related to the query & JS Pod
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: resetWidget function causes the next async method to be undefined
3 participants