@@ -90,30 +90,31 @@ export const Spinner: FC<SpinnerProps> = ({
90
90
// only bails out of redundant state updates if they happen outside of a
91
91
// render. Inside a render, if you keep calling a state dispatch, you will
92
92
// get an infinite render loop, no matter what the state value is.
93
- const [ delayDone , setDelayDone ] = useState ( safeDelay === 0 ) ;
94
- if ( delayDone && ! loading ) {
95
- setDelayDone ( false ) ;
93
+ const [ delayExpired , setDelayExpired ] = useState ( safeDelay === 0 ) ;
94
+ if ( delayExpired && ! loading ) {
95
+ setDelayExpired ( false ) ;
96
96
}
97
- if ( ! delayDone && loading && safeDelay === 0 ) {
98
- setDelayDone ( true ) ;
97
+ if ( ! delayExpired && safeDelay === 0 ) {
98
+ setDelayExpired ( true ) ;
99
99
}
100
100
useEffect ( ( ) => {
101
101
if ( safeDelay === 0 ) {
102
102
return ;
103
103
}
104
104
105
105
const delayId = window . setTimeout ( ( ) => {
106
- setDelayDone ( true ) ;
106
+ setDelayExpired ( true ) ;
107
107
} , safeDelay ) ;
108
108
return ( ) => window . clearTimeout ( delayId ) ;
109
109
} , [ safeDelay ] ) ;
110
110
111
111
/**
112
112
* @todo Figure out if this conditional logic can ever cause a component to
113
- * lose state. I would hope not, since the children prop is the same in both
114
- * cases, but I need to test this out
113
+ * lose state when showSpinner flips from false to true while
114
+ * unmountedWhileLoading is false. I would hope not, since the children prop
115
+ * is the same in both cases, but I need to test this out
115
116
*/
116
- const showSpinner = delayDone && loading ;
117
+ const showSpinner = loading && delayExpired ;
117
118
if ( ! showSpinner ) {
118
119
return children ;
119
120
}
0 commit comments