Sub topic 9
Timing: delays, flicker, and transitions
This chapter assumes you know the screen states from earlier in the tutorial (loading, empty, error, success), the main loading patterns (spinners, skeletons, progress bars), and basic TypeScript and CSS. It covers when to show those states, how long to keep them visible, and how to move between them without distracting the user.
Why timing is a design decision
Most state designs are judged as static mockups: a spinner screen, a skeleton screen, a content screen. Users never see them as separate pictures. They see a sequence, and the sequence has a speed. A well-designed skeleton that appears for 80 ms and disappears looks like a glitch. A spinner that never gives way to an error looks like a frozen app.
Three timing problems come up repeatedly:
- Flash of loading state. A fast response triggers a loading indicator that vanishes almost immediately.
- Flicker between states. The screen alternates among loading, content, and loading again, for example during refetches or rapid filter changes.
- Abrupt or jumpy transitions. Content replaces a placeholder with a different size, so the page jumps.
The fixes are a delay before showing, a minimum time on screen, stable layout, and restrained animation.
How long waits feel
Response-time research, popularized by Jakob Nielsen, groups waits into rough bands. The exact numbers vary by context, but they are good defaults.
| Wait | How it feels | Typical design response |
|---|---|---|
| Under about 100 ms | Instant | No indicator. Show the result. |
| 100 ms to 1 s | Noticeable, but the flow continues | Usually no indicator, or a very subtle one such as a pressed button state. |
| 1 s to 10 s | The user's attention starts to drift | Spinner or skeleton. Consider a short status message. |
| Over about 10 s | The user wonders if it is stuck | Determinate progress, a time estimate, a way to leave or cancel, and a plan for timeouts. |
These bands drive the rest of the chapter. A loading indicator is only useful once the user would otherwise wonder whether anything is happening. Before that point, an indicator adds noise.
Delay before showing: avoiding the flash
The first technique is to wait before showing the loading state. If the data arrives inside the delay, the indicator never appears. The typical delay is 200 to 400 ms. This is the idea behind the helper from the topic plan:
function showAfterDelay(delayMs: number, show: () => void): () => void {
const id = setTimeout(show, delayMs);
return () => clearTimeout(id);
}
// Only show the spinner if the request takes longer than 300 ms.
const cancel = showAfterDelay(300, () => console.log("show spinner"));
// When the request finishes quickly, call cancel() to avoid a flash of spinner.
cancel();The function returns a cancel function. Calling it before the timer fires means the spinner is never shown.
A delay alone has a gap, though. Suppose the delay is 300 ms and the response arrives at 350 ms. The spinner appears at 300 ms and disappears 50 ms later. That is the flicker you were trying to avoid, just moved to a different response time.
Minimum visible time: avoiding the blink
The second technique closes that gap. Once an indicator is visible, keep it visible for a minimum time, commonly 400 to 600 ms. A response arriving at 350 ms then leaves the spinner on screen until about 800 ms. The user sees one steady loading state instead of a blink.
This trades speed for stability. You add a little latency in the specific range where an indicator would otherwise flash. Responses faster than the delay are not affected, and slow responses are only held back by at most the minimum visible time.
The following code combines both rules. It controls a show and a hide callback and can be used with any UI framework.
interface IndicatorOptions {
delayMs: number;
minVisibleMs: number;
show: () => void;
hide: () => void;
}
interface Indicator {
start: () => void;
stop: () => void;
}
function createIndicator(opts: IndicatorOptions): Indicator {
let showTimer: ReturnType<typeof setTimeout> | undefined;
let hideTimer: ReturnType<typeof setTimeout> | undefined;
let shownAt: number | null = null;
return {
start() {
// A hide is pending: the indicator is still visible, so keep it.
if (hideTimer !== undefined) {
clearTimeout(hideTimer);
hideTimer = undefined;
return;
}
// Already waiting to show, or already showing.
if (showTimer !== undefined || shownAt !== null) return;
showTimer = setTimeout(() => {
showTimer = undefined;
shownAt = Date.now();
opts.show();
}, opts.delayMs);
},
stop() {
// Finished before the delay elapsed: never show anything.
if (showTimer !== undefined) {
clearTimeout(showTimer);
showTimer = undefined;
return;
}
if (shownAt === null || hideTimer !== undefined) return;
const elapsed = Date.now() - shownAt;
const remaining = Math.max(0, opts.minVisibleMs - elapsed);
hideTimer = setTimeout(() => {
hideTimer = undefined;
shownAt = null;
opts.hide();
}, remaining);
},
};
}
const sleep = (ms: number) => new Promise<void>((r) => setTimeout(r, ms));
async function demo(label: string, requestMs: number): Promise<void> {
const indicator = createIndicator({
delayMs: 300,
minVisibleMs: 500,
show: () => console.log(`${label}: spinner shown`),
hide: () => console.log(`${label}: spinner hidden`),
});
indicator.start();
await sleep(requestMs);
indicator.stop();
console.log(`${label}: content rendered at ${requestMs} ms`);
}
async function main(): Promise<void> {
await demo("fast", 120); // never shows a spinner
await demo("borderline", 350); // spinner stays until about 800 ms
await sleep(600);
await demo("slow", 1500); // spinner for the full wait
await sleep(600);
}
main();Run it and you should see no spinner for the fast case. In the borderline case the spinner is shown at 300 ms and hidden at about 800 ms.
Note the order in the stop function. Cancelling a pending show comes first, because that is the case where nothing was ever displayed.
The state machine behind the indicator
The helper above is a small state machine. Drawing it makes the edge cases easy to check.
The Closing state is what stops flicker when requests come back to back. A user typing in a search box may trigger several requests in quick succession. Without Closing, the indicator hides and reappears between each one.
Avoiding flicker during refetches
Timing rules for the first load differ from rules for later loads.
- Initial load. There is nothing to show. Use a placeholder (skeleton or spinner) with the delay and minimum time described above.
- Refetch with data already on screen. Keep the existing content visible and mark it as updating. Replacing it with a skeleton throws away information the user is reading. A thin progress bar or a small "Updating…" label is usually enough. This approach is often called stale-while-revalidate.
- Rapid changes (filters, search as you type). Debounce the request, keep the old results until the new ones arrive, and ignore responses that are no longer relevant.
That last point is a correctness issue as well as a design one. If request A is slow and request B is fast, B's results can be shown and then overwritten by A's late arrival. Cancel the old request, or compare a request token before applying the result:
let latestRequestId = 0;
async function search(query: string): Promise<void> {
const requestId = ++latestRequestId;
const results = await fetchResults(query);
if (requestId !== latestRequestId) return; // a newer search replaced this one
render(results);
}
declare function fetchResults(query: string): Promise<string[]>;
declare function render(results: string[]): void;Stable layout and transitions
When a placeholder is replaced by content, the user should feel that the same thing filled in. Layout shift breaks that feeling and can cause misclicks if a button moves just as someone taps it.
- Match dimensions. Give skeleton rows the same height and spacing as real rows. Reserve space for images with fixed dimensions or an aspect ratio.
- Do not collapse the container. When a list goes from loading to empty, the empty state should occupy a similar area, so the page below does not jump.
- Prefer fades over slides for swapping states. A short opacity change (about 150 to 250 ms) is enough. Long or bouncy animations make the interface feel slower than the data actually is.
- Animate only what helps. Do not animate every state change. Error appearance, in particular, should be immediate. Delaying an error message to make it fade in slowly delays the user's recovery.
A simple fade with reduced-motion support:
.state-content {
opacity: 1;
transition: opacity 200ms ease-out;
}
.state-content[data-entering="true"] {
opacity: 0;
}
@media (prefers-reduced-motion: reduce) {
.state-content {
transition: none;
}
.skeleton-row {
animation: none;
}
}The prefers-reduced-motion media query respects an operating-system setting. Some users get discomfort or nausea from motion, so shimmering skeletons and sliding panels should switch to static versions when it is set.
Long waits and timeouts
A loading state must end. Decide in advance what happens at each stage of a long wait:
- Under the delay (about 300 ms). Show nothing.
- Short wait (about 300 ms to a few seconds). Show a spinner or skeleton.
- Long wait (for example, after 5 to 10 seconds). Add reassurance, such as "Still working. This is taking longer than usual." Offer a Cancel action if the operation can be cancelled safely.
- Timeout. Stop the request and switch to an error state that is classified as retryable. Do not leave the indicator spinning.
Choose the timeout from the operation. A page of search results might give up at 15 seconds, while a file upload might need minutes and should show determinate progress instead of a spinner.
When you show a determinate progress bar, avoid values that move backward or stall at 99%. If you cannot estimate progress honestly, use an indeterminate indicator and a status message instead.
Timing and assistive technology
Timing choices also affect screen reader users. If you delay the visual spinner by 300 ms, delay the announcement by the same amount. Otherwise a screen reader says "Loading" for every fast request, which is the audible version of flicker. Likewise, announce completion once, not on every intermediate update. Chapter 10 covers live regions in detail. For now, treat the visible indicator and its announcement as one unit with one timing rule.
Common mistakes
- Showing a spinner immediately for every request, including cached or local ones.
- Setting a delay but no minimum visible time, which moves the flicker to a different response speed.
- Replacing visible data with a skeleton during a refetch.
- Letting a late response overwrite a newer one.
- Cleaning up nothing on unmount. If the user navigates away, cancel timers and requests so the callback does not update a screen that no longer exists.
- Using animation durations over 300 ms for routine state swaps.
- Forgetting a timeout, so the loading state can last forever.
Exercise
A product page uses the rule "show a spinner after 300 ms, no minimum visible time." Testers report that on a good connection the spinner still flashes briefly on some page loads. Explain the cause and give a fix, including concrete numbers.
Show answer
The flash happens when the response arrives just after the 300 ms delay, for example at 340 ms. The spinner appears at 300 ms and disappears 40 ms later, which looks like a blink. The delay only protects responses faster than 300 ms. Add a minimum visible time of about 500 ms, so once the spinner appears it stays until at least 800 ms. The result is that responses under 300 ms show no spinner and slower ones show a steady spinner. A secondary option is to fade the placeholder out over about 200 ms instead of removing it instantly. Also make sure the screen reader announcement follows the same delay and minimum.
Exercise
A search box fires a request on each keystroke and shows a skeleton while loading. Users see results flicker, and sometimes the results shown do not match the text in the box. List three changes that address both problems.
Show answer
(1) Debounce the input, for example by 200 to 300 ms, so fewer requests are sent. (2) Keep the previous results visible during the refetch and show only a subtle updating indicator, rather than swapping to a skeleton each time. (3) Guard against out-of-order responses by cancelling the previous request or comparing a request ID before rendering, so a late response for an older query cannot overwrite a newer one. Using a delayed indicator with a minimum visible time for the updating label is also acceptable.