Skip to content

Commit 7a668d2

Browse files
committed
docs: update comments for clarity
1 parent 4560c24 commit 7a668d2

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

site/src/components/Spinner/Spinner.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,16 @@ function useShowSpinner(loading: boolean, spinnerDelayMs: number): boolean {
139139
safeDelay = 0;
140140
}
141141

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
149152
const [delayLapsed, setDelayLapsed] = useState(safeDelay === 0);
150153
const [renderCache, setRenderCache] = useState({ loading, safeDelay });
151154
const resetOnRerender =

0 commit comments

Comments
 (0)