feat: add root exports to avoid deep imports#79
Conversation
|
Someone is attempting to deploy a commit to the React Component Team on Vercel. A member of the Team first needs to authorize it. |
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (10)
Walkthrough更新入口聚合导出以重导出新增类型 Changes导出与依赖入口化
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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
docs/examples/ssr.tsxESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox. src/CSSMotion.tsxESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox. src/hooks/useIsomorphicLayoutEffect.tsESLint skipped: the ESLint configuration for this file references a package that is not available in 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. Comment |
There was a problem hiding this comment.
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.
| import * as UtilDiff from './util/diff'; | ||
| import * as UtilMotion from './util/motion'; | ||
|
|
||
| export { default as MotionContext, default as Provider } from './context'; |
There was a problem hiding this comment.
在 src/context.tsx 中,Context 是通过 export const Context = React.createContext(...) 导出的 React Context 对象,而默认导出(default)是 MotionProvider 组件。
当前代码中:
export { default as MotionContext, default as Provider } from './context';这会导致 MotionContext 和 Provider 都指向 MotionProvider 组件。如果外部用户尝试通过 useContext(MotionContext) 来消费 Context,将会因为传入了组件而不是 Context 对象而导致运行时错误。
应该将 Context 命名导出重命名为 MotionContext 进行导出。
| export { default as MotionContext, default as Provider } from './context'; | |
| export { Context as MotionContext, default as Provider } from './context'; |
There was a problem hiding this comment.
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
| import * as UtilDiff from './util/diff'; | ||
| import * as UtilMotion from './util/motion'; | ||
|
|
||
| export { default as MotionContext, default as Provider } from './context'; |
There was a problem hiding this comment.
🧩 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 2Repository: 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}' || trueRepository: 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}' || trueRepository: 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.tsx中export const Context才是 React Context 对象;但export default是MotionProvider组件。src/index.tsx将./context默认导出同时命名为MotionContext和Provider,因此当前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
2bc21b8 to
c2a4ff4
Compare
背景
其他项目在使用
@rc-component/motion时,为了导入内部模块(如CSSMotion),需要使用 deep import:这会触发 ESLint 的 no-restricted-imports 规则报错。
改动
在 src/index.tsx 中添加根路径导出:
现在可以这样导入:
Summary by CodeRabbit