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: vue received a Component that was made a reactive object #4367

Merged
merged 1 commit into from
Sep 11, 2024
Merged

Conversation

likui628
Copy link
Collaborator

@likui628 likui628 commented Sep 11, 2024

Description

[Vue warn]: Vue received a Component that was made a reactive object. This can lead to unnecessary performance overhead and should be avoided by marking the component with markRaw or using shallowRef instead of ref.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Checklist

ℹ️ Check all checkboxes - this will indicate that you have done everything in accordance with the rules in CONTRIBUTING.

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs:dev command.
  • Run the tests with pnpm test.
  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Summary by CodeRabbit

  • New Features

    • Introduced a utility function deepToRaw for converting reactive objects to their raw counterparts, enhancing data handling.
    • Added new dependencies to improve modularity and functionality across various components.
  • Enhancements

    • Updated tabs.vue and menu.vue components to utilize the deepToRaw utility for better performance and data management.
    • Made the menus property in the menu.vue component required, ensuring stricter type enforcement.
  • Bug Fixes

    • Adjusted how tab data is processed to prevent unintended side effects related to Vue's reactivity.

Copy link

changeset-bot bot commented Sep 11, 2024

⚠️ No Changeset found

Latest commit: c9d0133

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Sep 11, 2024

Walkthrough

The pull request introduces several changes across multiple files, primarily involving the addition of new dependencies and the implementation of a utility function for handling Vue's reactivity. A new utility function, deepToRaw, is created to convert reactive objects into their raw forms. Additionally, components within the UI kit are updated to utilize this new utility, ensuring that the handling of tab and menu data is optimized. The modifications also enforce stricter type definitions for properties in certain components.

Changes

File Change Summary
packages/@core/base/shared/package.json Added dependency "@vue/reactivity": "^3.5.4" to enhance functionality.
packages/@core/base/shared/src/utils/index.ts Added export statement for the reactivity module.
packages/@core/base/shared/src/utils/reactivity.ts Introduced deepToRaw function to convert reactive objects to raw values.
packages/@core/ui-kit/tabs-ui/package.json Added dependency "@vben-core/shared": "workspace:*" for shared functionalities.
packages/@core/ui-kit/tabs-ui/src/components/tabs-chrome/tabs.vue Imported deepToRaw and modified tabsView computed property to process tab data.
packages/@core/ui-kit/tabs-ui/src/components/tabs/tabs.vue Imported deepToRaw and modified tabsView computed property to process tab data.
packages/effects/layouts/src/basic/layout.vue Modified wrapperMenus function to apply deepToRaw on menu items.
packages/effects/layouts/src/basic/menu/menu.vue Changed menus property from optional to required in the Props interface.

Sequence Diagram(s)

sequenceDiagram
    participant A as Component
    participant B as Tabs
    participant C as Menu

    A->>B: Pass tabs data
    B->>B: Process tabs with deepToRaw
    B->>A: Return processed tabs

    A->>C: Pass menu data
    C->>C: Process menus with deepToRaw
    C->>A: Return processed menus
Loading

Poem

🐇 In the meadow where changes bloom,
A utility hops, dispelling gloom.
With deepToRaw, our data's free,
No more wrappers, just pure glee!
Tabs and menus dance with grace,
In this code, we find our place! 🌼


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8f6bf6a and c9d0133.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (8)
  • packages/@core/base/shared/package.json (1 hunks)
  • packages/@core/base/shared/src/utils/index.ts (1 hunks)
  • packages/@core/base/shared/src/utils/reactivity.ts (1 hunks)
  • packages/@core/ui-kit/tabs-ui/package.json (1 hunks)
  • packages/@core/ui-kit/tabs-ui/src/components/tabs-chrome/tabs.vue (2 hunks)
  • packages/@core/ui-kit/tabs-ui/src/components/tabs/tabs.vue (2 hunks)
  • packages/effects/layouts/src/basic/layout.vue (2 hunks)
  • packages/effects/layouts/src/basic/menu/menu.vue (1 hunks)
Files skipped from review due to trivial changes (1)
  • packages/@core/base/shared/src/utils/index.ts
Additional comments not posted (8)
packages/@core/base/shared/src/utils/reactivity.ts (1)

3-24: LGTM!

The deepToRaw function looks good:

  • It correctly handles different types of inputs (arrays, reactive objects, plain objects) and recursively converts reactive objects to plain objects.
  • It maintains the type information of the input object using a type parameter T.
  • It uses Object.prototype.hasOwnProperty.call to safely check for the existence of properties.
  • The function is exported correctly using a named export.

The code changes are approved.

packages/@core/ui-kit/tabs-ui/package.json (1)

43-43: LGTM, but verify the package usage.

The addition of the new dependency @vben-core/shared is approved.

However, ensure that the @vben-core/shared package is actually being used in the tabs-ui package. If it's not being used, consider removing it to avoid unnecessary dependencies.

Run the following script to verify the package usage:

packages/@core/base/shared/package.json (1)

74-74: Dependency addition looks good, but the corresponding code changes are missing.

The addition of @vue/reactivity dependency with version constraint ^3.5.4 is approved as it aligns with the PR objective of addressing the Vue warning related to reactive objects.

However, the PR summary mentions using markRaw or shallowRef to resolve the warning, but the corresponding code changes are not provided in this file.

Could you please provide the code changes that demonstrate the usage of markRaw or shallowRef as mentioned in the PR summary? This will help ensure that the changes are complete and the warning is properly addressed.

packages/@core/ui-kit/tabs-ui/src/components/tabs/tabs.vue (2)

10-10: LGTM!

The new import statement for the deepToRaw utility is correctly written.


50-51: LGTM, but verify the impact on the application.

The changes in the tabsView computed property are correctly implemented.

Using deepToRaw likely ensures that the tab objects are converted to their raw form, potentially affecting how reactivity is handled in Vue. This change indicates a shift in how tab data is managed, possibly improving performance or ensuring that the data structure adheres to specific requirements.

Please ensure that this change is thoroughly tested to confirm that it behaves as expected and does not introduce any unintended side effects or break existing functionality related to the tabs.

Run the following script to verify the usage of the tabsView computed property:

Verification successful

Changes to tabsView are correctly implemented and consistent with its intended usage.

The tabsView computed property is used in the tabs.vue and tabs-chrome/tabs.vue components to iterate over tab data and render elements conditionally. The use of deepToRaw ensures that tab data is in a raw form, likely preventing reactivity issues and improving performance. No issues were found related to its usage.

  • tabs.vue: Usage in v-for loops and conditional rendering.
  • tabs-chrome/tabs.vue: Similar usage pattern as in tabs.vue.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `tabsView` computed property.

# Test: Search for the usage of `tabsView`. Expect: No errors or warnings related to the usage.
rg --type vue -A 5 $'tabsView'

Length of output: 57


Script:

#!/bin/bash
# Description: Verify the usage of the `tabsView` computed property by searching for it in all .vue files.

# Test: Search for the usage of `tabsView` in .vue files. Expect: No errors or warnings related to the usage.
rg 'tabsView' --glob '**/*.vue' -A 5

Length of output: 5239

packages/@core/ui-kit/tabs-ui/src/components/tabs-chrome/tabs.vue (2)

10-10: LGTM!

The code change is approved.


44-45: LGTM!

The code change is approved.

As mentioned in the PR summary, applying deepToRaw to the tab objects ensures that they are reactive and stripped of any Vue reactivity wrappers. This change could improve performance or prevent unintended side effects in the component's behavior.

packages/effects/layouts/src/basic/layout.vue (1)

114-117: LGTM! The use of deepToRaw helps avoid unnecessary reactivity overhead.

The changes in the wrapperMenus function are approved.

The use of deepToRaw is a good practice to ensure that the menu items are converted to plain objects before being returned. This helps avoid the Vue warning about receiving a component that was made a reactive object, which can lead to unnecessary performance overhead.

By converting the menu items to plain objects, the function ensures that the returned menu items are not wrapped in Vue's reactivity system, potentially improving performance and avoiding unexpected behavior when manipulating the menu items.


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

CodeRabbit Configuration 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.

@anncwb anncwb added the bug Something isn't working label Sep 11, 2024
@anncwb anncwb merged commit 61faa18 into main Sep 11, 2024
13 checks passed
@anncwb anncwb deleted the toRaw branch September 11, 2024 14:56
WitMiao pushed a commit to WitMiao/vue-vben-admin that referenced this pull request Sep 12, 2024
kkfive pushed a commit to kkfive/vue-vben-admin that referenced this pull request Sep 14, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Oct 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants