@@ -139,13 +139,16 @@ function useShowSpinner(loading: boolean, spinnerDelayMs: number): boolean {
139
139
safeDelay = 0 ;
140
140
}
141
141
142
- // Doing a bunch of mid-render state syncs to minimize risks of
143
- // contradictory states during re-renders. It's ugly, but it's what the
144
- // React team officially recommends. Be very careful with this logic; React
145
- // only bails out of redundant state updates if they happen outside of a
146
- // render. Inside a render, if you keep calling a state dispatch, you will
147
- // get an infinite render loop, no matter what the state value is. There
148
- // must be a "base case" that causes re-renders to stabilize/stop
142
+ // Doing a bunch of mid-render state syncs to minimize risks of UI tearing
143
+ // during re-renders. It's ugly, but it's what the React team officially
144
+ // recommends (even though this specific case is extra nasty).
145
+ //
146
+ // Be very careful with this logic; React only bails out of redundant state
147
+ // updates if they happen outside of a render. Inside a render, if you keep
148
+ // calling a state dispatch, you will get an infinite render loop, no matter
149
+ // what the value you dispatch. There must be a "base case" in the render
150
+ // path that causes state dispatches to stop eventually so that React can
151
+ // move on to the next component in the tree
149
152
const [ delayLapsed , setDelayLapsed ] = useState ( safeDelay === 0 ) ;
150
153
const [ renderCache , setRenderCache ] = useState ( { loading, safeDelay } ) ;
151
154
const resetOnRerender =
0 commit comments