Skip to content

fix: resolve pre-existing test failures on master - #815

Open
yoyo837 wants to merge 2 commits into
masterfrom
fix/pre-existing-test-failures
Open

yoyo837 wants to merge 2 commits into
masterfrom
fix/pre-existing-test-failures

Conversation

@yoyo837

@yoyo837 yoyo837 commented Sep 16, 2026

Copy link
Copy Markdown
Member

Background

PR #806 and other recent PRs show failing test checks, but the failures are pre-existing on master (reproduced locally by checking out master and running rc-test). They are caused by dependency updates (React 19.2.x / newer @types/react) merged after the last green master test run, not by any specific PR.

Failures fixed

  1. utils › pickAttrs › forwards every React DOM event handler
    @types/react now declares onEnter, onExit, onShare, onUpdate as DOM event handlers. Added them to the eventsName whitelist in pickAttrs so they are forwarded.

  2. hooks-17 › useId › fallback of React 17 or lower
    The fallback id index differs across React versions because StrictMode effect double-invocation behavior changed. The test now asserts the generated id pattern (/rc_unique_\d+/) instead of a fixed index.

Verification

npx rc-test: 30 suites / 197 tests passed (1 skipped) on this branch, while master fails the two tests above.

Summary by CodeRabbit

  • 测试
    • 更新水合相关测试,兼容 StrictMode 下 effect 的多次调用。
    • 收紧 DOM 事件处理器测试范围,避免将组件级回调误判为 DOM 事件。

- pickAttrs: forward new React DOM event handlers (onEnter, onExit,
  onShare, onUpdate) added in newer @types/react
- hooks-17 useId: assert generated id pattern instead of a fixed
  index, since React StrictMode effect double-invocation varies
  across React versions
Copilot AI lite review requested due to automatic review settings September 16, 2026 07:54
@vercel

vercel Bot commented Sep 16, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated
util Ready Ready Preview Sep 16, 2026 10:14am UTC

@coderabbitai

coderabbitai Bot commented Sep 16, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 1663ad54-0833-4503-87c8-86aba11563f6

📥 Commits

Reviewing files that changed from the base of the PR and between b031f69 and 6198688.

📒 Files selected for processing (2)
  • tests/hooks-17.test.tsx
  • tests/utils.test.ts
💤 Files with no reviewable changes (1)
  • tests/hooks-17.test.tsx

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


Walkthrough

本次变更更新两个测试。水合测试匹配动态生成的唯一标识。pickAttrs 测试仅从 DOMAttributes<T> 中收集 DOM 事件处理器。

Changes

测试断言调整

Layer / File(s) Summary
更新水合标识断言
tests/hooks-17.test.tsx
移除 React 版本判断和 matchId 辅助函数。水合断言改为检查目标元素的 id 是否匹配 /^rc_unique_\d+$/
限定 DOM 事件类型扫描
tests/utils.test.ts
测试先提取 DOMAttributes<T> 接口块,再收集其中以 on[A-Z] 开头的事件处理器。

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Merge Risk: ⚪ Minimal · up to 61986

The PR only adjusts test assertions for dependency-compatible behavior and is mergeable.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了本次修复两个既有测试失败的主要变更,内容简洁且与变更范围一致。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 3…
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/pre-existing-test-failures

Warning

Some tools did not complete. Review the errors below.

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

ESLint install timed out. The project may have too many dependencies for the sandbox.


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

小兔检查水合灯,
唯一标识跳数字。
DOM 事件排成行,
类型边界更清晰。
两个测试轻轻改,
断言稳稳向前跑。

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

@github-actions

github-actions Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

React Doctor found no new issues. 🎉

Reviewed by React Doctor for commit 6198688.

@codecov

codecov Bot commented Sep 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.77%. Comparing base (9f2ff96) to head (6198688).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #815   +/-   ##
=======================================
  Coverage   86.77%   86.77%           
=======================================
  Files          41       41           
  Lines        1096     1096           
  Branches      382      389    +7     
=======================================
  Hits          951      951           
  Misses        143      143           
  Partials        2        2           

☔ View full report in Codecov by Harness.
📢 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.

@github-actions

github-actions Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

✅ Preview is ready!

PR preview ✅ Ready ✅ Ready
🔗 Preview https://react-component-util-preview-pr-815.surge.sh
📝 Commit6198688
⏱️ Build time32.365s
📦 Size1.7 MB (-50 B ⬇️) · 46 files
🪵 LogsView logs
📱 MobileScan to open preview on mobile

↩️ Previous: ⚡️ 6198688 · react-component-util-preview-pr-815.surge.sh (open ↗) · 2026-09-16 10:14:55 UTC

🤖 Powered by surge-preview

Copilot AI 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.

🟢 Approval recommended

No blocking issues were identified; the remaining finding is a minor cleanup nit.

Pull request overview

Fixes two pre-existing React 19 test failures.

Changes:

  • Expands pickAttrs event-handler support.
  • Makes the fallback ID test version-independent.
File summaries
File Changes Review notes
tests/hooks-17.test.tsx Validates fallback IDs by pattern. Nit: remove unused matchId helper.
src/pickAttrs.ts Adds four event names to the whitelist.
Review details

Suppressed comments (1)

tests/hooks-17.test.tsx:57

  • The exact-id assertion was replaced, but the matchId helper above this test is now unused (it has no other references in this file). Please remove the dead helper so the test does not retain stale code that can confuse future maintenance.
      // React StrictMode may double-invoke effects across versions, so only
      // assert a generated id instead of a fixed index.
      const ele = container.querySelector('.target');
      expect(ele.id).toMatch(/^rc_unique_\d+$/);
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@zombieJ

zombieJ commented Sep 16, 2026

Copy link
Copy Markdown
Member

来自 Code Review Skill

这个 PR 在做什么

这个 PR 修复依赖升级后的两处测试失败:放宽 React 17 fallback ID 的断言,并向 pickAttrs 白名单加入四个回调名。当前 CI 全部通过,但 pickAttrs 的生产代码修改建立在测试误判之上。

结论

不适合合并

需要撤回四个回调名的白名单变更,并修正测试的事件提取逻辑。否则会把非 DOM 回调错误透传给原生节点。

问题清单

🔴 高优先级(阻塞合并)

  • ViewTransition 组件回调误判为 DOM 事件src/pickAttrs.ts:26

    onEnteronExitonShareonUpdate 属于 React ViewTransitionProps,不属于 DOMAttributes。失败测试扫描了整个 @types/react/index.d.ts,因此把它们错误归类为 DOM handler。

    加入白名单后,组件使用 pickAttrs(..., { attr: true }) 并将结果展开到 DOM 节点时,React 会产生 Unknown event handler property 警告并忽略这些属性;同时破坏了该工具过滤业务回调的语义。建议删除这四项,并使用 TypeScript AST 或限定 DOMAttributes 接口范围来生成测试事件列表。

🟡 中优先级(建议修复)

无。

🟢 低优先级(可选改进)

  • 删除已经失去调用方的 matchId helpertests/hooks-17.test.tsx:25

    新断言直接查询元素后,该函数已经未使用,可以顺手清理。

…ibutes

- Revert adding onEnter/onExit/onShare/onUpdate to pickAttrs eventsName:
  they are ViewTransitionProps callbacks, not DOM event handlers
- Extract React DOM event list only from the DOMAttributes interface
  block instead of scanning the whole index.d.ts
- Remove unused matchId helper in hooks-17 test
@yoyo837

yoyo837 commented Sep 16, 2026

Copy link
Copy Markdown
Member Author

感谢指正,确认是问题 ✅

onEnter/onExit/onShare/onUpdate 确实来自 ViewTransitionProps(index.d.ts 2061-2073 行),不属于 DOMAttributes,之前是测试扫描整个 d.ts 导致的误判。

已在 6198688 修复:

  • 撤回 pickAttrs 白名单的四处变更
  • 测试改为仅从 interface DOMAttributes<T> {...} 块内提取事件列表
  • 顺手删除失去调用方的 matchId helper

本地 rc-test 30 suites / 197 tests 全部通过。

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.

3 participants