Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@mantine/core] next try fixing transition issues #5873

Merged
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useEffect, useRef, useState } from 'react';
import ReactDOM from 'react-dom';
import { useDidUpdate, useReducedMotion } from '@mantine/hooks';
import { useMantineTheme } from '../../core';

Expand Down Expand Up @@ -43,7 +44,6 @@ export function useTransition({
const preHandler = shouldMount ? onEnter : onExit;
const handler = shouldMount ? onEntered : onExited;

setStatus(shouldMount ? 'pre-entering' : 'pre-exiting');
window.clearTimeout(timeoutRef.current);

const newTransitionDuration = reduceMotion ? 0 : shouldMount ? duration : exitDuration;
Expand All @@ -56,6 +56,10 @@ export function useTransition({
} else {
// Make sure new status won't be set within the same frame as this would disrupt animation #3126
rafRef.current = requestAnimationFrame(() => {
ReactDOM.flushSync(() => {
setStatus(shouldMount ? 'pre-entering' : 'pre-exiting');
});

rafRef.current = requestAnimationFrame(() => {
typeof preHandler === 'function' && preHandler();
setStatus(shouldMount ? 'entering' : 'exiting');
Expand Down
10 changes: 8 additions & 2 deletions packages/@mantine/modals/src/use-modals/use-modals.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ describe('@mantine/modals/use-modals', () => {
const modals = useModals();

useEffect(() => {
modals.openContextModal('contextTest', { innerProps: { text: testContent } });
modals.openContextModal('contextTest', {
innerProps: { text: testContent },
transitionProps: { duration: 0 },
});
}, []);

return <div>Empty</div>;
Expand All @@ -64,7 +67,7 @@ describe('@mantine/modals/use-modals', () => {
const modals = useModals();

useEffect(() => {
modals.openConfirmModal({});
modals.openConfirmModal({ transitionProps: { duration: 0 } });
}, []);

return <div>Empty</div>;
Expand All @@ -90,6 +93,7 @@ describe('@mantine/modals/use-modals', () => {
useEffect(() => {
modals.openConfirmModal({
labels: { confirm: 'Confirm', cancel: 'Cancel' },
transitionProps: { duration: 0 },
});
}, []);

Expand Down Expand Up @@ -117,6 +121,7 @@ describe('@mantine/modals/use-modals', () => {
confirm: <span>Confirm</span>,
cancel: <span>Cancel</span>,
},
transitionProps: { duration: 0 },
});
}, []);

Expand All @@ -143,6 +148,7 @@ describe('@mantine/modals/use-modals', () => {
modals.openModal({
title: 'Test title',
children: <h1>Children</h1>,
transitionProps: { duration: 0 },
});
}, []);

Expand Down
Loading