Skip to content

Conversation

clayzx
Copy link
Contributor

@clayzx clayzx commented Sep 4, 2025

🤔 这个变动的性质是?

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

🔗 相关 Issue

💡 需求背景和解决方案

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

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

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • fork仓库代码是否为最新避免文件冲突
  • Files changed 没有 package.json lock 等无关文件

Summary by CodeRabbit

  • Bug Fixes
    • 级联选择:修复懒加载过程中父节点未就绪导致的报错与选项渲染异常,提升稳定性与加载可靠性。
    • 弹窗:修复点击关闭图标会冒泡触发上层点击事件的问题,避免误触导致的意外关闭或重复回调,使交互更一致。

Copy link

coderabbitai bot commented Sep 4, 2025

Walkthrough

对 Cascader 懒加载链式归并中对子节点赋值增加了父节点空值保护;对 Popup 的关闭图标点击事件添加了 stopPropagation,避免冒泡影响其他点击逻辑。对外导出未变更。

Changes

Cohort / File(s) Summary
Cascader 懒加载空值保护
src/packages/cascader/cascader.taro.tsx
在 reduce 流程中为 parent.children = pane 增加判空:改为 if (parent) parent.children = pane,避免 parent 未定义时报错;其余逻辑保持不变。
Popup 关闭图标点击处理
src/packages/popup/popup.taro.tsx
handleCloseIconClick 中加入 e.stopPropagation(),防止点击关闭图标触发外层(如遮罩)点击处理;后续仍执行 onCloseIconClick(e) && close()

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as 用户
  participant CI as CloseIcon(关闭图标)
  participant PH as Popup(容器/遮罩)
  participant H as 处理器

  U->>CI: click
  note right of CI: 新增:stopPropagation()
  CI->>H: onCloseIconClick(e)
  alt 返回真
    H->>PH: close()
  else 返回假
    H-->>U: 不关闭
  end

  U->>PH: click(遮罩)
  PH->>PH: overlay onClick
  PH->>PH: close()
Loading
sequenceDiagram
  autonumber
  participant C as Cascader
  participant R as reduce(懒加载链)
  participant P as parent(可能为undefined)
  participant N as pane(子节点)

  C->>R: 迭代构建层级
  R->>P: 取得当前父节点
  alt P 存在
    R->>P: P.children = N
  else P 不存在
    note right of R: 新增空值保护:跳过赋值
  end
  R-->>C: 返回最终 options
  C->>C: setInnerOptions(...)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • refactor: popup 优化代码 #2944 — 同触达点:修改 src/packages/popup/popup.taro.tsx 的关闭图标点击处理(该 PR对处理器进行重命名与简化),与本次添加 stopPropagation() 的变更紧密相关。

Suggested reviewers

  • oasis-cloud
  • irisSong
  • xiaoyatong

Poem

小兔拍耳听风声,
级级懒载护父根。
关窗一按不外传,
泡泡静落夜色深。
代码轻拢无惊雷,
行间稳当赴清晨。

✨ 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.
    • 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.
  • 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 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/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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 action:review This PR needs more reviews (less than 2 approvals) 3.x Target branch 3.x labels Sep 4, 2025
Copy link

codecov bot commented Sep 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.15%. Comparing base (52d84bd) to head (7ddeab9).

Additional details and impacted files
@@            Coverage Diff             @@
##           feat_v3.x    #3354   +/-   ##
==========================================
  Coverage      88.15%   88.15%           
==========================================
  Files            291      291           
  Lines          19212    19212           
  Branches        2988     2988           
==========================================
  Hits           16937    16937           
  Misses          2269     2269           
  Partials           6        6           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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: 0

🧹 Nitpick comments (3)
src/packages/popup/popup.taro.tsx (1)

171-174: 放宽关闭条件判定,避免“未显式返回值不关闭”

当前写法要求 onCloseIconClick 显式返回 truthy 才会关闭;若用户回调未返回值(undefined),将导致不关闭,和直觉不符。建议改为“非 false 即关闭”,并使用可选链以防御空回调。

可按以下方式调整:

 const handleCloseIconClick = (e: ITouchEvent) => {
   e.stopPropagation()
-  onCloseIconClick(e) && close()
+  if (onCloseIconClick?.(e) !== false) close()
 }
src/packages/cascader/cascader.taro.tsx (2)

165-176: 避免同名变量“parent”遮蔽,提升可读性与可维护性

回调内部的 const parent = await promise 会遮蔽外层 parent,阅读和调试都容易混淆。建议重命名为 node 并相应替换,保持语义清晰。

-        await innerValue.reduce(async (promise: Promise<any>, val, key) => {
-          const pane = await onLoad({ value: val }, key)
-          const parent = await promise
-          if (parent) parent.children = pane
-          if (key === innerValue.length - 1) {
-            return Promise.resolve(parent)
-          }
-          if (pane) {
-            const node = pane.find((p) => p.value === val)
-            return Promise.resolve(node)
-          }
-        }, Promise.resolve(parent))
+        await innerValue.reduce(async (promise: Promise<any>, val, key) => {
+          const pane = await onLoad({ value: val }, key)
+          const node = await promise
+          if (node) node.children = pane
+          if (key === innerValue.length - 1) {
+            return Promise.resolve(node)
+          }
+          if (pane) {
+            const next = pane.find((p) => p.value === val)
+            return Promise.resolve(next)
+          }
+        }, Promise.resolve(parent))

185-186: 避免陈旧闭包与竞态:完善依赖并添加“活性”守卫

useEffect 只依赖 lazy,但内部使用了 innerValueonLoad;当外部受控值或加载函数变化时不会重新拉取,且并发加载可能造成越界更新。建议将依赖改为 [lazy, innerValue, onLoad],并用 active 标记防止卸载后的 setInnerOptions

-  useEffect(() => {
-    const load = async () => {
+  useEffect(() => {
+    let active = true
+    const load = async () => {
       const parent = { children: [] }
       try {
         await innerValue.reduce(async (promise: Promise<any>, val, key) => {
           const pane = await onLoad({ value: val }, key)
           const parent = await promise
           if (parent) parent.children = pane
           if (key === innerValue.length - 1) {
             return Promise.resolve(parent)
           }
           if (pane) {
             const node = pane.find((p) => p.value === val)
             return Promise.resolve(node)
           }
         }, Promise.resolve(parent))
 
-        // 如果需要处理最终结果,可以在这里使用 last
-        setInnerOptions(parent.children)
+        if (active) setInnerOptions(parent.children)
       } catch (error) {
         console.error('Error loading data:', error)
       }
     }
 
-    if (lazy) load()
-  }, [lazy])
+    if (lazy) load()
+    return () => {
+      active = false
+    }
+  }, [lazy, innerValue, onLoad])
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 52d84bd and 7ddeab9.

📒 Files selected for processing (2)
  • src/packages/cascader/cascader.taro.tsx (1 hunks)
  • src/packages/popup/popup.taro.tsx (1 hunks)
⏰ 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). (2)
  • GitHub Check: build
  • GitHub Check: test
🔇 Additional comments (2)
src/packages/popup/popup.taro.tsx (1)

171-174: 阻止关闭图标点击冒泡修复“点穿”:通过

在关闭图标点击中添加 e.stopPropagation() 能有效避免冒泡触发 Overlay 的点击关闭逻辑,符合预期场景。LGTM。

src/packages/cascader/cascader.taro.tsx (1)

165-170: 对子节点赋值增加空值保护:通过

if (parent) parent.children = pane 能避免在上一轮返回 undefined 时的运行时异常,修复懒加载链路中层级不存在的报错问题。LGTM。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Target branch 3.x action:review This PR needs more reviews (less than 2 approvals) size/XS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant