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

using mutative #38950

Open
wants to merge 1 commit into
base: release
Choose a base branch
from
Open

using mutative #38950

wants to merge 1 commit into from

Conversation

vsvamsi1
Copy link
Contributor

@vsvamsi1 vsvamsi1 commented Feb 2, 2025

Description

Tip

Add a TL;DR when the description is longer than 500 words or extremely technical (helps the content, marketing, and DevRel team).

Please also include relevant motivation and context. List any dependencies that are required for this change. Add links to Notion, Figma or any other documents that might be relevant to the PR.

Fixes #Issue Number
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.All"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/13095907366
Commit: f99a60c
Cypress dashboard.
Tags: @tag.All
Spec:


Sun, 02 Feb 2025 07:18:51 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • Chores / Refactor

    • Updated internal state management across the application using a new dependency.
    • Removed obsolete development-only behavior for cleaner operations.
  • Tests

    • Updated test cases to ensure alignment with the new state update approach.

These changes improve maintainability and internal performance while keeping user-facing functionality consistent.

@vsvamsi1 vsvamsi1 requested review from AnaghHegde and removed request for a team February 2, 2025 05:21
@vsvamsi1 vsvamsi1 self-assigned this Feb 2, 2025
Copy link
Contributor

coderabbitai bot commented Feb 2, 2025

Walkthrough

This pull request replaces the usage of the immer library’s produce function with the mutative library’s create function across the codebase. A new dependency, "mutative": "^1.1.0", has been added to the project. Multiple files in components, reducers, hooks, sagas, and tests have been updated to adopt this new state management approach. Additionally, the related autofreeze functionality in the entry file has been removed, thereby eliminating reliance on an immer-specific feature.

Changes

File(s) Change Summary
app/client/package.json Added dependency: "mutative": "^1.1.0" to the dependencies section.
app/client/src/{WidgetProvider/factory,index.tsx}, app/client/src/components/{editorComponents/WidgetQueryGeneratorForm,index.tsx,propertyControls/ButtonTabControl.tsx} Replaced immer's produce with mutative's create in component logic and factory functions for immutable state updates.
app/client/src/{ce/reducers/entityReducers/jsActionsReducer.tsx, ce/reducers/uiReducers/applicationsReducer.tsx, reducers/entityReducers/{datasourceReducer.ts, metaReducer/index.ts, metaReducer/metaReducerUtils.ts}, utils/ReducerUtils.ts Updated reducers and related utilities to use create instead of produce for state modifications.
app/client/src/ce/pages/Editor/Explorer/hooks.tsx Replaced produce with create in various hooks managing component state.
app/client/src/sagas/WidgetAdditionSagas.ts Swapped produce for create to handle state updates during widget addition workflows.
app/client/src/workers/{Evaluation/__tests__/generateOpimisedUpdates.test.ts, Evaluation/evalTreeWithChanges.test.ts, common/DataTreeEvaluator/utils.test.ts} Modified tests to adopt mutative’s create in place of immer’s produce, preserving test logic.
app/client/src/index.tsx Removed setAutoFreeze import, variable, and function call, eliminating the autofreeze mechanism previously set based on the environment.

Sequence Diagram(s)

sequenceDiagram
    participant Code as Application Code
    participant Mutative as mutative Library
    participant Reducer as Reducer/State Manager
    participant Test as Automated Tests

    Code->>Mutative: Call create(state, draft => {...})
    Mutative-->>Code: Return updated state
    Code->>Reducer: Update state using new mechanism
    Reducer-->>Code: State updated response
    Test->>Mutative: Invoke create in test cases
    Mutative-->>Test: Provide drafted state for validation
Loading

Possibly related PRs

Suggested labels

Enhancement, skip-changelog, ok-to-test

Suggested reviewers

  • ApekshaBhosale
  • ankitakinger
  • sagar-qa007

Poem

In our code a change takes flight,
From immer's grip to mutative light.
State flows smooth with every tweak,
A dance of functions, precise and sleek.
Cheers to changes that make our code shine bright!
🚀✨

✨ 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.

@vsvamsi1 vsvamsi1 added the ok-to-test Required label for CI label Feb 2, 2025
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 (2)
app/client/src/utils/ReducerUtils.ts (1)

23-42: Consider renaming createImmerReducer to reflect the use of mutative.

The function name is now misleading as it uses the mutative library instead of immer.

-export const createImmerReducer = (
+export const createMutativeReducer = (
🧰 Tools
🪛 Biome (1.9.4)

[error] 34-34: Do not access Object.prototype method 'hasOwnProperty' from target object.

It's recommended using Object.hasOwn() instead of using Object.hasOwnProperty().
See MDN web docs for more details.

(lint/suspicious/noPrototypeBuiltins)

app/client/src/components/propertyControls/ButtonTabControl.tsx (1)

65-67: Simplify the mutative array update.

The current implementation can be simplified by returning the new array directly.

-      const updatedValues: string[] = create(values, (draft: string[]) => {
-        draft.push(value);
-      });
+      const updatedValues = create(values, (draft: string[]) => {
+        return [...draft, value];
+      });
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 81c5d47 and f99a60c.

⛔ Files ignored due to path filters (1)
  • app/client/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (16)
  • app/client/package.json (1 hunks)
  • app/client/src/WidgetProvider/factory/index.tsx (2 hunks)
  • app/client/src/ce/pages/Editor/Explorer/hooks.tsx (4 hunks)
  • app/client/src/ce/reducers/entityReducers/jsActionsReducer.tsx (2 hunks)
  • app/client/src/ce/reducers/uiReducers/applicationsReducer.tsx (2 hunks)
  • app/client/src/components/editorComponents/WidgetQueryGeneratorForm/index.tsx (2 hunks)
  • app/client/src/components/propertyControls/ButtonTabControl.tsx (2 hunks)
  • app/client/src/index.tsx (1 hunks)
  • app/client/src/reducers/entityReducers/datasourceReducer.ts (7 hunks)
  • app/client/src/reducers/entityReducers/metaReducer/index.ts (4 hunks)
  • app/client/src/reducers/entityReducers/metaReducer/metaReducerUtils.ts (2 hunks)
  • app/client/src/sagas/WidgetAdditionSagas.ts (2 hunks)
  • app/client/src/utils/ReducerUtils.ts (2 hunks)
  • app/client/src/workers/Evaluation/__tests__/generateOpimisedUpdates.test.ts (27 hunks)
  • app/client/src/workers/Evaluation/evalTreeWithChanges.test.ts (9 hunks)
  • app/client/src/workers/common/DataTreeEvaluator/utils.test.ts (5 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
app/client/src/workers/Evaluation/__tests__/generateOpimisedUpdates.test.ts

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

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


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

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

app/client/src/workers/common/DataTreeEvaluator/utils.test.ts

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

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-check-cyclic-deps / check-cyclic-dependencies
  • GitHub Check: client-build / client-build
  • GitHub Check: client-prettier / prettier-check
  • GitHub Check: client-lint / client-lint
🔇 Additional comments (15)
app/client/src/utils/ReducerUtils.ts (1)

35-37: LGTM! Clean migration to mutative.

The migration pattern correctly preserves immutability semantics while switching to the mutative library.

app/client/src/index.tsx (1)

25-26: Verify development-time mutation detection after removing autofreeze.

With the removal of Immer's autofreeze, ensure that mutative provides equivalent development-time safeguards against accidental mutations.

app/client/src/reducers/entityReducers/metaReducer/metaReducerUtils.ts (1)

85-91: LGTM! Clean migration preserving nested update logic.

The migration to mutative correctly maintains the complex state update logic using path-based setters.

app/client/src/reducers/entityReducers/metaReducer/index.ts (1)

14-14: LGTM! State updates look correct with mutative.

The transition from immer's produce to mutative's create is implemented correctly across all reducer cases. The immutability pattern is preserved.

Also applies to: 41-51, 57-67, 73-83

app/client/src/workers/common/DataTreeEvaluator/utils.test.ts (1)

9-9: LGTM! Test cases correctly updated to use mutative.

The transition to mutative is correctly implemented in test cases. While there's a static analysis warning about the delete operator, it's acceptable in test code.

Also applies to: 173-176, 190-192, 198-201, 216-218, 224-227, 242-245

app/client/src/components/editorComponents/WidgetQueryGeneratorForm/index.tsx (1)

2-2: LGTM! State updates in updateConfig are correctly implemented.

The transition to mutative maintains the same state update behavior while preserving all edge case handling.

Also applies to: 182-223

app/client/src/ce/pages/Editor/Explorer/hooks.tsx (1)

9-9: LGTM! Hooks correctly updated to use mutative.

The transition to mutative preserves the existing filtering logic and performance measurements. Array mutations are handled correctly.

Also applies to: 187-208, 228-241, 259-270

app/client/src/ce/reducers/entityReducers/jsActionsReducer.tsx (1)

9-9: LGTM! Clean migration from immer to mutative.

The migration maintains the same immutable state update pattern and functionality.

Also applies to: 403-418

app/client/src/workers/Evaluation/evalTreeWithChanges.test.ts (1)

7-7: LGTM! Consistent migration in test cases.

All test cases have been updated to use mutative while maintaining the same test coverage and assertions.

Also applies to: 262-265, 314-316, 349-353, 389-393, 429-433, 459-463, 498-502, 536-540

app/client/src/sagas/WidgetAdditionSagas.ts (1)

23-23: LGTM! Clean migration in widget props handling.

The state update logic for widget props remains intact with the new library.

Also applies to: 115-119

app/client/src/WidgetProvider/factory/index.tsx (1)

38-38: LGTM! Clean migration in widget property pane configuration.

The property pane configuration update logic remains intact with the new library.

Also applies to: 421-423

app/client/package.json (1)

164-164: Verify mutative version compatibility.

The addition of mutative alongside immer could lead to potential state management conflicts. Consider removing immer after the migration is complete.

Run the following script to check for any version conflicts or security advisories:

✅ Verification successful

Mutative version compatibility verified.

  • The npm query confirms that mutative is correctly set to version 1.1.0.
  • No security advisories or reported vulnerabilities were found.
  • Although both mutative and immer coexist, no inherent version conflicts were detected. Consider removing immer after the migration is complete if it's no longer needed.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for version conflicts and security advisories

# Check npm for latest version and any security advisories
curl -s "https://registry.npmjs.org/mutative" | jq '.["dist-tags"].latest,.time.modified'

# Check for any reported vulnerabilities
gh api graphql -f query='
{
  securityVulnerabilities(first: 5, ecosystem: NPM, package: "mutative") {
    nodes {
      advisory {
        summary
        severity
        publishedAt
      }
      vulnerableVersionRange
      firstPatchedVersion {
        identifier
      }
    }
  }
}'

Length of output: 466

app/client/src/reducers/entityReducers/datasourceReducer.ts (1)

469-476: LGTM! Clean migration to mutative.

The state updates using mutative's create function are implemented correctly, maintaining immutability and type safety.

Also applies to: 659-661, 667-673, 679-685, 688-690, 696-701, 707-712, 715-717, 723-728, 734-739

app/client/src/workers/Evaluation/__tests__/generateOpimisedUpdates.test.ts (1)

113-115: LGTM! Test cases properly updated.

The migration to mutative's create function is thorough and maintains test coverage. The use of delete operator in tests is acceptable.

Also applies to: 122-125, 134-136, 148-150, 182-184, 207-209, 210-215, 247-249, 305-308, 336-339, 380-386, 387-394, 446-448, 475-481, 482-485, 491-493, 507-509, 555-557, 586-593, 631-640, 661-668

app/client/src/ce/reducers/uiReducers/applicationsReducer.tsx (1)

533-542: LGTM! Proper null checks in place.

The state update using mutative's create function is implemented correctly with proper null checks for optional navigationSetting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test Required label for CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant