@@ -9,7 +9,6 @@ import { useDirection } from '@radix-ui/react-direction';
99import { useComposedRefs } from '@radix-ui/react-compose-refs' ;
1010import { useControllableState } from '@radix-ui/react-use-controllable-state' ;
1111import { useId } from '@radix-ui/react-id' ;
12- import { useLayoutEffect } from '@radix-ui/react-use-layout-effect' ;
1312
1413import type * as Radix from '@radix-ui/react-primitive' ;
1514import type { Scope } from '@radix-ui/react-context' ;
@@ -231,29 +230,11 @@ const TabsContent = React.forwardRef<TabsContentElement, TabsContentProps>(
231230 const composedRefs = useComposedRefs ( forwardedRef , ref ) ;
232231 const isSelected = value === context . value ;
233232 const isMountAnimationPreventedRef = React . useRef ( isSelected ) ;
234- const originalStylesRef = React . useRef < Record < string , string > > ( ) ;
235233
236- useLayoutEffect ( ( ) => {
237- const node = ref . current ;
238-
239- if ( node ) {
240- originalStylesRef . current = originalStylesRef . current || {
241- animationDuration : node . style . animationDuration ,
242- } ;
243-
244- // Prevent animations from running if open when initially mounted
245- const originalDuration = originalStylesRef . current . animationDuration ;
246- const animationPrevented = isMountAnimationPreventedRef . current ;
247-
248- node . style . animationDuration = animationPrevented ? '0s' : originalDuration ;
249- isMountAnimationPreventedRef . current = false ;
250- }
251-
252- /**
253- * Depends on `isSelected` as we want to restore the original
254- * animation when navigating away from an initially open tab.
255- */
256- } , [ isSelected ] ) ;
234+ React . useEffect ( ( ) => {
235+ const rAF = requestAnimationFrame ( ( ) => ( isMountAnimationPreventedRef . current = false ) ) ;
236+ return ( ) => cancelAnimationFrame ( rAF ) ;
237+ } , [ ] ) ;
257238
258239 return (
259240 < Presence present = { isSelected } >
@@ -268,6 +249,10 @@ const TabsContent = React.forwardRef<TabsContentElement, TabsContentProps>(
268249 tabIndex = { 0 }
269250 { ...contentProps }
270251 ref = { composedRefs }
252+ style = { {
253+ ...props . style ,
254+ animationDuration : isMountAnimationPreventedRef . current ? '0s' : undefined ,
255+ } }
271256 >
272257 { present && children }
273258 </ Primitive . div >
0 commit comments