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: JSObject diff error when actions are missing #38572

Merged
merged 3 commits into from
Jan 18, 2025

Conversation

ashit-rath
Copy link
Contributor

@ashit-rath ashit-rath commented Jan 10, 2025

Description

This PR fixes 2 issues
Issue 1 - No function available in the dropdown of a valid JS Module in JS Module editor
Due to some reason the actions property in the JSObject is missing instead of being [], due to this when the check is done for getting the diff const preExisted = jsAction.actions.find((js) => js.name === action.name); the .find is on an undefined value. The actual reason of the actions to be missing is yet to be discovered but this is added to add guard against such failures.

Issue 2 - When a function is removed from a JSModule, a silent error is thrown by the splice
TypeError: Cannot delete property '0' of [object Array]
The reason for this is that the jsObject are directly being mutated for an object where the writable property is false.
Upon verifying the code block removed from line 145-155 has no use since it just updates the jsActions object which neither is used by subsequent code of the function nor the caller of this function.
Also splicing directly on redux selector data mutates the redux store directly which is a bad practice.
So technically it's a piece of code that is unused, thus removing it fixes the problem

Fixes #38683

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/12802464049
Commit: 316f0ae
Cypress dashboard.
Tags: @tag.All
Spec:


Thu, 16 Jan 2025 11:54:27 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling in JS collection updates by ensuring proper array initialization
    • Enhanced action comparison logic to handle undefined action arrays more gracefully
  • Refactor

    • Simplified action comparison and deletion process in JS collection utilities

Copy link
Contributor

coderabbitai bot commented Jan 10, 2025

Walkthrough

The pull request introduces modifications to two files: JSPaneSagas.ts and JSPaneUtils.tsx. The changes focus on improving the robustness of JavaScript collection action handling by adding null checks and simplifying action processing logic. The modifications ensure that action arrays are properly initialized and prevent potential runtime errors when manipulating JavaScript actions.

Changes

File Change Summary
app/client/src/sagas/JSPaneSagas.ts Added initialization check for actions array in handleEachUpdateJSCollection generator function
app/client/src/utils/JSPaneUtils.tsx Updated action finding logic with null-safe array access and removed archived action deletion logic

Assessment against linked issues

Objective Addressed Explanation
JS Module functions missing in dropdown selector Unable to definitively confirm full resolution without more context

Possibly related PRs

Suggested labels

JS Objects, Javascript Product, Query & JS Pod, Needs Triaging

Suggested reviewers

  • dvj1988
  • ankitakinger
  • sondermanish

Poem

Code flows like water, smooth and clear
Null checks dance, errors disappear
JavaScript actions, now robust and bright
Sagas weave magic in the developer's sight! 🧙‍♂️✨

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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 Jan 10, 2025
@ashit-rath ashit-rath self-assigned this Jan 16, 2025
@ashit-rath ashit-rath added the ok-to-test Required label for CI label Jan 16, 2025
@ashit-rath
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

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

Copy link

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

@github-actions github-actions bot added the Task A simple Todo label Jan 16, 2025
@ashit-rath
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

@ashit-rath ashit-rath marked this pull request as ready for review January 16, 2025 05:06
Copy link

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

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

🧹 Nitpick comments (1)
app/client/src/utils/JSPaneUtils.tsx (1)

54-56: LGTM! Defensive null check added.

The null check prevents the TypeError when actions are undefined. Consider using optional chaining for a more modern approach.

-      const preExisted = (jsAction.actions || []).find(
+      const preExisted = jsAction.actions?.find(
         (js) => js.name === action.name,
       );
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 71ff3ee and 316f0ae.

📒 Files selected for processing (2)
  • app/client/src/sagas/JSPaneSagas.ts (1 hunks)
  • app/client/src/utils/JSPaneUtils.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-check-cyclic-deps / check-cyclic-dependencies
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-build / client-build
  • GitHub Check: client-prettier / prettier-check
🔇 Additional comments (1)
app/client/src/sagas/JSPaneSagas.ts (1)

211-216: LGTM! Proper initialization of actions array.

This change ensures that the actions array is always initialized before any operations are performed on it, preventing potential null reference errors.

Copy link

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

@ashit-rath ashit-rath merged commit 86bddaa into release Jan 18, 2025
88 checks passed
@ashit-rath ashit-rath deleted the fix/js-update-for-module branch January 18, 2025 04:18
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Feb 7, 2025
## Description
This PR fixes 2 issues
<em>Issue 1<em> - No function available in the dropdown of a valid JS
Module in JS Module editor
Due to some reason the actions property in the JSObject is missing
instead of being `[]`, due to this when the check is done for getting
the diff `const preExisted = jsAction.actions.find((js) => js.name ===
action.name);` the `.find` is on an `undefined` value. The actual reason
of the `actions` to be missing is yet to be discovered but this is added
to add guard against such failures.

<em>Issue 2<em> - When a function is removed from a JSModule, a silent
error is thrown by the splice
`TypeError: Cannot delete property '0' of [object Array]`
The reason for this is that the jsObject are directly being mutated for
an object where the `writable` property is `false`.
Upon verifying the code block removed from line 145-155 has no use since
it just updates the jsActions object which neither is used by subsequent
code of the function nor the caller of this function.
Also splicing directly on redux selector data mutates the redux store
directly which is a bad practice.
So technically it's a piece of code that is unused, thus removing it
fixes the problem



Fixes appsmithorg#38683

## 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/12802464049>
> Commit: 316f0ae
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12802464049&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Thu, 16 Jan 2025 11:54:27 UTC
<!-- end of auto-generated comment: Cypress test results  -->


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


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

## Summary by CodeRabbit

- **Bug Fixes**
- Improved error handling in JS collection updates by ensuring proper
array initialization
- Enhanced action comparison logic to handle undefined action arrays
more gracefully

- **Refactor**
- Simplified action comparison and deletion process in JS collection
utilities

<!-- 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
Bug Something isn't working ok-to-test Required label for CI Task A simple Todo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] JS Module functions missing in dropdown selector to Run
3 participants