Question presented to candidate: "Several Server Components each need the current user. Do you thread it down from the top, or fetch it in each one?"
What a strong answer should cover:
React.cache()memoises a function for the duration of one server render pass. Identical calls with identical arguments return the same result and run the underlying work once.- That is what makes colocation safe: each component fetches what it needs, and the deduplication means N components produce one request rather than N.
- The scope is deliberately narrow — per request, not a persistent cache. Two different users' page renders never share results.
- Frameworks additionally extend
fetchitself with request memoisation, so identicalfetchcalls dedupe without wrapping. - Cache keys are the arguments, compared by identity — so passing a fresh object each call defeats it.
- It only works inside a React server render. Verified: outside one it does not deduplicate at all.
- Why not just fetch at the top and pass down: that reintroduces prop drilling and couples every component to its parent's data-loading.
- Related but distinct from HTTP caching,
unstable_cache, and a client query library — different lifetimes entirely.
Clarifying questions expected:
- "Is this per-request deduplication, or caching across requests? Those are different tools."
- "Are we in an RSC framework, or a client-only app?"
Code / implementation expected: Yes — a cached data function called from several components.