Add transition.inherit to allow transition composition#3538
Conversation
Add opt-in `inheritTransition` prop to MotionConfig that shallow-merges its transition with the parent MotionConfig's transition instead of replacing it. This lets users set global defaults (duration, ease) via a parent MotionConfig while nested MotionConfigs add properties like delay without losing the parent's settings. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
PR Review: Add inheritTransition prop to MotionConfigSummaryThis PR adds an opt-in ✅ Strengths
🔍 Code Quality ReviewImplementation (packages/framer-motion/src/components/MotionConfig/index.tsx:47-49)The merge logic is clean and straightforward: if (config.inheritTransition) {
config.transition = { ...parentConfig.transition, ...config.transition }
}Minor concern: The Context Definition (packages/framer-motion/src/context/MotionConfigContext.tsx:56-62)Good JSDoc documentation added. Interface follows existing patterns.
|
Move transition merging from a MotionConfig prop to a field on the transition object itself. This enables merging at two levels: MotionConfig nesting and value-specific overrides (e.g. opacity). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Code ReviewI've reviewed PR #3538 which adds transition inheritance functionality to MotionConfig. Overall, this is a well-implemented feature that solves a real user pain point (#2271). Here's my detailed feedback: ✅ Strengths1. Clean API DesignThe evolution from a separate 2. Comprehensive Test Coverage
3. Backwards CompatibilityThe opt-in nature via 4. Implementation Quality
🔍 Potential Issues & Suggestions1. Type Safety Concern (Minor)Location: The export function getValueTransition(transition: any, key: string) {Recommendation: Consider typing this as 2. Edge Case: Circular Reference Risk (Low Priority)Location: While unlikely in practice, if a user inadvertently creates circular references in nested MotionConfigs with 3. Documentation GapThe
Consider adding examples to the MotionConfig component JSDoc. 4. useMemo Dependency (Correctness Check)Location: The
Test this scenario: <MotionConfig transition={{ duration: 1 }}>
<MotionConfig transition={{ inherit: true, delay: 0.5 }}>
<motion.div />
</MotionConfig>
</MotionConfig>Does the inner MotionConfig create a new context on every render? If yes, consider memoizing the merged transition separately. 5. Whitespace Issue (Nitpick)Location: There's an extraneous blank line added after 🔒 SecurityNo security concerns identified. The feature doesn't introduce any injection risks or unsafe operations. ⚡ PerformancePerformance impact should be minimal:
The only concern is the useMemo dependency mentioned above (item #4). 📝 Code StyleFollows the repository conventions:
🎯 Recommendations Priority
✨ VerdictThis is a solid implementation of a highly requested feature. The test coverage is excellent, the API design is clean, and backwards compatibility is preserved. The concerns raised are minor and don't block merging, but addressing the useMemo dependency (item #4) would be good to verify before release. Great work! 🚀 |
transition.inherit to allow transition composition
…n animate Extract shared resolveTransition function that handles inherit merging, and reuse it in MotionConfig, getValueTransition, and animateTarget. This enables animate.transition to merge with the component/context transition via inherit: true. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Code ReviewOverviewThis PR adds transition inheritance capability to ✅ Strengths
🔍 Potential Issues & Suggestions1. Performance: Repeated object spreading on hot pathIn transition = transition
? resolveTransition(transition, defaultTransition)
: defaultTransitionThis calls Impact: Low-to-medium depending on animation frequency 2. Edge case:
|
|
yessss lets goooooo 🎉 |
Summary
inherit: truetoTransition