Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/hooks/useStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,13 @@ export default function useStatus(
}

// Consume each visibility transition once. Activity can reconnect this effect
// without a new transition. Read the live status to avoid notifying an old
// render when a layout effect has already started the next motion.
// without a new transition. Wait for the settled render to commit, and
// check the live status in case an effect has already started another motion.
if (
pendingVisibleChangeRef.current &&
asyncVisible !== undefined &&
asyncVisible === visibleRef.current &&
currentStatus === STATUS_NONE &&
getStatus() === STATUS_NONE
) {
pendingVisibleChangeRef.current = false;
Expand Down
27 changes: 27 additions & 0 deletions tests/CSSMotion.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,33 @@ describe('CSSMotion', () => {
unmount();
});

it('removes the node before notifying a new callback when leave is disabled', () => {
const motion = (props: CSSMotionProps) => (
<CSSMotion motionName="transition" motionAppear={false} {...props}>
{({ className }, ref) => (
<div className={className} ref={ref} data-testid="panel" />
)}
</CSSMotion>
);

const { queryByTestId, rerender } = render(motion({ visible: true }));
rerender(motion({ visible: false }));
act(() => {
jest.runAllTimers();
});
expect(queryByTestId('panel')).toHaveClass('transition-leave-active');

const onVisibleChanged = jest.fn(() => {
expect(queryByTestId('panel')).toBeNull();
});
rerender(
motion({ visible: false, motionLeave: false, onVisibleChanged }),
);

expect(onVisibleChanged).toHaveBeenCalledTimes(1);
expect(onVisibleChanged).toHaveBeenCalledWith(false);
});

it('fast visible to !visible', () => {
const onVisibleChanged = jest.fn();

Expand Down
Loading