Skip to content

fix: guard missing React version export - #810

Merged
yoyo837 merged 1 commit into
react-component:masterfrom
nrps9909:codex/fix-vite-react-version
Sep 17, 2026
Merged

yoyo837 merged 1 commit into
react-component:masterfrom
nrps9909:codex/fix-vite-react-version

Conversation

@nrps9909

@nrps9909 nrps9909 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  • avoid crashing while loading rc-util/es/ref when a bundler's React interop object does not expose version
  • preserve the existing React 19 check when version is available
  • add a regression test for the missing-export shape

Why

rc-util@5.44.4 started reading version.split(...) at module scope, and the same unguarded read remains in the current @rc-component/util source. In the Vite production-build cases reported in #647 and #783, the React named export can be undefined, so importing ref.js throws before the application renders. Treating a missing version as an unknown version keeps the React 18-compatible path and prevents the module-load failure. A legacy rc-util release would require a maintainer backport to 5.x.

Verification — September 17, 2026

Rebased onto current master (c241125); signed/GitHub-Verified head: 3863469d708a5a5be1b34e93148c10572fae31a4.

  • Full suite: 31 suites, 198 tests passed; 1 test skipped.
  • TypeScript, ESM/CJS/declaration build, focused ESLint (0 errors), Prettier and diff checks passed.
  • GitHub signatures and changed-file blobs were checked against the local branch.
  • Includes upstream fix: resolve pre-existing test failures on master #815, which fixes the prior pickAttrs and React-17 fallback test failures.
  • Upstream CI: ✅ test currently action_required. A maintainer must approve the fork workflow before it can run.
  • Vercel preview still requires upstream team authorization.

AI assistance disclosure

Codex assisted with implementation, conflict resolution, regression tests, and validation.

@vercel

vercel Bot commented Aug 28, 2026

Copy link
Copy Markdown

@nrps9909 is attempting to deploy a commit to the afc163's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: da1677a1-1d37-49d5-9dfa-f5742312c915

📥 Commits

Reviewing files that changed from the base of the PR and between d1045f4 and a42c5a7.

📒 Files selected for processing (2)
  • src/ref.ts
  • tests/ref-version.test.ts

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


Walkthrough

本次变更为 ReactMajorVersion 增加可选链访问,并新增测试。versionundefined 时,模块加载不再因调用 split 抛出异常。

Changes

React version 缺失处理

Layer / File(s) Summary
version 防护与加载测试
src/ref.ts, tests/ref-version.test.ts
ReactMajorVersion 使用 version?.split('.')[0]。新增 Jest 测试,验证 React 未导出 version 时加载 src/ref 不会抛出异常。

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

Merge Risk: ⚪ Minimal · up to a42c5

The change prevents an import-time crash when React lacks a version export while preserving the existing behavior when the version is available. No actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed 变更满足问题 #647 的主要目标。代码在 React 版本导出为 undefined 时避免调用 split,并新增回归测试验证模块加载不会抛出异常。
Out of Scope Changes check ✅ Passed 所有变更均围绕问题 #647,包括 React 版本检测修复和对应回归测试。未发现无关或超出范围的代码变更。
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 2…
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题“fix: guard missing React version export”准确概括了主要变更,即防止缺少 React 版本导出时发生崩溃。标题简洁且具体。
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 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

小兔守着 version 门,
缺失时也不惊慌。
可选链轻轻探路,
ref 模块安稳加载。
测试敲响绿色铃,
代码继续向前跑。

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

@nrps9909
nrps9909 force-pushed the codex/fix-vite-react-version branch from cc94637 to 3825a2b Compare August 28, 2026 10:16
@nrps9909
nrps9909 changed the base branch from 5.x to master August 28, 2026 10:16
@nrps9909
nrps9909 force-pushed the codex/fix-vite-react-version branch from 3825a2b to a42c5a7 Compare August 28, 2026 10:17
@yoyo837

yoyo837 commented Sep 17, 2026

Copy link
Copy Markdown
Member

CI failed.

Signed-off-by: 陳廷安 <73953029+nrps9909@users.noreply.github.com>
@nrps9909
nrps9909 force-pushed the codex/fix-vite-react-version branch from a42c5a7 to 3863469 Compare September 17, 2026 08:18
@nrps9909

Copy link
Copy Markdown
Contributor Author

Rebased onto current master (c241125); signed/GitHub-Verified head: 3863469d708a5a5be1b34e93148c10572fae31a4.

  • Full suite: 31 suites, 198 tests passed; 1 test skipped.
  • TypeScript, ESM/CJS/declaration build, focused ESLint (0 errors), Prettier and diff checks passed.
  • GitHub signatures and changed-file blobs were checked against the local branch.
  • Includes upstream fix: resolve pre-existing test failures on master #815, which fixes the prior pickAttrs and React-17 fallback test failures.
  • Upstream CI: ✅ test currently action_required. A maintainer must approve the fork workflow before it can run.
  • Vercel preview still requires upstream team authorization.

@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.77%. Comparing base (c241125) to head (3863469).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #810   +/-   ##
=======================================
  Coverage   86.77%   86.77%           
=======================================
  Files          41       41           
  Lines        1096     1096           
  Branches      397      382   -15     
=======================================
  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.

@yoyo837
yoyo837 merged commit 389c571 into react-component:master Sep 17, 2026
11 of 12 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