Skip to content

feat: add root exports to avoid deep imports#79

Closed
EmilyyyLiu wants to merge 1 commit into
react-component:masterfrom
EmilyyyLiu:feat/add-root-exports
Closed

feat: add root exports to avoid deep imports#79
EmilyyyLiu wants to merge 1 commit into
react-component:masterfrom
EmilyyyLiu:feat/add-root-exports

Conversation

@EmilyyyLiu
Copy link
Copy Markdown
Contributor

@EmilyyyLiu EmilyyyLiu commented Jun 5, 2026

背景

其他项目在使用 @rc-component/motion 时,为了导入内部模块(如 CSSMotion),需要使用 deep import:

import CSSMotion from '@rc-component/motion/es/CSSMotion';

这会触发 ESLint 的 no-restricted-imports 规则报错。

改动

在 src/index.tsx 中添加根路径导出:

  • 组件: CSSMotion, CSSMotionList, MotionContext
  • 工具: UtilDiff, UtilMotion
  • 类型: CSSMotionRef

现在可以这样导入:

import CSSMotion from '@rc-component/motion/CSSMotion';
import CSSMotionList from '@rc-component/motion/CSSMotionList';
import { MotionContext, UtilDiff, UtilMotion } from '@rc-component/motion';

Summary by CodeRabbit

  • 改进
    • 扩展了库的导出接口,新增并补充了若干类型与命名导出(保持默认导出不变),改善可导入性。
  • 示例
    • 更新示例代码为统一的导入方式,简化使用体验。
  • 维护/杂项
    • 统一和简化了内部依赖与构建配置,升级了若干依赖版本,调整了 TypeScript 路径映射。

@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 5, 2026

Someone is attempting to deploy a commit to the React Component Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 5, 2026

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f7c47171-846c-4e50-93bb-fab8c24199f4

📥 Commits

Reviewing files that changed from the base of the PR and between 2bc21b8 and c2a4ff4.

📒 Files selected for processing (10)
  • docs/examples/ssr.tsx
  • package.json
  • src/CSSMotion.tsx
  • src/hooks/useIsomorphicLayoutEffect.ts
  • src/hooks/useNextFrame.ts
  • src/hooks/useStatus.ts
  • src/hooks/useStepQueue.ts
  • src/index.tsx
  • src/util/motion.ts
  • tsconfig.json

Walkthrough

更新入口聚合导出以重导出新增类型 CSSMotionRefCSSMotionConfig,将 genCSSMotion 作为命名导出;把若干文件对 @rc-component/util 的深路径/默认导入替换为包入口的命名导入,并同步更新示例、tsconfig 与若干依赖版本。

Changes

导出与依赖入口化

Layer / File(s) Summary
入口导出调整
src/index.tsx
扩展从 ./CSSMotion 的导入以包含 CSSMotionConfig 与新增 CSSMotionRef 类型,并将 genCSSMotion 在命名导出中一并暴露;默认导出仍为 CSSMotionProvider 导出形式保持不变。
统一 @rc-component/util 包入口导入
src/CSSMotion.tsx, src/hooks/useIsomorphicLayoutEffect.ts, src/hooks/useNextFrame.ts, src/hooks/useStatus.ts, src/hooks/useStepQueue.ts, src/util/motion.ts
将原先基于 @rc-component/util 的深路径或默认导入(如 lib/Dom/*, lib/ref, lib/raf, lib/hooks/* 等)替换为从 @rc-component/util 包入口的命名导入(例如 canUseDom, raf, getDOM, composeRef, useState 等)。运行时 API/导出签名未改变。
示例、tsconfig 与依赖更新
docs/examples/ssr.tsx, package.json, tsconfig.json
示例改为 import CSSMotion, { genCSSMotion } from 'rc-motion'package.json 升级 @rc-component/util@rc-component/father-plugin 版本,tsconfig.json 移除 rc-motion/es/* 的路径映射,仅保留 rc-motionsrc/index.tsx 的映射。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • zombieJ

Poem

🐰 入口一并聚,类型轻声出,
深路径化为入口路。
依赖小幅升版本,示例同步来助力,
小兔挥手说改好,构建更顺途。

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

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

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

docs/examples/ssr.tsx

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

src/CSSMotion.tsx

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.

src/hooks/useIsomorphicLayoutEffect.ts

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.

  • 5 others

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
Copy Markdown

@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

This pull request updates src/index.tsx to export additional internal utilities (UtilDiff, UtilMotion), types (CSSMotionRef), and re-exports CSSMotion and MotionContext. A critical issue was identified where MotionContext is incorrectly exported as the default export of ./context (which is actually the MotionProvider component) instead of the named Context export. This would lead to runtime errors when users attempt to consume the context. A suggestion has been provided to correct this export.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/index.tsx Outdated
import * as UtilDiff from './util/diff';
import * as UtilMotion from './util/motion';

export { default as MotionContext, default as Provider } from './context';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

src/context.tsx 中,Context 是通过 export const Context = React.createContext(...) 导出的 React Context 对象,而默认导出(default)是 MotionProvider 组件。

当前代码中:

export { default as MotionContext, default as Provider } from './context';

这会导致 MotionContextProvider 都指向 MotionProvider 组件。如果外部用户尝试通过 useContext(MotionContext) 来消费 Context,将会因为传入了组件而不是 Context 对象而导致运行时错误。

应该将 Context 命名导出重命名为 MotionContext 进行导出。

Suggested change
export { default as MotionContext, default as Provider } from './context';
export { Context as MotionContext, default as Provider } from './context';

Copy link
Copy Markdown

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/index.tsx`:
- Line 13: 当前导出把默认导出(MotionProvider 组件)同时命名为 MotionContext 和 Provider,导致
MotionContext 实际是 Provider 而非 React Context 对象;修复方法是在 src/index.tsx 中将 ./context
的 Context 命名导出为 MotionContext(即 export Context as MotionContext)并把默认导出以
MotionProvider 或 Provider 的名称导出(例如 export default as MotionProvider 或命名导出
Provider),确保 Context、MotionProvider/Provider 的命名与 src/context.tsx 中的 Context
和默认导出组件一致以消除语义混淆。
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 08935bf3-36aa-49da-9fc8-b0e30b9a9603

📥 Commits

Reviewing files that changed from the base of the PR and between 5b7cb37 and 2bc21b8.

📒 Files selected for processing (1)
  • src/index.tsx

Comment thread src/index.tsx Outdated
import * as UtilDiff from './util/diff';
import * as UtilMotion from './util/motion';

export { default as MotionContext, default as Provider } from './context';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚖️ Poor tradeoff

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# 验证 ./context 文件的默认导出以及是否需要导出 Context 对象

# 检查 context.tsx 的导出结构
echo "=== Checking context.tsx exports ==="
rg -A 2 "^export default" src/context.tsx

# 检查是否有命名导出 Context
echo -e "\n=== Checking for Context named export ==="
rg -n "^export.*Context" src/context.tsx

# 搜索代码库中对 MotionContext 的使用,确认消费者期望
echo -e "\n=== Checking usage of MotionContext in codebase ==="
rg -n "MotionContext" --type ts --type tsx -C 2

Repository: react-component/motion

Length of output: 346


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Show src/index.tsx around line 13 ==="
nl -ba src/index.tsx | sed -n '1,80p'

echo -e "\n=== Search for MotionContext usage across src (no file type filter) ==="
rg -n "MotionContext" src -C 2 || true

echo -e "\n=== Search for imports from ./context or context in general ==="
rg -n "from ['\"].*context['\"]" src -C 2 || true

echo -e "\n=== Search for named Context usage ==="
rg -n "\\bContext\\b" src -S -C 2 --glob 'src/**/*.{ts,tsx}' || true

Repository: react-component/motion

Length of output: 169


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Show src/index.tsx (first 120 lines with line numbers) ==="
cat -n src/index.tsx | sed -n '1,120p'

echo -e "\n=== Search for MotionContext usage across src ==="
rg -n "MotionContext" src -C 2 || true

echo -e "\n=== Search for imports from ./context or .*context ==="
rg -n "from ['\"].*context['\"]" src -C 2 || true

echo -e "\n=== Search for named Context usage (exported/used) ==="
rg -n "\\bContext\\b" src -S -C 2 --glob 'src/**/*.{ts,tsx}' || true

Repository: react-component/motion

Length of output: 3812


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Show src/context.tsx around exports ==="
cat -n src/context.tsx | sed -n '1,120p'

Repository: react-component/motion

Length of output: 785


修正 MotionContext 的导出语义以避免 API 误导。

  • src/context.tsxexport const Context 才是 React Context 对象;但 export defaultMotionProvider 组件。
  • src/index.tsx./context 默认导出同时命名为 MotionContextProvider,因此当前 MotionContext 实际导出的是 Provider 组件而非 Context 对象(名称语义不一致)。
  • 建议按目标拆分命名:若要暴露 Context 对象,应在 src/index.tsx 里导出 Context as MotionContext;若要暴露 Provider 组件,应将其命名为 MotionProvider/Provider(而不要用 MotionContext)。
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/index.tsx` at line 13, 当前导出把默认导出(MotionProvider 组件)同时命名为 MotionContext 和
Provider,导致 MotionContext 实际是 Provider 而非 React Context 对象;修复方法是在 src/index.tsx
中将 ./context 的 Context 命名导出为 MotionContext(即 export Context as
MotionContext)并把默认导出以 MotionProvider 或 Provider 的名称导出(例如 export default as
MotionProvider 或命名导出 Provider),确保 Context、MotionProvider/Provider 的命名与
src/context.tsx 中的 Context 和默认导出组件一致以消除语义混淆。

* fix: avoid rc package deep imports

* chore: remove local deep import lint rule

* chore: bump father-plugin
@EmilyyyLiu EmilyyyLiu force-pushed the feat/add-root-exports branch from 2bc21b8 to c2a4ff4 Compare June 5, 2026 02:28
@EmilyyyLiu EmilyyyLiu closed this Jun 5, 2026
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