@@ -110,6 +110,10 @@ export interface CSSMotionState {
110110 prevProps ?: CSSMotionProps ;
111111}
112112
113+ export function isRefConsume ( children ?: CSSMotionProps [ 'children' ] ) {
114+ return children ?. length < 2 ;
115+ }
116+
113117/**
114118 * `transitionSupport` is used for none transition test case.
115119 * Default we use browser transition event support check.
@@ -193,33 +197,33 @@ export function genCSSMotion(config: CSSMotionConfig) {
193197 }
194198
195199 // We should render children when motionStyle is sync with stepStatus
196- const motionChildren = React . useMemo ( ( ) => {
200+ const returnNode = React . useMemo ( ( ) => {
197201 if ( styleReady === 'NONE' ) {
198202 return null ;
199203 }
200204
201- let nextMotionChildren : React . ReactNode ;
205+ let motionChildren : React . ReactNode ;
202206 const mergedProps = { ...eventProps , visible } ;
203207
204208 if ( ! children ) {
205209 // No children
206- nextMotionChildren = null ;
210+ motionChildren = null ;
207211 } else if ( status === STATUS_NONE ) {
208212 // Stable children
209213 if ( mergedVisible ) {
210- nextMotionChildren = children ( { ...mergedProps } , nodeRef ) ;
214+ motionChildren = children ( { ...mergedProps } , nodeRef ) ;
211215 } else if ( ! removeOnLeave && renderedRef . current && leavedClassName ) {
212- nextMotionChildren = children (
216+ motionChildren = children (
213217 { ...mergedProps , className : leavedClassName } ,
214218 nodeRef ,
215219 ) ;
216220 } else if ( forceRender || ( ! removeOnLeave && ! leavedClassName ) ) {
217- nextMotionChildren = children (
221+ motionChildren = children (
218222 { ...mergedProps , style : { display : 'none' } } ,
219223 nodeRef ,
220224 ) ;
221225 } else {
222- nextMotionChildren = null ;
226+ motionChildren = null ;
223227 }
224228 } else {
225229 // In motion
@@ -237,7 +241,7 @@ export function genCSSMotion(config: CSSMotionConfig) {
237241 `${ status } -${ statusSuffix } ` ,
238242 ) ;
239243
240- nextMotionChildren = children (
244+ motionChildren = children (
241245 {
242246 ...mergedProps ,
243247 className : clsx ( getTransitionName ( motionName , status ) , {
@@ -250,22 +254,20 @@ export function genCSSMotion(config: CSSMotionConfig) {
250254 ) ;
251255 }
252256
253- return nextMotionChildren ;
257+ return motionChildren ;
254258 } , [ idRef . current ] ) as React . ReactElement ;
255259
256- const shouldAutoInjectRef = children ?. length < 2 ;
257-
258- if ( shouldAutoInjectRef && supportNodeRef ( motionChildren ) ) {
259- const originNodeRef = getNodeRef ( motionChildren ) ;
260+ if ( isRefConsume ( children ) && supportNodeRef ( returnNode ) ) {
261+ const originNodeRef = getNodeRef ( returnNode ) ;
260262
261263 if ( originNodeRef !== nodeRef ) {
262- return React . cloneElement ( motionChildren , {
264+ return React . cloneElement ( returnNode , {
263265 ref : composeRef ( originNodeRef , nodeRef ) ,
264266 } ) ;
265267 }
266268 }
267269
268- return motionChildren ;
270+ return returnNode ;
269271 } ,
270272 ) ;
271273
0 commit comments