From 032e9fb6c784efeb2dfda6785e295de6caa2b78a Mon Sep 17 00:00:00 2001 From: yoyo837 Date: Fri, 13 Nov 2026 09:11:30 +0800 Subject: [PATCH 1/3] fix(motion): attach motion ref to the content wrapper `CSSMotion` binds its transition listeners on the element passed through the motion ref, while the motion classNames and styles are applied to the content wrapper. Since `transitionend` only bubbles upwards, the listeners never saw the wrapper transitions and every motion could only finish through `motionDeadline`. Without a deadline the drawer stayed on `-leave -leave-active` forever and `afterOpenChange(false)` was never called. --- src/DrawerPopup.tsx | 20 ++++++++++++++++++-- tests/motion.spec.tsx | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/src/DrawerPopup.tsx b/src/DrawerPopup.tsx index 4e53f84f..0aa1d543 100644 --- a/src/DrawerPopup.tsx +++ b/src/DrawerPopup.tsx @@ -280,6 +280,21 @@ const DrawerPopup: React.ForwardRefRenderFunction< // =========================== Resize =========================== const wrapperRef = React.useRef(null); + // `CSSMotion` binds its transition listeners on the element passed through the + // motion ref. Motion classNames/styles are applied to the content wrapper, so the + // ref must point to the wrapper as well, otherwise `transitionend` never reaches + // the listeners and the motion can only end via `motionDeadline`. + const motionRefHolder = React.useRef>(null); + const fillWrapperRef = React.useCallback((node: HTMLDivElement) => { + wrapperRef.current = node; + + const motionRef = motionRefHolder.current; + if (typeof motionRef === 'function') { + motionRef(node); + } else if (motionRef) { + (motionRef as React.MutableRefObject).current = node; + } + }, []); const isResizable = !!resizable; const resizeConfig = (typeof resizable === 'object' && resizable) || {}; @@ -328,10 +343,11 @@ const DrawerPopup: React.ForwardRefRenderFunction< leavedClassName={`${prefixCls}-content-wrapper-hidden`} > {({ className: motionClassName, style: motionStyle }, motionRef) => { + motionRefHolder.current = motionRef; + const content = ( { expect(closeCount).toBe(1); }); + + it('ends the leave motion on the transition end of the content wrapper', () => { + const afterOpenChange = jest.fn(); + const motion = { motionName: 'bamboo' }; + + const renderDrawer = (open: boolean, destroyOnHidden?: boolean) => ( + + ); + + const { container, rerender } = render(renderDrawer(true)); + rerender(renderDrawer(false)); + + // Wait for the active step, the only phase which binds the motion events + act(() => { + jest.runAllTimers(); + }); + + const wrapper = container.querySelector('.rc-drawer-content-wrapper'); + expect(wrapper).toHaveClass('bamboo-leave-active'); + + // No `motionDeadline` here: only the transition end of the wrapper can settle it + fireEvent.transitionEnd(wrapper); + + expect(afterOpenChange).toHaveBeenCalledTimes(1); + expect(afterOpenChange).toHaveBeenCalledWith(false); + + act(() => { + jest.runAllTimers(); + }); + + expect(container.querySelector('.rc-drawer-content-wrapper')).toHaveClass( + 'rc-drawer-content-wrapper-hidden', + ); + }); }); From 9f54ac40d1149ddafc9b31f59187afd98ecbc3e7 Mon Sep 17 00:00:00 2001 From: yoyo837 Date: Fri, 13 Nov 2026 09:17:59 +0800 Subject: [PATCH 2/3] refactor: compose the motion ref with fillRef Reuse the shared `fillRef` helper instead of branching on the ref shape by hand, so the object-ref path stays covered by the utility rather than our own code. --- src/DrawerPopup.tsx | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/DrawerPopup.tsx b/src/DrawerPopup.tsx index 0aa1d543..7aa363cc 100644 --- a/src/DrawerPopup.tsx +++ b/src/DrawerPopup.tsx @@ -1,7 +1,7 @@ import { clsx } from 'clsx'; import type { CSSMotionProps } from '@rc-component/motion'; import CSSMotion from '@rc-component/motion'; -import { pickAttrs, useEvent } from '@rc-component/util'; +import { fillRef, pickAttrs, useEvent } from '@rc-component/util'; import * as React from 'react'; import type { DrawerContextProps } from './context'; import DrawerContext from './context'; @@ -284,16 +284,10 @@ const DrawerPopup: React.ForwardRefRenderFunction< // motion ref. Motion classNames/styles are applied to the content wrapper, so the // ref must point to the wrapper as well, otherwise `transitionend` never reaches // the listeners and the motion can only end via `motionDeadline`. - const motionRefHolder = React.useRef>(null); + const motionRefHolder = React.useRef>(null); const fillWrapperRef = React.useCallback((node: HTMLDivElement) => { wrapperRef.current = node; - - const motionRef = motionRefHolder.current; - if (typeof motionRef === 'function') { - motionRef(node); - } else if (motionRef) { - (motionRef as React.MutableRefObject).current = node; - } + fillRef(motionRefHolder.current, node); }, []); const isResizable = !!resizable; From 185a77da5423da3d04b5f3bab65f65a2a8157e32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Mon, 16 Nov 2026 11:14:32 +0800 Subject: [PATCH 3/3] refactor(motion): simplify wrapper ref composition --- src/DrawerPopup.tsx | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/DrawerPopup.tsx b/src/DrawerPopup.tsx index 7aa363cc..6f9772a2 100644 --- a/src/DrawerPopup.tsx +++ b/src/DrawerPopup.tsx @@ -1,7 +1,7 @@ import { clsx } from 'clsx'; import type { CSSMotionProps } from '@rc-component/motion'; import CSSMotion from '@rc-component/motion'; -import { fillRef, pickAttrs, useEvent } from '@rc-component/util'; +import { pickAttrs, useEvent, composeRef } from '@rc-component/util'; import * as React from 'react'; import type { DrawerContextProps } from './context'; import DrawerContext from './context'; @@ -280,15 +280,6 @@ const DrawerPopup: React.ForwardRefRenderFunction< // =========================== Resize =========================== const wrapperRef = React.useRef(null); - // `CSSMotion` binds its transition listeners on the element passed through the - // motion ref. Motion classNames/styles are applied to the content wrapper, so the - // ref must point to the wrapper as well, otherwise `transitionend` never reaches - // the listeners and the motion can only end via `motionDeadline`. - const motionRefHolder = React.useRef>(null); - const fillWrapperRef = React.useCallback((node: HTMLDivElement) => { - wrapperRef.current = node; - fillRef(motionRefHolder.current, node); - }, []); const isResizable = !!resizable; const resizeConfig = (typeof resizable === 'object' && resizable) || {}; @@ -337,8 +328,6 @@ const DrawerPopup: React.ForwardRefRenderFunction< leavedClassName={`${prefixCls}-content-wrapper-hidden`} > {({ className: motionClassName, style: motionStyle }, motionRef) => { - motionRefHolder.current = motionRef; - const content = (