Question presented to candidate: "Our team page loads a list of profile cards from the server, and right now it shows a spinner and then everything jumps into place. Build a skeleton loader instead: grey placeholder shapes in the same layout as the real cards, with a shimmer, that are swapped for the real content when it arrives. Make the skeleton pieces reusable, and handle the request failing."
Requirements:
- Reusable primitive
Skeletonwithvariant(text,circle,rect),widthandheight; numbers mean pixels. - A
ProfileCardSkeletonbuilt from the primitives with exactly the same box sizes as the realProfileCard, so nothing shifts when content arrives. - Loading state modelled explicitly:
loading,success(with data) orerror(with a message). Three skeleton cards while loading, real cards on success, an error with a Retry button on failure. - A Reload button (disabled while loading) shows the skeleton again; a "make the next request fail" checkbox demonstrates the error path. The data comes from a simulated API (a
setTimeoutpromise), and only the latest request may update the screen. - Accessibility: the skeleton shapes are hidden from assistive technology; the list region has
aria-busywhile loading and a status message ("Loading team members"); errors userole="alert". - The shimmer is a CSS animation that is switched off for
prefers-reduced-motion.
What a strong answer should cover:
- Modelling loading as one state with explicit variants instead of several booleans.
- Matching placeholder geometry to the real layout to avoid layout shift, and how to check it.
- Composition: small primitives combined into content-specific skeletons.
- What screen readers should hear instead of empty boxes (
aria-hidden,aria-busy, a live status). - Ignoring stale responses (race conditions, React StrictMode double effects), and when to delay the skeleton to avoid a flash on fast responses.
Clarifying questions expected:
- "How long do requests usually take? Should we avoid flashing a skeleton for very fast responses?"
- "On reload, should old content stay visible while new data loads, or go back to the skeleton?"
- "Do we know how many items to expect, so the skeleton count matches?"
Code / implementation expected: Yes. Primitives, a card skeleton, a page that fetches from a fake API with loading, success and error states.