Sub topic 3
Choosing a Loading Pattern
Assume you know basic UI design vocabulary, asynchronous data fetching, HTML, and TypeScript. This chapter focuses on choosing how a screen communicates waiting. The goal is not to make every request look busy. The goal is to help people understand what is happening and what they can do while they wait.
A loading pattern is the visual and behavioral design used while data or an action is in progress. The right pattern depends on the wait’s length, the user’s task, and how much of the final content is already known.
Match the pattern to the wait
Use a spinner when the user needs to wait for an operation, but the interface does not have enough information to show the result’s shape. A spinner works well for a short action such as saving a setting or loading a small menu.
Use a skeleton screen when the layout of the incoming content is predictable. A skeleton is a simplified placeholder for the final interface. It shows where headings, images, and rows will appear. This helps users understand the page structure before the content arrives.
Use a progress indicator when the system can measure progress. A determinate progress bar might show that an upload is 60% complete. An indeterminate progress bar communicates activity without claiming a completion percentage.
Use optimistic UI when the system can update the interface immediately and safely correct the result if the operation fails. For example, a user can mark an item as favorite immediately while the request runs in the background.
| Pattern | Best fit | Main risk |
|---|---|---|
| Spinner | Short, discrete actions | Gives little information during a long wait |
| Skeleton | Predictable page or list layout | Feels misleading if the layout changes |
| Progress bar | Measurable work, such as uploads | False precision when progress is estimated |
| Optimistic UI | Reversible, low-risk actions | Users may see a change that later fails |
Choose between a spinner and a skeleton
A spinner is compact and honest. It says, “The system is working,” but it does not suggest when the work will finish. Use it for a button, dialog, or small region rather than replacing an entire page when the page structure is already known.
A skeleton reduces the sense of a blank screen. It works especially well for repeated rows, cards, or article layouts. Match the skeleton’s size and position to the expected content. A row that jumps from a short placeholder to a tall result creates layout shift, which makes the page harder to follow.
Do not use a skeleton merely because it looks polished. If the response usually arrives almost immediately, a skeleton can flash and make the interface feel slower. If the content has no stable shape, a spinner is clearer.
Use progress and optimistic updates carefully
A progress bar should represent a meaningful measurement. For a file upload, bytes sent can provide a real percentage. For a server task with unknown work, use an indeterminate indicator instead of advancing a bar at arbitrary speeds.
Optimistic UI shortens perceived response time by showing the expected result before confirmation. It needs a recovery plan:
- Disable duplicate actions while the request is pending.
- Keep enough information to restore the previous state.
- Explain what happened if the request fails.
- Give the user a retry action when retrying is safe.
Use optimistic UI for actions such as toggling a preference, adding a reaction, or reordering a personal list. Avoid it for irreversible actions, payments, or operations where a temporary display could cause serious confusion.
> callout warning > Never show a percentage that the system cannot support. A moving indicator is not the same as measurable progress.
Handle transitions deliberately
Loading is a state, not a decoration. A screen may move from loading to success, empty, or error. Design each transition so the user can tell what changed.
For short requests, delay showing a spinner by roughly 200–300 milliseconds. If the request completes before the delay, show no loading indicator. This prevents a brief flash that makes fast interactions feel unstable. For longer requests, keep the indicator visible until the result is ready.
A refresh has a different requirement from an initial load. Keep existing content visible when possible and show a smaller indicator near the refreshed region. Replacing useful content with a full-page spinner makes the interface feel less responsive.
function showAfterDelay(delayMs: number, show: () => void): () => void {
const id = setTimeout(show, delayMs);
return () => clearTimeout(id);
}
const cancelSpinner = showAfterDelay(300, () => {
console.log("show spinner");
});
// Call this when the request finishes before 300 ms.
cancelSpinner();Review a loading pattern
Before release, ask:
- Does the pattern match the actual information available?
- Does it preserve useful content during refreshes?
- Does it avoid false progress or unnecessary animation?
- Can users tell which control or region is waiting?
- What happens when the request takes much longer than usual?
- What happens if it succeeds with no items or fails?
Exercise
A project list has a stable row layout, but the API usually takes two seconds and provides no completion percentage. Which loading pattern is the best default, and why?
Show answer
Use a skeleton list. The stable layout lets users see the page structure, and the two-second wait is long enough that a blank region would feel unresponsive. Use an indeterminate indicator as a small supplement if needed, but do not invent a percentage.