Skip to content

Conversation

@EmilyyyLiu
Copy link
Contributor

@EmilyyyLiu EmilyyyLiu commented Sep 10, 2025

依赖rc-util修改为 @rc-component/util
替换 useMergedState 为 useControlledState

Summary by CodeRabbit

  • 重构
    • 核心实现与状态管理迁移到新通用工具库,内部实现调整但对外行为与 API 保持一致。
  • 杂务
    • 包与构建配置重命名与重构,更新依赖与构建脚本以统一命名空间与工具链。
  • 测试
    • 测试引用同步更新以配合依赖迁移,测试逻辑与断言保持不变。
  • 文档
    • 示例与 README 中的引用已更新,确保示例和演示可正常运行。

@vercel
Copy link

vercel bot commented Sep 10, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
slider Error Error Sep 11, 2025 2:01am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 10, 2025

Caution

Review failed

The head commit changed during the review from c9e2ef3 to 873a4ee.

Walkthrough

此次变更将包名与内部导入从 rc-* 迁移到 @rc-component/*,更新 package.json、构建/别名配置、源码、示例和测试的导入路径;在 src/Slider.tsx 中把原先的 useMergedState 替换为新 useControlledState(defaultValue, value),其余运行逻辑未改动。

Changes

Cohort / File(s) Summary
Package / config
package.json, tsconfig.json, .dumirc.ts
包名由 rc-slider@rc-component/slider,替换依赖 rc-util@rc-component/util,更新 devDeps(移除 np/rc-tooltip/rc-trigger,新增 @rc-component/np/tooltip/trigger 等);tsconfig/alias 映射相应改为 @rc-component/slider 指向 src
核心源码导入迁移
src/Handles/Handle.tsx, src/Slider.tsx, src/hooks/* (useDrag.ts, useRange.ts)
将 KeyCode、useEvent、useLayoutEffect、warning、raf、isEqual 等工具的导入源由 rc-util/... 改为 @rc-component/util/...src/Slider.tsx 同时将状态钩子由 useMergedState<...> 改为 useControlledState(defaultValue, value)(调用签名已变更),其余行为保持。
示例与文档
docs/examples/*, docs/examples/components/TooltipSlider.tsx, README.md
将示例与文档中的 rc-slider、相关 CSS 与 tooltip/trigger 的导入更新为 @rc-component/slider / @rc-component/tooltip,示例代码不改逻辑。
测试与 mocks
tests/*, tests/__mocks__/rc-trigger.js
测试内对 KeyCode、spyElementPrototypes、resetWarned、domHook 的导入路径由 rc-util/... 切换为 @rc-component/util/...;Trigger mock 改为从 @rc-component/trigger/lib/mock 引入。测试逻辑未变。
示例组件
docs/examples/*/*.tsx
各示例文件统一将 rc-slider 导入替换为 @rc-component/slider,无逻辑改动。

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as 用户
  participant S as Slider 组件
  participant CS as useControlledState
  participant H as Hooks/Helpers
  participant P as 上层回调 (onChange/onAfterChange)

  U->>S: 交互 (拖动/键盘/点击)
  S->>CS: 读取/派生 mergedValue (defaultValue, value)
  S->>H: 计算 rawValues、格式化、约束
  H-->>S: 返回下一个 value(s)
  S->>P: 触发 onChange(nextValue) (via useEvent)
  alt 交互结束
    S->>P: 触发 onAfterChange(nextValue)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Pre-merge checks (3 passed)

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed 标题 "chore: migrate to @rc-component namespace and update dependencies" 简洁且直接反映了 PR 的主要改动:将包名与导入迁移到 @rc-component 命名空间并更新相关依赖(例如 rc-util → @rc-component/util),这与 raw_summary 和 pr_objectives 中的描述一致。标题虽未显式提到将 useMergedState 替换为 useControlledState 等实现细节,但标题不需要覆盖所有变更,能让同事快速把握主要目的。
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

Poem

小兔跳过旧路径,🐇
导入换上新衣裳;
控制钩子换了签名,
值流仍按旧节奏唱。
测试微笑点个头,✨
发布路上再鼓掌。

✨ Finishing Touches
🧪 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

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

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @EmilyyyLiu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the project's utility dependencies by migrating from rc-util to the more modern @rc-component/util package. This change involves updating import paths and the package.json dependency. Additionally, the state management within the Slider component has been improved by adopting the useControlledState hook, aligning with contemporary React practices for controlled components.

Highlights

  • Dependency Upgrade: The project's utility dependency rc-util has been upgraded and replaced with @rc-component/util across all relevant files and in package.json.
  • State Management Hook Replacement: The useMergedState hook in src/Slider.tsx has been replaced with useControlledState from the new utility package, streamlining state management for the Slider component.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

本次 Pull Request 将 rc-util 依赖升级为 @rc-component/util,并使用 useControlledState 替换了 useMergedState hook。这是一次清晰的重构,解决了 useMergedState 的一个已知问题,同时使状态管理逻辑更简洁。相关修改在整个代码库中(包括源文件、示例和测试)都得到了一致的应用。整体来看,这是一次高质量的重构,提升了代码的健壮性和可维护性。

@socket-security
Copy link

socket-security bot commented Sep 10, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​rc-component/​np@​1.0.4701006684100
Updated@​rc-component/​father-plugin@​1.1.0 ⏵ 2.1.382 +310077 +187100
Added@​rc-component/​tooltip@​1.2.18110010089100
Added@​rc-component/​util@​1.3.09910010091100
Added@​rc-component/​trigger@​3.5.29910010092100

View full report

Copy link
Contributor

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/Slider.tsx (2)

362-385: range 可编辑插入位置的边界错误(应在数组开头插入时却插到索引 1)

valueBeforeIndex 初始为 0 会导致当 newValue 小于现有所有值时插入索引错误(应为 0,现为 1)。将其初值改为 -1 更稳妥。

-      let valueBeforeIndex = 0; // Record the index which value < newValue
+      let valueBeforeIndex = -1; // Record the index which value < newValue
...
-      if (rangeEditable && valueDist !== 0 && (!maxCount || rawValues.length < maxCount)) {
+      if (rangeEditable && valueDist !== 0 && (!maxCount || rawValues.length < maxCount)) {
         cloneNextValues.splice(valueBeforeIndex + 1, 0, newValue);
         focusIndex = valueBeforeIndex + 1;
       } else {
         cloneNextValues[valueIndex] = newValue;
       }

443-446: useState 类型不匹配(TS)

useState<number>(null) 在严格模式下会报错,需允许 null

-  const [keyboardValue, setKeyboardValue] = React.useState<number>(null);
+  const [keyboardValue, setKeyboardValue] = React.useState<number | null>(null);
🧹 Nitpick comments (5)
docs/examples/components/TooltipSlider.tsx (1)

6-6: raf 导入迁移正确;建议为 cancel 增加空值保护并复位 ID

当前 cancelKeepAlign 里直接对可能为 nullrafRef.current 做取消,运行时会把 null 传给 raf.cancel。为稳妥起见加一道判空并将 ref 复位,避免后续误用。

可参考(非范围内变更示例):

function cancelKeepAlign() {
  if (rafRef.current != null) {
    raf.cancel(rafRef.current);
    rafRef.current = null;
  }
}
tests/Slider.test.js (1)

4-5: 命名风格小一致性:建议统一使用 KeyCode

本文件用 keyCode(小驼峰),而其他文件多为 KeyCode(帕斯卡)。不影响功能,但建议统一,便于检索与维护。

可选(仅示意):

-import keyCode from '@rc-component/util/lib/KeyCode';
+import KeyCode from '@rc-component/util/lib/KeyCode';
src/Slider.tsx (3)

296-306: 内部状态建议存储为已排序数组,减少一次渲染差异

onChange 前已对 cloneNextValues 排序,但存入本地状态时未排序。为保证渲染前后一致性,可直接存排序结果。

-    // We set this later since it will re-render component immediately
-    setValue(cloneNextValues);
+    // We set this later since it will re-render component immediately
+    setValue(cloneNextValues.slice().sort((a, b) => a - b));

308-337: handlesRef 直接调用存在空指针风险,建议加可选链

handlesRef.current 在极端时间序(卸载/快速切换)下可能为空,添加可选链更稳妥。

-      handlesRef.current.hideHelp();
+      handlesRef.current?.hideHelp?.();
...
-    handlesRef.current.hideHelp();
-    handlesRef.current.focus(nextFocusIndex);
+    handlesRef.current?.hideHelp?.();
+    handlesRef.current?.focus?.(nextFocusIndex);

485-491: 拖拽结束后聚焦索引可能为 -1,应加保护

draggingValue 未在 rawValues 中找到时,valueIndex-1,直接 focus(-1) 不安全。

-  React.useEffect(() => {
-    if (!dragging) {
-      const valueIndex = rawValues.lastIndexOf(draggingValue);
-      handlesRef.current.focus(valueIndex);
-    }
-  }, [dragging]);
+  React.useEffect(() => {
+    if (!dragging) {
+      const valueIndex = rawValues.lastIndexOf(draggingValue);
+      if (valueIndex >= 0) {
+        handlesRef.current?.focus?.(valueIndex);
+      }
+    }
+  }, [dragging]);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 874875a and 84a60c6.

📒 Files selected for processing (10)
  • docs/examples/components/TooltipSlider.tsx (1 hunks)
  • package.json (1 hunks)
  • src/Handles/Handle.tsx (1 hunks)
  • src/Slider.tsx (2 hunks)
  • src/hooks/useDrag.ts (1 hunks)
  • src/hooks/useRange.ts (1 hunks)
  • tests/Range.test.tsx (1 hunks)
  • tests/Slider.test.js (1 hunks)
  • tests/common.test.js (1 hunks)
  • tests/marks.test.js (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/Slider.tsx (2)
docs/examples/editable.tsx (1)
  • value (12-69)
docs/examples/multiple.tsx (1)
  • value (19-49)
⏰ 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: Socket Security: Pull Request Alerts
🔇 Additional comments (9)
tests/common.test.js (1)

4-5: 导入路径迁移 LGTM

测试工具从 rc-util 切到 @rc-component/util 一致且无逻辑变动。

src/hooks/useRange.ts (1)

1-1: 统一 warning 的导入方式

发现 src/Slider.tsx 使用了默认导入:

import warning from '@rc-component/util/lib/warning';

src/hooks/useRange.ts 则用了命名导入:

import { warning } from '@rc-component/util/lib/warning';

请确认 @rc-component/util/lib/warning 的实际导出方式(default 或 named),并在全项目中统一导入,以避免运行时 warningundefined

src/hooks/useDrag.ts (1)

2-3: Hook 导入迁移 LGTM

useEventuseLayoutEffect 从 @rc-component/util 引入与预期一致,SSR 下该封装可避免警告。

tests/marks.test.js (1)

4-4: 导入路径迁移 LGTM

仅替换测试工具导入路径,无行为变化。

package.json (1)

46-46: 请手动确认 rc-util 迁移和 Node 版本兼容性

  • 全库重新扫描,确保无任何 rc-util 导入或残留依赖。
  • 核对 engines.node 配置,确认满足 @rc-component/util@^1.3.0 的最低 Node 要求。
src/Handles/Handle.tsx (1)

2-2: KeyCode 导入路径更新 LGTM

与全局迁移保持一致,键盘交互逻辑无需调整。

tests/Range.test.tsx (1)

4-6: 迁移到 @rc-component/util 的测试导入看起来正确

KeyCode、domHook、warning 重置的路径替换无误,测试语义未变更。

src/Slider.tsx (2)

253-254: useControlledState 使用方式合理,但请核对默认值语义

useControlledState(defaultValue, value) 将替代原 useMergedState。请确认在 valuedefaultValue 同为 undefined 时,初值仍按期望在 UI 上呈现为 min(当前通过后续逻辑回落到 mergedMin)。若需要与旧行为完全一致,可补充回归用例覆盖“未受控且未提供 defaultValue”的初始渲染。


1-4: 确认 isEqual 第三参数语义一致性
rc-util 到 @rc-component/util 迁移已完成,但请手动核对 isEqual(a, b, true) 中第三个布尔参数在新包中的含义与旧实现保持一致,以免影响 onChange 触发判断。

@EmilyyyLiu EmilyyyLiu changed the title refactor: Upgrade utils and replace useMergedState chore: migrate to @rc-component namespace and update dependencies Sep 11, 2025
Copy link
Contributor

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (4)
README.md (2)

1-1: README 标题仍是 rc-slider,需与包名同步为 @rc-component/slider

与 package.json 中的 "name": "@rc-component/slider" 不一致,易造成使用混淆。

-# rc-slider
+# @rc-component/slider

12-13: 将 README 中的徽章/链接从 rc-slider 更新为作用域包 @rc-component/slider(@ 在 URL 中需编码)

README 多处仍引用 rc-slider,请按下方 diff 更新并在合并前本地预览 README 渲染确认徽章能正常加载。位置:README.md 行 12-13;也适用于行 24-27、32。

-[npm-image]: http://img.shields.io/npm/v/rc-slider.svg?style=flat-square
-[npm-url]: http://npmjs.org/package/rc-slider
+[npm-image]: https://img.shields.io/npm/v/%40rc-component%2Fslider.svg?style=flat-square
+[npm-url]: https://npmjs.org/package/@rc-component/slider
-[download-image]: https://img.shields.io/npm/dm/rc-slider.svg?style=flat-square
-[download-url]: https://npmjs.org/package/rc-slider
-[bundlephobia-url]: https://bundlephobia.com/package/rc-slider
-[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/rc-slider
+[download-image]: https://img.shields.io/npm/dm/%40rc-component%2Fslider.svg?style=flat-square
+[download-url]: https://npmjs.org/package/@rc-component/slider
+[bundlephobia-url]: https://bundlephobia.com/package/@rc-component/slider
+[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/@rc-component/slider
-[![rc-slider](https://nodei.co/npm/rc-slider.png)](https://npmjs.org/package/rc-slider)
+[![@rc-component/slider](https://nodei.co/npm/@rc-component/slider.png)](https://npmjs.org/package/@rc-component/slider)
package.json (2)

31-31: 发布作用域包建议显式设置 publishConfig.access

缺少该配置时,npm publish 可能默认为私有或失败(视 registry 而定)。

   "files": [
     "assets/*.css",
     "lib",
     "es"
   ],
+  "publishConfig": {
+    "access": "public"
+  },

82-83: 将 package.json 的 engines.node 升级到 >=18.x

验证:npm view dumi/father/@rc-component/np engines 返回 { node: '>=18.x' },当前 ">=8.x" 与工具链不符。

文件:package.json 行 82-83

-  "engines": {
-    "node": ">=8.x"
-  }
+  "engines": {
+    "node": ">=18.x"
+  }
🧹 Nitpick comments (5)
docs/examples/editable.tsx (1)

2-2: 确认 UnstableContext 的公开导出;考虑避免示例依赖内部类型路径

  • 请确认 UnstableContext 在新包仍为公开导出(与旧包一致)。
  • 可选:将 UnstableContextProps 从包内对外导出,或在此处改为从包内导入类型,减少对 ../../src/context 的内部耦合。
docs/examples/multiple.tsx (2)

31-36: 示例为受控用法但未更新 state,滑块将无法交互

value 固定而 onChange 未调用 setValue,导致示例不可拖动。建议启用受控更新,或改为非受控(用 defaultValue 并移除 value)。

推荐受控修复:

-          value={value}
-          onChange={(nextValue) => {
-            // console.log('>>>', nextValue);
-            // setValue(nextValue as any);
-          }}
+          value={value}
+          onChange={(nextValue) => {
+            setValue(nextValue as number[]);
+          }}

或者改为非受控:

-          value={value}
+          defaultValue={value}
-          onChange={(nextValue) => {
-            // console.log('>>>', nextValue);
-            // setValue(nextValue as any);
-          }}
+          onChange={console.log}

11-13: 移除未使用的 log 函数或在 onChange 中使用

当前未被使用,保留会增加示例噪音。

-function log(value) {
-  console.log(value);
-}
+// 可在 onChange 中直接使用 console.log,移除此函数
README.md (1)

171-173: 版权段落中的包名亦需更新

与包名保持一致。

-`rc-slider` is released under the MIT license.
+`@rc-component/slider` is released under the MIT license.
package.json (1)

15-16: bugs 链接建议切换为 HTTPS

微调但更一致。

-  "bugs": {
-    "url": "https://github.com/react-component/slider/issues"
-  },
+  "bugs": {
+    "url": "https://github.com/react-component/slider/issues"
+  },
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 84a60c6 and 873a4ee.

📒 Files selected for processing (14)
  • .dumirc.ts (1 hunks)
  • README.md (3 hunks)
  • docs/examples/components/TooltipSlider.tsx (1 hunks)
  • docs/examples/debug.tsx (1 hunks)
  • docs/examples/editable.tsx (1 hunks)
  • docs/examples/handle.tsx (1 hunks)
  • docs/examples/marks.tsx (1 hunks)
  • docs/examples/multiple.tsx (1 hunks)
  • docs/examples/range.tsx (1 hunks)
  • docs/examples/slider.tsx (1 hunks)
  • docs/examples/vertical.tsx (1 hunks)
  • package.json (3 hunks)
  • tests/__mocks__/rc-trigger.js (1 hunks)
  • tsconfig.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/examples/components/TooltipSlider.tsx
🔇 Additional comments (10)
tsconfig.json (1)

13-13: 为 @rc-component/slider 增补 es/lib 子路径 alias(需本地或重新运行搜索确认)

当前 tsconfig 仅映射根入口;为避免示例/测试或历史导入解析失败,建议同时映射 es/lib 子路径。自动化搜索在 sandbox 中未能检索文件(ripgrep 跳过所有文件),无法确认仓库内是否存在相关导入。位置: tsconfig.json(paths)。

  "paths": {
    "@/*": ["src/*"],
    "@@/*": ["src/.umi/*"],
-    "@rc-component/slider": ["src/index.tsx"]
+    "@rc-component/slider": ["src/index.tsx"],
+    "@rc-component/slider/es/*": ["src/*"],
+    "@rc-component/slider/lib/*": ["src/*"]
  }

在仓库根运行下面更稳健的搜索脚本以验证(若仍返回 “No files were searched”,加上 --debug 调试 ripgrep 或用 git grep):

#!/bin/bash
# 在仓库根运行
rg -nP -uu --hidden --glob '!node_modules/**' "from ['\"]rc-slider" || true
rg -nP -uu --hidden --glob '!node_modules/**' "from ['\"]@rc-component/slider/(es|lib)" || true
rg -nP -uu --hidden --glob '!node_modules/**' "useMergedState|useControlledState" || true
# 备用:git grep(不受 .gitignore 限制)
git grep -n -e "from ['\"]rc-slider" -e "from ['\"]@rc-component/slider/(es|lib)" -e "useMergedState" -e "useControlledState" || true
docs/examples/debug.tsx (1)

1-1: 导入路径切换到 @rc-component/slider,LGTM

与别名迁移保持一致,无行为变化预期。

docs/examples/range.tsx (1)

2-2: 导入路径迁移正确,示例不涉及 API 变更

本文件仅为别名替换,行为应保持一致。

docs/examples/vertical.tsx (1)

1-1: 导入路径迁移正确

无其它改动,示例可按原逻辑运行。

docs/examples/handle.tsx (1)

1-1: 导入路径迁移正确

顺带确认 ./components/TooltipSlider 内部也已迁移到 @rc-component/* 生态(tooltip/util 等)。

docs/examples/slider.tsx (1)

2-2: 导入迁移 OK;请复核 null 受控语义在新 hook 下的表现

内部从 useMergedState 改为 useControlledState 后,value: nullundefined 的受控/非受控语义边界可能不同。请手测本文件的 NullableSlider/NullableRangeSlider 场景,确认与旧版一致(含 defaultValueonChangeComplete 时机)。

docs/examples/marks.tsx (1)

1-1: 导入路径迁移正确

仅别名替换,无功能改动。

.dumirc.ts (1)

6-8: 别名更新与迁移一致,LGTM

@rc-component/slider$@rc-component/slider/es 都指向 src,满足文档/示例运行需求。

package.json (2)

2-4: 包改名与版本重置为 1.0.0:请明确迁移/发布策略

[email protected] 迁移到作用域包并重置版本,生态会期望 README/NPM 标签/迁移指南一并到位。请确认:

  • 是否并行发布(rc-slider 继续维护);
  • README 顶部是否增加迁移说明;
  • CDN/unpkg 的路径示例是否同步。

我可以协助起草迁移段落与变更摘要(BREAKING CHANGE)放入 CHANGELOG。


44-47: 依赖迁移到 @rc-component/util 已完成,LGTM

与源码与测试中的导入迁移一致。

Comment on lines +1 to 3
import Trigger from '@rc-component/trigger/lib/mock';

export default Trigger;
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Jest 手动 mock 名称与包名不匹配,当前 mock 可能不生效

文件名仍为 rc-trigger.js,但代码与依赖已迁移到 @rc-component/trigger。Jest 的手动 mock 会按“模块名=文件名”匹配,除非在配置中做了 moduleNameMapper 映射,否则导入 @rc-component/trigger 时不会命中此 mock。建议二选一:

  • 重命名/新增 mock 文件为 tests/__mocks__/@rc-component/trigger.js
  • 或在 Jest 配置里增加 moduleNameMapper@rc-component/trigger 映射到现有 mock。

可以按需应用以下任一修复。

重命名文件方案:

-// tests/__mocks__/rc-trigger.js
+// tests/__mocks__/@rc-component/trigger.js
 import Trigger from '@rc-component/trigger/lib/mock';
 export default Trigger;

Jest 配置映射方案(示例:jest.config.js):

 module.exports = {
   // ...
+  moduleNameMapper: {
+    '^@rc-component/trigger$': '<rootDir>/tests/__mocks__/rc-trigger.js',
+  },
 };

快速校验仓库中是否已存在相关映射或显式 mock:


🏁 Script executed:

#!/bin/bash
# 查找 jest 配置与模块映射,以及是否仍有对 rc-trigger 的显式 mock
fd -a -t f -g "jest*.{js,ts,cjs,mjs,json}" .
rg -n -C2 -P "(moduleNameMapper|@rc-component/trigger|rc-trigger)" --no-heading
rg -n -C2 -P "jest\.mock\(['\"](rc-trigger|@rc-component/trigger)['\"]\)" --type js --type ts --type tsx --type jsx tests src

Length of output: 515


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "==== jest.config.js (if exists) ===="
if [[ -f jest.config.js ]]; then
  sed -n '1,400p' jest.config.js || true
else
  echo "jest.config.js not found at repo root"
fi

echo "==== package.json relevant lines ===="
if [[ -f package.json ]]; then
  sed -n '1,400p' package.json | rg -n --color=never "(\"@rc-component/trigger\"|moduleNameMapper|\"jest\")" || true
else
  echo "package.json not found"
fi

echo "==== tests/__mocks__/rc-trigger.js ===="
if [[ -f tests/__mocks__/rc-trigger.js ]]; then
  sed -n '1,200p' tests/__mocks__/rc-trigger.js || true
else
  echo "tests/__mocks__/rc-trigger.js not found"
fi

echo "==== repo-wide search for moduleNameMapper / jest.mock / @rc-component/trigger / rc-trigger ===="
rg -n --hidden --no-ignore -S "(moduleNameMapper|jest\.mock\(|@rc-component/trigger|rc-trigger)" --no-heading || true

Length of output: 14722


修复 Jest 手动 mock 名称与包名不匹配

tests/mocks/rc-trigger.js 当前文件名为 rc-trigger,但导入的是 '@rc-component/trigger';仓库未配置 moduleNameMapper,Jest 不会命中该 mock。可二选一:

  • 方案 A(推荐):重命名/新增 mock 为 scoped 包名:
-// tests/__mocks__/rc-trigger.js
+// tests/__mocks__/@rc-component/trigger.js
import Trigger from '@rc-component/trigger/lib/mock';
export default Trigger;
  • 方案 B:在 jest.config.js 添加映射到现有 mock:
module.exports = {
  setupFiles: ["./tests/setup.js"],
+ moduleNameMapper: {
+   '^@rc-component/trigger$': '<rootDir>/tests/__mocks__/rc-trigger.js',
+ },
};

位置:tests/mocks/rc-trigger.js,jest.config.js

📝 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
import Trigger from '@rc-component/trigger/lib/mock';
export default Trigger;
// tests/__mocks__/@rc-component/trigger.js
import Trigger from '@rc-component/trigger/lib/mock';
export default Trigger;
Suggested change
import Trigger from '@rc-component/trigger/lib/mock';
export default Trigger;
module.exports = {
setupFiles: ["./tests/setup.js"],
moduleNameMapper: {
'^@rc-component/trigger$': '<rootDir>/tests/__mocks__/rc-trigger.js',
},
};
🤖 Prompt for AI Agents
tests/__mocks__/rc-trigger.js around lines 1-3: the manual Jest mock file name
(rc-trigger.js) does not match the scoped package name '@rc-component/trigger',
so Jest won’t pick it up; fix by either (A) renaming or adding a new mock file
that matches the scoped package path (create
tests/__mocks__/@rc-component/trigger.js or
tests/__mocks__/@rc-component/trigger/index.js and export the same mock), or (B)
add a moduleNameMapper entry in jest.config.js mapping '^@rc-component/trigger$'
to '<rootDir>/tests/__mocks__/rc-trigger.js'; choose A (recommended) unless you
prefer central mapping.

@EmilyyyLiu EmilyyyLiu force-pushed the useControlledState-use branch from c9e2ef3 to 873a4ee Compare September 11, 2025 02:05
@codecov
Copy link

codecov bot commented Sep 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.39%. Comparing base (874875a) to head (873a4ee).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1065   +/-   ##
=======================================
  Coverage   99.39%   99.39%           
=======================================
  Files          14       14           
  Lines         661      661           
  Branches      199      191    -8     
=======================================
  Hits          657      657           
  Misses          4        4           

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

@zombieJ zombieJ merged commit 8d68868 into react-component:master Sep 11, 2025
12 of 13 checks passed
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.

2 participants