Skip to content

feat: customWrapper 支持 class 和 style 属性#19432

Open
panyu97py wants to merge 1 commit into
NervJS:mainfrom
panyu97py:featCustomWrapperSupportClassStyle
Open

feat: customWrapper 支持 class 和 style 属性#19432
panyu97py wants to merge 1 commit into
NervJS:mainfrom
panyu97py:featCustomWrapperSupportClassStyle

Conversation

@panyu97py

@panyu97py panyu97py commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

这个 PR 做了什么? (简要描述所做更改)

这个 PR 是什么类型? (至少选择一个)

  • 错误修复 (Bugfix) issue: fix #
  • 新功能 (Feature)
  • 代码重构 (Refactor)
  • TypeScript 类型定义修改 (Types)
  • 文档修改 (Docs)
  • 代码风格更新 (Code style update)
  • 构建优化 (Chore)
  • 其他,请描述 (Other, please describe):

这个 PR 涉及以下平台:

  • 所有平台
  • Web 端(H5)
  • 移动端(React-Native)
  • 鸿蒙(Harmony)
  • 鸿蒙容器(Harmony Hybrid)
  • ASCF 元服务
  • 快应用(QuickApp)
  • 所有小程序
  • 微信小程序
  • 企业微信小程序
  • 京东小程序
  • 百度小程序
  • 支付宝小程序
  • 支付宝 IOT 小程序
  • 钉钉小程序
  • QQ 小程序
  • 飞书小程序
  • 快手小程序
  • 头条小程序

Summary by CodeRabbit

  • 新功能
    • 第三方组件模板现在支持传递自定义 CSS 类名和内联样式,提升组件样式定制能力。

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

自定义包装器生成的第三方组件标签新增 classstyle 绑定,并保留原有的 liddata-sid 输出逻辑。

Changes

第三方模板更新

Layer / File(s) Summary
自定义包装器属性绑定
packages/shared/src/template.ts
custom-wrapper 分支为组件标签新增 class="{{i.cl}}"style="{{i.st}}" 绑定,同时保留现有属性拼装逻辑。

Estimated code review effort: 1 (Trivial) | ~5 minutes

Poem

我是小兔蹦蹦跳,
模板添上样式帽。
class、style 一起跑,
原有属性不丢掉。
代码整洁,胡萝卜香!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了此次为 customWrapper 新增 class 和 style 属性支持的主要变更。
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@panyu97py

Copy link
Copy Markdown
Contributor Author

#19242 修复解决了这个问题

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/shared/src/template.ts (1)

480-480: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

建议统一使用 Shortcuts.Class / Shortcuts.Style 这里直接写 i.cl / i.st,和 buildThirdPartyAttr 的生成方式不一致,后续映射变更时容易漏改。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/shared/src/template.ts` at line 480, Update the component template
generation in the relevant template-building function to use the shared
Shortcuts.Class and Shortcuts.Style mappings instead of directly referencing
i.cl and i.st, matching buildThirdPartyAttr and keeping attribute mappings
consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/shared/src/template.ts`:
- Line 480: Update the component template generation in the relevant
template-building function to use the shared Shortcuts.Class and Shortcuts.Style
mappings instead of directly referencing i.cl and i.st, matching
buildThirdPartyAttr and keeping attribute mappings consistent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 45a10ffd-34ab-4d5c-a5d0-6306da332ad4

📥 Commits

Reviewing files that changed from the base of the PR and between 0db37ec and cb19f88.

📒 Files selected for processing (1)
  • packages/shared/src/template.ts

@panyu97py

Copy link
Copy Markdown
Contributor Author

背景

微信小程序原生自定义组件支持在宿主节点上直接设置 class、style、动画以及 Flex 布局等属性,开发者可以像使用普通 view 一样进行布局,无需额外增加包装节点。

相比之下,当前 CustomWrapper 不支持 class、style 属性,与微信原生自定义组件的行为存在差异,无法作为一个普通的布局节点使用。

存在的问题

由于无法给 CustomWrapper 宿主节点设置布局样式,会带来一些实际使用上的限制:

  • 无法使用 flex: 1、width: 100%、height: 100% 等依赖宿主节点参与布局计算的样式。
  • ScrollView 等依赖父容器尺寸的场景容易出现高度异常、无法滚动等问题。
  • 业务侧只能通过增加额外包裹节点、手动计算高度等方式进行适配,不仅增加了页面层级,也提高了维护成本。

方案

为 CustomWrapper 增加 class、style 属性支持,并透传到实际渲染节点,使其能够像微信原生自定义组件一样参与页面布局计算。

@panyu97py

Copy link
Copy Markdown
Contributor Author

@Single-Dancer 帮忙 Review 一下?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant