@@ -2,7 +2,8 @@ import * as React from 'react';
2
2
import { useLocation } from 'react-router' ;
3
3
import { styled } from '@mui/material/styles' ;
4
4
import GlobalStyles from '@mui/material/GlobalStyles' ;
5
- import { fakeClock , setupFakeClock } from '../utils/setupFakeClock' ; // eslint-disable-line
5
+ // eslint-disable-next-line import/no-relative-packages
6
+ import { fakeClock , setupFakeClock } from '../utils/setupFakeClock' ;
6
7
7
8
const StyledBox = styled ( 'div' , {
8
9
shouldForwardProp : ( prop ) => prop !== 'isDataGridTest' && prop !== 'isDataGridPivotTest' ,
@@ -75,15 +76,16 @@ function TestViewer(props: any) {
75
76
}
76
77
77
78
function MockTime ( props : React . PropsWithChildren < { shouldAdvanceTime : boolean } > ) {
78
- const [ ready , setReady ] = React . useState ( false ) ;
79
+ const [ dispose , setDispose ] = React . useState < ( ( ) => void ) | null > ( null ) ;
80
+ const [ prevShouldAdvanceTime , setPrevShouldAdvanceTime ] = React . useState ( props . shouldAdvanceTime ) ;
79
81
80
- React . useEffect ( ( ) => {
81
- const dispose = setupFakeClock ( props . shouldAdvanceTime ) ;
82
- setReady ( true ) ;
83
- return dispose ;
84
- } , [ props . shouldAdvanceTime ] ) ;
82
+ if ( ! dispose || prevShouldAdvanceTime !== props . shouldAdvanceTime ) {
83
+ dispose ?. ( ) ;
84
+ setDispose ( ( ) => setupFakeClock ( props . shouldAdvanceTime ) ) ;
85
+ setPrevShouldAdvanceTime ( props . shouldAdvanceTime ) ;
86
+ }
85
87
86
- return ready ? props . children : null ;
88
+ return props . children ;
87
89
}
88
90
89
91
function LoadFont ( props : any ) {
0 commit comments