Skip to content

Conversation

@ccs-song
Copy link
Contributor

@ccs-song ccs-song commented Aug 7, 2025

🤔 这个 PR 的性质是?(至少选择一个)

  • 日常 bug 修复
  • 新特性提交
  • 站点、文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • TypeScript 定义更新
  • CI/CD 改进
  • 包体积优化
  • 性能优化
  • 功能增强
  • 国际化改进
  • 代码重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他改动(是关于什么的改动?)

🔗 相关 Issue

#1191

💡 需求背景和解决方案

1、修复children为函数时,wd-tabs渲染错误
2、publicChildren.sort排序由 引用 改为 uid

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充

Summary by CodeRabbit

  • 新功能

    • 增加了对标签页(Tabs)数据变化时,标签导航项顺序正确性的测试用例。
    • 新增了组件节点扁平化功能的测试,确保多层级嵌套节点的正确处理。
  • 修复

    • 优化了嵌套组件树的节点扁平化和子组件排序逻辑,提升了多层级组件结构下的准确性和健壮性。

@vercel
Copy link

vercel bot commented Aug 7, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
wot-design-uni ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 7, 2025 6:55am

@netlify
Copy link

netlify bot commented Aug 7, 2025

Deploy Preview for wot-design-uni ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 017058e
🔍 Latest deploy log https://app.netlify.com/projects/wot-design-uni/deploys/68944d9130b4550008d73adc
😎 Deploy Preview https://deploy-preview-1211--wot-design-uni.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link

coderabbitai bot commented Aug 7, 2025

Walkthrough

本次变更主要对 useChildren.ts 中的 flattenVNodessortChildren 函数进行了类型和遍历逻辑的增强,以更精确地处理嵌套的 VNode 结构和通过唯一组件 ID 排序子组件。同时,新增了测试用例验证 tab 导航项顺序的正确性,并新增了 flattenVNodes 的单元测试覆盖多种场景。

Changes

Cohort / File(s) Change Summary
VNode 扁平化与排序逻辑优化
src/uni_modules/wot-design-uni/components/composables/useChildren.ts
扩展 flattenVNodes 参数类型,完善递归遍历逻辑,支持更深层次的 VNode 结构,并通过唯一 ID 排序子组件。
Tabs 组件顺序测试
tests/components/wd-tabs.test.ts
新增测试用例,验证 tab 数据变化后导航项的渲染顺序是否正确。
flattenVNodes 单元测试
tests/composables/useChildren.test.ts
新增针对 flattenVNodes 函数的测试,覆盖多种 VNode 结构及组件子树情况,验证扁平化逻辑正确性。

Sequence Diagram(s)

sequenceDiagram
    participant ParentComponent
    participant useChildren
    participant flattenVNodes
    participant sortChildren

    ParentComponent->>useChildren: 调用 sortChildren(parent)
    useChildren->>sortChildren: 传递 parent.subTree
    sortChildren->>flattenVNodes: 递归扁平化 VNode 结构
    flattenVNodes-->>sortChildren: 返回扁平 VNode 列表
    sortChildren->>useChildren: 通过唯一 ID 排序 publicChildren
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Possibly related issues

Poem

小兔跳跃在代码林,
VNode 深处细细寻。
唯一 ID 排队行,
Tabs 顺序不再乱。
测试一过心欢畅,
代码世界更安宁! 🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 b1ddb9e and 017058e.

📒 Files selected for processing (2)
  • src/uni_modules/wot-design-uni/components/composables/useChildren.ts (2 hunks)
  • tests/composables/useChildren.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/uni_modules/wot-design-uni/components/composables/useChildren.ts
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: Moonofweisheng
PR: Moonofweisheng/wot-design-uni#733
File: src/uni_modules/wot-design-uni/components/wd-tabs/wd-tabs.vue:327-327
Timestamp: 2024-11-24T06:12:44.418Z
Learning: 在 `src/uni_modules/wot-design-uni/components/wd-tabs/wd-tabs.vue` 中,由于 `title` 可能会发生变化,涉及到 `title` 的优化不太容易实现,需谨慎处理。
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: Test Components (wd-gap)
  • GitHub Check: Test Components (wd-segmented)
  • GitHub Check: Test Components (wd-index-bar)
  • GitHub Check: Test Components (wd-checkbox)
  • GitHub Check: Test Components (wd-message-box)
  • GitHub Check: Test Components (wd-select-picker)
  • GitHub Check: Test Components (wd-circle)
  • GitHub Check: Test Components (wd-tabbar)
  • GitHub Check: Test Components (wd-img)
  • GitHub Check: Test Components (wd-password-input)
  • GitHub Check: Test Components (wd-notice-bar)
  • GitHub Check: Test Components (wd-img-cropper)
  • GitHub Check: Test Components (wd-status-tip)
  • GitHub Check: Test Components (wd-icon)
  • GitHub Check: Test Components (wd-grid)
  • GitHub Check: Test Components (wd-grid-item)
  • GitHub Check: Test Components (wd-badge)
  • GitHub Check: Test Components (wd-floating-panel)
  • GitHub Check: Test Components (wd-tag)
  • GitHub Check: Test Components (wd-watermark)
🔇 Additional comments (6)
tests/composables/useChildren.test.ts (6)

1-3: 导入语句正确且必要

导入语句清晰明确,包含了测试所需的所有依赖:被测试的函数、测试框架和 Vue 相关工具。


5-10: 辅助函数设计良好

createVNodeWithSubTree 函数很好地模拟了组件的 subTree 行为,使用 @ts-expect-error 合理地处理了测试中的类型问题。这种设计使得测试能够准确验证 flattenVNodes 函数对组件子树的处理能力。


12-12: 测试套件结构完善

测试套件使用了清晰的描述性命名,为 flattenVNodes 函数提供了全面的测试覆盖。


13-19: 边界条件测试完整

正确测试了非 VNode 输入的边界情况,包括 null 和空数组,验证函数能够安全处理无效输入并返回空数组。使用类型断言来测试边界情况是合适的做法。


21-47: VNode 扁平化测试覆盖全面

这些测试用例很好地覆盖了 VNode 扁平化的核心功能:

  • 单层 VNode 的处理
  • 多个同级 VNode 的扁平化
  • 嵌套 VNode 的递归扁平化

测试逻辑正确,能够有效验证函数的预期行为,包括顺序保持和深层嵌套结构的正确处理。


49-66: 组件子树处理测试设计优秀

这两个测试用例针对 PR 的核心功能进行了精确验证:

  • 嵌套场景下的 component.subTree 遍历
  • 顶层 VNode 的 component.subTree 处理

测试正确验证了函数能够识别并遍历组件子树,这直接对应了 PR 中提到的增强遍历逻辑。期望值包含了组件 VNode 本身和其子树内容,符合扁平化的预期行为。

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Support

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

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 generate unit tests to generate unit tests for 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.

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2bb28f3 and b1ddb9e.

📒 Files selected for processing (2)
  • src/uni_modules/wot-design-uni/components/composables/useChildren.ts (2 hunks)
  • tests/components/wd-tabs.test.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: Moonofweisheng
PR: Moonofweisheng/wot-design-uni#733
File: src/uni_modules/wot-design-uni/components/wd-tabs/wd-tabs.vue:327-327
Timestamp: 2024-11-24T06:12:44.418Z
Learning: 在 `src/uni_modules/wot-design-uni/components/wd-tabs/wd-tabs.vue` 中,由于 `title` 可能会发生变化,涉及到 `title` 的优化不太容易实现,需谨慎处理。
📚 Learning: 在 `src/uni_modules/wot-design-uni/components/wd-tabs/wd-tabs.vue` 中,由于 `title` 可能会发生变化,涉及到 `title` 的...
Learnt from: Moonofweisheng
PR: Moonofweisheng/wot-design-uni#733
File: src/uni_modules/wot-design-uni/components/wd-tabs/wd-tabs.vue:327-327
Timestamp: 2024-11-24T06:12:44.418Z
Learning: 在 `src/uni_modules/wot-design-uni/components/wd-tabs/wd-tabs.vue` 中,由于 `title` 可能会发生变化,涉及到 `title` 的优化不太容易实现,需谨慎处理。

Applied to files:

  • tests/components/wd-tabs.test.ts
📚 Learning: 在文件 `wd-message-box.vue` 的 `togglemodal` 方法中,当 `ispass` 为 `false` 时,应阻止执行 `confirm`,但不触发 `cancel` 操作...
Learnt from: Moonofweisheng
PR: Moonofweisheng/wot-design-uni#761
File: src/uni_modules/wot-design-uni/components/wd-message-box/wd-message-box.vue:166-182
Timestamp: 2024-12-05T15:55:35.371Z
Learning: 在文件 `wd-message-box.vue` 的 `toggleModal` 方法中,当 `isPass` 为 `false` 时,应阻止执行 `confirm`,但不触发 `cancel` 操作。

Applied to files:

  • tests/components/wd-tabs.test.ts
📚 Learning: 在 `src/uni_modules/wot-design-uni/components/wd-progress/wd-progress.vue` 文件中,当 `percentage` 为 0 时,应...
Learnt from: Moonofweisheng
PR: Moonofweisheng/wot-design-uni#748
File: src/uni_modules/wot-design-uni/components/wd-progress/wd-progress.vue:87-128
Timestamp: 2024-11-30T06:44:18.181Z
Learning: 在 `src/uni_modules/wot-design-uni/components/wd-progress/wd-progress.vue` 文件中,当 `percentage` 为 0 时,应通过 `update` 函数处理 `percentage` 为 0 的情况,而不需要在 `updateProgress` 函数中进行特殊处理。

Applied to files:

  • tests/components/wd-tabs.test.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Generate Test Summary
🔇 Additional comments (2)
src/uni_modules/wot-design-uni/components/composables/useChildren.ts (1)

66-75: 排序逻辑改进合理

使用组件的唯一标识符 uid 进行排序比直接使用引用更加可靠,特别是在处理动态组件和函数式子组件时。这个改进能有效解决原有的排序问题。

tests/components/wd-tabs.test.ts (1)

431-467: 测试用例实现合理

新增的测试用例很好地验证了当 tab 数据动态变化时,导航项的顺序是否正确。测试覆盖了从单个 tab 到多个 tab 的动态更新场景,并正确验证了每个导航项的文本内容和顺序。

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