Skip to content

feat(design-config): design-config adds arbitrary attribute features of global configuration components #3419

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

Merged
merged 5 commits into from
May 14, 2025

Conversation

zzcr
Copy link
Member

@zzcr zzcr commented May 13, 2025

feat(design-config): design-config添加全局配置组件任意属性特性
image

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Alert component content is now centered by default in demos and global configuration.
    • Enhanced component setup merges default design properties with user-defined properties for improved customization.
    • Design configuration is accessible within renderless APIs for greater flexibility.
  • Bug Fixes

    • Added a test verifying Alert content is centered as expected.
  • Chores

    • Minor formatting update in package configuration (no functional impact).
    • Updated demo description to clarify global design prop customization support starting from version 3.23.0.

Copy link

coderabbitai bot commented May 13, 2025

Walkthrough

The changes introduce and propagate a default center: true property for the Alert component within design configurations and ensure this behavior is reflected in both Vue 2 and Vue 3 adapters. The setup logic is enhanced to merge design-specific props with user props, and a new utility, getCustomProps, is added across Vue adapters. A related test and configuration demos are updated accordingly.

Changes

File(s) Change Summary
examples/sites/demos/pc/app/config-provider/base.vue
examples/sites/demos/pc/app/config-provider/base-composition-api.vue
Added center: true to the props of the Alert component in the design config, centering alert content by default.
examples/sites/demos/pc/app/config-provider/basic.spec.ts Extended test to assert that .tiny-alert has justify-content: center style, verifying the new default.
packages/vue-common/src/adapter/vue2/index.ts
packages/vue-common/src/adapter/vue2.7/index.ts
packages/vue-common/src/adapter/vue3/index.ts
Added new exported function getCustomProps to retrieve the current component's props; updated renderComponent to accept and merge customDesignProps.
packages/vue-common/src/index.ts Refactored $setup to merge design config props with user props; introduced getDesignConfig; updated setup to expose design config in renderless utils.
examples/sites/demos/pc/app/config-provider/webdoc/config-provider.js Updated description text for the "design" property to clarify version support and customization scope in both Chinese and English.
packages/vue/package.json Removed trailing newline; no functional changes.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Component
    participant $setup
    participant getDesignConfig
    participant getCustomProps
    participant renderComponent

    User->>Component: Uses Alert component
    Component->>$setup: Calls setup with props/context
    $setup->>getDesignConfig: Fetch design config (global & component)
    $setup->>getCustomProps: Retrieve user-passed props
    $setup->>renderComponent: Merge design props (e.g., center: true) with user props
    renderComponent-->>Component: Rendered with merged props
Loading

Poem

In the meadow of code, an alert stands tall,
Now centered with grace, admired by all.
With helpers for props, and configs that blend,
The rabbit ensures defaults and customs both mend.
Tests check the style, adapters align—
Hopping forward, the UI will shine!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

examples/sites/demos/pc/app/config-provider/webdoc/config-provider.js

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

packages/vue-common/src/adapter/vue2.7/index.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

packages/vue-common/src/adapter/vue2/index.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 22aeaf0 and 3e400b4.

📒 Files selected for processing (3)
  • examples/sites/demos/pc/app/config-provider/webdoc/config-provider.js (1 hunks)
  • packages/vue-common/src/adapter/vue2.7/index.ts (1 hunks)
  • packages/vue-common/src/adapter/vue2/index.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
packages/vue-common/src/adapter/vue2.7/index.ts (3)
packages/vue-common/src/index.ts (2)
  • hooks (412-412)
  • props (54-62)
packages/vue-common/src/adapter/vue2/index.ts (2)
  • rootConfig (57-57)
  • getCustomProps (59-62)
packages/vue-common/src/adapter/vue3/index.ts (2)
  • rootConfig (41-45)
  • getCustomProps (47-50)
packages/vue-common/src/adapter/vue2/index.ts (3)
packages/vue-common/src/index.ts (2)
  • hooks (412-412)
  • props (54-62)
packages/vue-common/src/adapter/vue2.7/index.ts (2)
  • rootConfig (48-48)
  • getCustomProps (50-53)
packages/vue-common/src/adapter/vue3/index.ts (2)
  • rootConfig (41-45)
  • getCustomProps (47-50)
🪛 Biome (1.9.4)
packages/vue-common/src/adapter/vue2.7/index.ts

[error] 35-35: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

packages/vue-common/src/adapter/vue2/index.ts

[error] 44-46: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: PR E2E Test (pnpm test:e2e3)
🔇 Additional comments (6)
packages/vue-common/src/adapter/vue2/index.ts (2)

37-37: Implementation of customDesignProps parameter in renderComponent

The addition of the customDesignProps parameter to the renderComponent function supports the feature to allow global configuration of arbitrary component props. This parameter will be used to pass design configuration properties to components.


59-62: Implementation of getCustomProps utility

The addition of the getCustomProps function is a good utility that retrieves the component's props data from the current instance. This is important for accessing user-provided props to merge with design configuration props.

packages/vue-common/src/adapter/vue2.7/index.ts (2)

29-29: Implementation of customDesignProps parameter in Vue 2.7 adapter

The addition of the customDesignProps parameter to the renderComponent function in Vue 2.7 adapter mirrors the change in the Vue 2 adapter, maintaining consistency across adapters.


50-53: Implementation of getCustomProps utility in Vue 2.7 adapter

The getCustomProps function is correctly implemented to retrieve props data from the current Vue 2.7 instance, consistent with the Vue 2 implementation but adapted for Vue 2.7 specifics.

examples/sites/demos/pc/app/config-provider/webdoc/config-provider.js (2)

15-15: Updated documentation for design property in Chinese

The description now clearly explains that from version 3.23.0, the global configuration supports customizing any props attribute for double-layer components. Good examples are provided to help users understand the feature's capabilities.


17-17: Updated documentation for design property in English

The English description has been updated to match the Chinese description, providing consistent documentation across languages. The text clearly explains the feature's capabilities and limitations.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@github-actions github-actions bot added the enhancement New feature or request (功能增强) label May 13, 2025
Copy link

Walkthrough

This PR introduces a feature to the design-config that allows global configuration components to accept arbitrary attributes. It includes updates to various Vue adapter files to support this functionality, as well as modifications to demo and test files to verify the new behavior.

Changes

Files Summary
base-composition-api.vue, base.vue Added props with center: true to components.
basic.spec.ts Added test to verify text alignment is centered.
index.ts (vue2.7, vue2, vue3) Introduced getCustomProps function to retrieve custom properties.
index.ts (vue-common) Refactored $setup and setup functions to incorporate customDesignProps.
package.json Minor version update.


Object.keys(designProps).forEach((key) => {
// 用户没有配置的属性才进行覆盖
if (!Object.prototype.hasOwnProperty.call(customProps, key)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that Object.prototype.hasOwnProperty.call is used correctly to avoid potential issues with objects that may not inherit from Object.prototype. This is a critical check to prevent unexpected behavior.

Copy link

@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: 2

🧹 Nitpick comments (3)
packages/vue-common/src/index.ts (3)

159-170: getDesignConfig – handle case-mismatch & null component names

getComponentName() may return an empty string for anonymous components, leading to an undefined lookup in globalDesignConfig.components.
Also, component names in user config might be written in different cases (e.g. alert, Alert, ALERT).

Consider normalising both sides to the same case and early-returning when no name is found:

-  const designConfig = globalDesignConfig?.components?.[getComponentName().replace($prefix, '')]
+  const compName = getComponentName()?.replace($prefix, '') || ''
+  const designConfig =
+    compName &&
+    Object.keys(globalDesignConfig?.components ?? {}).find(
+      (key) => key.toLowerCase() === compName.toLowerCase()
+    )
+      ? globalDesignConfig.components[
+          Object.keys(globalDesignConfig.components).find(
+            (key) => key.toLowerCase() === compName.toLowerCase()
+          )
+        ]
+      : undefined

This prevents subtle “config not applied” bugs when users write alert instead of Alert.


172-201: $setup – avoid recomputation of customProps inside computed

getCustomProps() relies on getCurrentInstance(); when called during setup it is cheap, but invoking it on every component instantiation is unnecessary.
Move the call outside the designProps loop to compute once:

-  const designProps = designConfig?.props
-  if (designProps) {
-    // 获取用户传递的props
-    const customProps = getCustomProps()
+  const designProps = designConfig?.props
+  const customProps = getCustomProps()
+  if (designProps) {

Negligible performance gain but improves readability.


202-208: mergeClass helper leaks tailwind-merge to every consumer

mergeClass calls customDesignConfig.twMerge directly. If a user replaces twMerge later (lazy injection), already-imported modules will still hold the old reference.

Export it as a function capturing the current twMerge at call time:

-export const mergeClass = (...cssClasses) => customDesignConfig.twMerge(stringifyCssClass(cssClasses))
+export const mergeClass = (...cssClasses) =>
+  (customDesignConfig.twMerge ?? ((v) => v))(stringifyCssClass(cssClasses))

Prevents runtime crashes when twMerge is swapped or not provided.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 580b065 and 14958c9.

📒 Files selected for processing (8)
  • examples/sites/demos/pc/app/config-provider/base-composition-api.vue (1 hunks)
  • examples/sites/demos/pc/app/config-provider/base.vue (1 hunks)
  • examples/sites/demos/pc/app/config-provider/basic.spec.ts (1 hunks)
  • packages/vue-common/src/adapter/vue2.7/index.ts (1 hunks)
  • packages/vue-common/src/adapter/vue2/index.ts (1 hunks)
  • packages/vue-common/src/adapter/vue3/index.ts (2 hunks)
  • packages/vue-common/src/index.ts (2 hunks)
  • packages/vue/package.json (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
packages/vue-common/src/adapter/vue2/index.ts (2)
packages/vue-common/src/adapter/vue2.7/index.ts (1)
  • getCustomProps (41-44)
packages/vue-common/src/adapter/vue3/index.ts (1)
  • getCustomProps (47-50)
packages/vue-common/src/adapter/vue2.7/index.ts (2)
packages/vue-common/src/adapter/vue2/index.ts (1)
  • getCustomProps (52-55)
packages/vue-common/src/adapter/vue3/index.ts (1)
  • getCustomProps (47-50)
packages/vue-common/src/adapter/vue3/index.ts (2)
packages/vue-common/src/adapter/vue2/index.ts (1)
  • getCustomProps (52-55)
packages/vue-common/src/adapter/vue2.7/index.ts (1)
  • getCustomProps (41-44)
packages/vue-common/src/index.ts (1)
packages/vue-common/src/adapter/vue3/index.ts (3)
  • getComponentName (52-61)
  • getCustomProps (47-50)
  • renderComponent (25-39)
🪛 Biome (1.9.4)
packages/vue-common/src/adapter/vue3/index.ts

[error] 35-35: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: PR E2E Test (pnpm test:e2e3)
🔇 Additional comments (6)
packages/vue-common/src/adapter/vue2/index.ts (1)

52-55: Well-implemented utility function to support arbitrary attributes

This getCustomProps function elegantly retrieves the component instance's props data, allowing access to user-defined props. This is essential for the design-config feature to support arbitrary attributes in global configuration components.

The implementation correctly handles potential undefined values using optional chaining and provides a fallback empty object. It's also consistent with the similar implementations in Vue 2.7 and Vue 3 adapters.

packages/vue/package.json (1)

240-240: LGTM - Minor whitespace change

The only change is the removal of a trailing newline, which is a trivial formatting change with no functional impact.

examples/sites/demos/pc/app/config-provider/base-composition-api.vue (1)

56-58: Well-implemented design configuration attribute

Adding the center: true prop to the Alert component's design configuration demonstrates the new arbitrary attribute feature. This change makes the Alert component's text centered by default when using this design configuration.

The implementation is clean and properly structured within the existing configuration object.

examples/sites/demos/pc/app/config-provider/basic.spec.ts (1)

13-15: Good test coverage for the new feature

This test properly verifies that the Alert component's text is centered as a result of the center: true design configuration property. The test confirms that the CSS text-align property is correctly set to center.

The comment "验证文字居中" (verifying text centering) clearly documents the purpose of this test case.

examples/sites/demos/pc/app/config-provider/base.vue (1)

63-66: Nice addition – validates the new design-config capability

Adding center: true under Alert.props showcases the arbitrary-attribute feature nicely and should read well in demos.

Once the Vue 2 adapters forward customDesignProps (see previous comment) this demo will work across all targets.

packages/vue-common/src/adapter/vue3/index.ts (1)

25-39: Ordering & duplication guard in the merged‐prop spread

  1. ...attrs is placed before ...customDesignProps.
    Because Vue normalises incoming attrs into props when names match, a user could still override a design default via an attribute instead of a prop, so this order is correct – keep it. 👍

  2. However, props and customDesignProps are independent spreads and may contain the same key; the later spread (customDesignProps) will win.
    That contradicts the rule implemented in $setup (“only override when the user did not set the prop”).
    Consider merging before calling h to ensure the carefully-filtered object is passed only once:

-      { ref: 'modeTemplate', ...props, ...attrs, ...customDesignProps, ...extend },
+      {
+        ref: 'modeTemplate',
+        ...attrs,
+        ...customDesignProps,
+        ...props,          // user props last -> guaranteed priority
+        ...extend
+      },

Double-check with a simple unit test that a runtime prop (<tiny-alert center="false" />) still overrides the design default.

🧰 Tools
🪛 Biome (1.9.4)

[error] 35-35: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Comment on lines +41 to +44
export const getCustomProps = () => {
const instance = hooks.getCurrentInstance()?.proxy
return instance?.$options?.propsData || {}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

getCustomProps added, but the surrounding adapter is still oblivious to the new customDesignProps flow

getCustomProps itself looks fine, yet the Vue 2.7 adapter never forwards the merged customDesignProps object that $setup now passes in.
As a result, any default props coming from the global design-config are silently ignored in a Vue 2.7 runtime, breaking the very feature this PR introduces (e.g. the new Alert.center default will not work).

Minimal patch (works for both Vue 2 and Vue 2.7 adapters):

 export const renderComponent = ({
   view = null as any,
   component = null as any,
   props,
+  customDesignProps = {},
   context: { attrs, listeners: on, slots },
   extend = {}
 }) => {
   return () =>
     hooks.h(
       (view && view.value) || component,
-      Object.assign({ props, attrs, [extend.isSvg ? 'nativeOn' : 'on']: on, scopedSlots: { ...slots } }, extend)
+      Object.assign(
+        { props: { ...customDesignProps, ...props }, attrs, [extend.isSvg ? 'nativeOn' : 'on']: on, scopedSlots: { ...slots } },
+        extend
+      )
     )
 }

Key points

  1. Keep the existing ordering so user props still win over design defaults.
  2. Provide a default {} to stay backwards-compatible with callers that do not yet supply the parameter.

Please mirror the same change in packages/vue-common/src/adapter/vue2/index.ts to keep all Vue-2 builds consistent.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const getCustomProps = () => {
const instance = hooks.getCurrentInstance()?.proxy
return instance?.$options?.propsData || {}
}
export const renderComponent = ({
view = null as any,
component = null as any,
props,
customDesignProps = {},
context: { attrs, listeners: on, slots },
extend = {}
}) => {
return () =>
hooks.h(
(view && view.value) || component,
Object.assign(
{ props: { ...customDesignProps, ...props }, attrs, [extend.isSvg ? 'nativeOn' : 'on']: on, scopedSlots: { ...slots } },
extend
)
)
}

Comment on lines +47 to +50
export const getCustomProps = () => {
const instance = hooks.getCurrentInstance()
return instance?.vnode?.props || {}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Prefer instance.props to capture camel-cased prop keys

instance.vnode.props gives you the raw vnode props which may preserve kebab-cased keys and include attrs/events.
instance.props exposes the normalised reactive props object, mapping kebab-case to camelCase – a closer match to the keys declared in designConfig.props.

-export const getCustomProps = () => {
-  const instance = hooks.getCurrentInstance()
-  return instance?.vnode?.props || {}
-}
+export const getCustomProps = () => {
+  const instance = hooks.getCurrentInstance()
+  return instance?.props || {}
+}

This avoids false negatives when a user passes center="false" (kebab) but the design config checks for center (camel).

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const getCustomProps = () => {
const instance = hooks.getCurrentInstance()
return instance?.vnode?.props || {}
}
export const getCustomProps = () => {
const instance = hooks.getCurrentInstance()
return instance?.props || {}
}

Copy link

@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

♻️ Duplicate comments (1)
packages/vue-common/src/adapter/vue2.7/index.ts (1)

36-39: ⚠️ Potential issue

customDesignProps is passed incorrectly to the component

The current implementation adds customDesignProps as a separate property in the object passed to the Vue component, but it needs to be merged with the props object to actually apply the design configuration properties to the component.

Apply this fix to properly merge design props with user props:

 Object.assign(
-  { props, attrs, customDesignProps, [extend.isSvg ? 'nativeOn' : 'on']: on, scopedSlots: { ...slots } },
+  { props: { ...customDesignProps, ...props }, attrs, [extend.isSvg ? 'nativeOn' : 'on']: on, scopedSlots: { ...slots } },
   extend
 )

This ensures that:

  1. Design configuration properties are applied to the component
  2. User props take precedence over design defaults (as they should)
  3. The implementation is consistent with the expected behavior
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 92c2625 and 22aeaf0.

📒 Files selected for processing (2)
  • packages/vue-common/src/adapter/vue2.7/index.ts (1 hunks)
  • packages/vue-common/src/adapter/vue2/index.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/vue-common/src/adapter/vue2/index.ts (3)
packages/vue-common/src/index.ts (1)
  • hooks (412-412)
packages/vue-common/src/adapter/vue2.7/index.ts (2)
  • rootConfig (43-43)
  • getCustomProps (45-48)
packages/vue-common/src/adapter/vue3/index.ts (2)
  • rootConfig (41-45)
  • getCustomProps (47-50)
🪛 Biome (1.9.4)
packages/vue-common/src/adapter/vue2.7/index.ts

[error] 35-35: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

packages/vue-common/src/adapter/vue2/index.ts

[error] 44-46: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: PR E2E Test (pnpm test:e2e3)
🔇 Additional comments (4)
packages/vue-common/src/adapter/vue2/index.ts (2)

37-37: Added new parameter customDesignProps for design configuration support

The parameter has been added to support arbitrary attributes from design configuration, which aligns with the PR objectives.


60-63: getCustomProps implementation looks good

The function correctly retrieves the current component instance's props data, which will be used for merging with design configuration.

packages/vue-common/src/adapter/vue2.7/index.ts (2)

29-29: Added new parameter customDesignProps for design configuration support

The parameter has been added to support arbitrary attributes from design configuration, which aligns with the PR objectives.


45-48: getCustomProps implementation looks good

The function correctly retrieves the current component instance's props data, which will be used for merging with design configuration.

Comment on lines 45 to 52
{
props,
attrs,
customDesignProps,
[extend.isSvg ? 'nativeOn' : 'on']: on,
ref: 'modeTemplate',
scopedSlots: { ...slots }
},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

customDesignProps is passed incorrectly to the component

The current implementation adds customDesignProps as a separate property in the object passed to the Vue component, but it needs to be merged with the props object to actually apply the design configuration properties to the component.

Apply this fix to properly merge design props with user props:

 Object.assign(
   {
-    props,
+    props: { ...customDesignProps, ...props },
     attrs,
-    customDesignProps,
     [extend.isSvg ? 'nativeOn' : 'on']: on,
     ref: 'modeTemplate',
     scopedSlots: { ...slots }
   },
   extend
 )

This ensures that:

  1. Design configuration properties are applied to the component
  2. User props take precedence over design defaults (as they should)
  3. The implementation is consistent with the expected behavior
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{
props,
attrs,
customDesignProps,
[extend.isSvg ? 'nativeOn' : 'on']: on,
ref: 'modeTemplate',
scopedSlots: { ...slots }
},
{
props: { ...customDesignProps, ...props },
attrs,
[extend.isSvg ? 'nativeOn' : 'on']: on,
ref: 'modeTemplate',
scopedSlots: { ...slots }
},

@zzcr zzcr mentioned this pull request May 13, 2025
13 tasks
@kagol kagol merged commit 7fc60b1 into dev May 14, 2025
9 of 10 checks passed
@kagol kagol deleted the add-global-props-config-0513 branch May 14, 2025 02:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request (功能增强)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants