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: js library load functionality handling for default exports #36539

Merged
merged 3 commits into from
Sep 26, 2024

Conversation

AmanAgarwal041
Copy link
Contributor

@AmanAgarwal041 AmanAgarwal041 commented Sep 25, 2024

Description

When the library which exports as default was installed, it was being handled to add the functionality to the new accessor name generated from the url. This was fixed from the pr : #36483
When the application page is refreshed the installed library get loaded again, which was again installing the library to default accessor. This PR handles the accessor to be which was already assigned while installing the library.

Fixes #36530
or
Fixes Issue URL

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

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/11049788382
Commit: 1cf092e
Cypress dashboard.
Tags: @tag.JS
Spec:


Thu, 26 Sep 2024 10:46:34 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of default exports from imported libraries for better clarity and functionality.

Copy link
Contributor

coderabbitai bot commented Sep 25, 2024

Walkthrough

The changes in this pull request enhance the handling of default exports in the loadLibraries function. The logic has been refined to ensure that default exports are correctly assigned unique names, which helps maintain the integrity of the self object after libraries are reloaded. This update aims to resolve issues with library functionality following page reloads.

Changes

File Change Summary
app/client/src/workers/Evaluation/handlers/jsLibrary.ts Updated installLibrary and loadLibraries functions to streamline handling of default exports.

Assessment against linked issues

Objective Addressed Explanation
Ensure library with default export works after reload (#36530)

Possibly related PRs

Suggested reviewers

  • rishabhrathod01

In the realm of code, a change takes flight,
Default exports now shine so bright.
With libraries loaded, and functions anew,
Reload with ease, let the magic ensue!
A bug once lurking, now fades from sight,
Thanks to the tweaks, everything feels right! 🌟


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 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 Bug Something isn't working Community Reported issues reported by community members Custom JS Libraries Issues related to adding custom JS library High This issue blocks a user from building or impacts a lot of users Javascript Product Issues related to users writing javascript in appsmith Needs Triaging Needs attention from maintainers to triage Production Query & JS Pod Issues related to the query & JS Pod labels Sep 25, 2024
@AmanAgarwal041 AmanAgarwal041 added the ok-to-test Required label for CI label Sep 25, 2024
@AmanAgarwal041
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/11032788578.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 36539.
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: 1

🧹 Outside diff range and nitpick comments (1)
app/client/src/workers/Evaluation/handlers/jsLibrary.ts (1)

325-331: Use 'forEach' Instead of 'map' for Iteration with Side Effects

In this block, you're using map to iterate over defaultAccessors and perform operations, but map is intended to create a new array based on the return values. Since the returned array isn't used, forEach is more appropriate for iterating when you're not collecting results.

Consider changing the code to:

-defaultAccessors.map((key) => {
+defaultAccessors.forEach((key) => {

This change clarifies your intent and avoids confusion about unused return values.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2f2f5a6 and 2335fc6.

📒 Files selected for processing (1)
  • app/client/src/workers/Evaluation/handlers/jsLibrary.ts (1 hunks)
🧰 Additional context used
Biome
app/client/src/workers/Evaluation/handlers/jsLibrary.ts

[error] 323-323: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

🔇 Additional comments not posted (1)
app/client/src/workers/Evaluation/handlers/jsLibrary.ts (1)

323-323: ⚠️ Potential issue

Consider Avoiding the 'delete' Operator for Performance

Using the delete operator can negatively impact performance because it alters the object's structure, leading to de-optimization in JavaScript engines. Instead, assigning undefined to the property maintains the object's shape and is more efficient.

Let's modify the code as follows:

-delete self["default"];
+self["default"] = undefined;
⛔ Skipped due to learnings
Learnt from: rishabhrathod01
PR: appsmithorg/appsmith#36483
File: app/client/src/workers/Evaluation/handlers/jsLibrary.ts:152-158
Timestamp: 2024-09-24T10:45:10.162Z
Learning: Replacing `delete self[key];` with `self[key] = undefined;` in the `installLibrary` function of `jsLibrary.ts` causes bugs in the product. Therefore, we should continue using the `delete` operator when removing properties from `self`.
🧰 Tools
Biome

[error] 323-323: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

app/client/src/workers/Evaluation/handlers/jsLibrary.ts Outdated Show resolved Hide resolved
Copy link

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

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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2335fc6 and 1cf092e.

📒 Files selected for processing (1)
  • app/client/src/workers/Evaluation/handlers/jsLibrary.ts (3 hunks)
🧰 Additional context used
🪛 Biome
app/client/src/workers/Evaluation/handlers/jsLibrary.ts

[error] 463-463: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

🔇 Additional comments (2)
app/client/src/workers/Evaluation/handlers/jsLibrary.ts (2)

131-155: Well done on improving the handling of default exports!

Class, let's take a moment to appreciate the improvements made to the installLibrary function. The changes here show a good understanding of how to handle default exports more effectively.

  1. The logic for determining differentiating keys has been streamlined, making it easier to follow.
  2. The new function movetheDefaultExportedLibraryToAccessorKey encapsulates the logic for mapping default exports to unique accessor names, which is a great example of code organization.
  3. By reassessing the differentiating keys after the default export operation, we ensure that all changes are properly accounted for.

These modifications will make our library installation process more robust and easier to maintain. Keep up the good work!


303-314: Excellent work on maintaining consistency!

Class, let's examine the improvements made to the loadLibraries function. It's crucial to maintain consistency across related functions, and that's exactly what has been achieved here.

  1. The handling of default exports now mirrors the approach used in the installLibrary function.
  2. By calling movetheDefaultExportedLibraryToAccessorKey, we ensure that default exports are handled uniformly throughout the codebase.
  3. The reassessment of default accessors after the operation maintains the integrity of our library loading process.

This consistency will make our code more predictable and easier to understand. Remember, consistency is key in writing maintainable code!

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

@AmanAgarwal041 AmanAgarwal041 merged commit 347dba5 into release Sep 26, 2024
44 checks passed
@AmanAgarwal041 AmanAgarwal041 deleted the fix/js-library branch September 26, 2024 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Community Reported issues reported by community members Custom JS Libraries Issues related to adding custom JS library High This issue blocks a user from building or impacts a lot of users Javascript Product Issues related to users writing javascript in appsmith Needs Triaging Needs attention from maintainers to triage ok-to-test Required label for CI Production Query & JS Pod Issues related to the query & JS Pod
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: When the library with default export is installed, on reload the library doesn't work.
2 participants