Skip to content
Chapter 31Lesson 5

Quiz - Loading, errors, and the four async files

Quiz progress

0 / 0

A detail view sits behind a <Suspense>. The user clicks from inv_001 to inv_002, the component re-renders with the new invoiceId, and inv_001’s data stays on screen for the whole new load with no skeleton in between. Why does the fallback skip, and what’s the one-line fix?

React sees the same component in the same slot and reuses its resolved subtree; add key={invoiceId} to the suspending child so a changed key forces a fresh mount that suspends again.

The boundary lost track of the load; add an isLoading flag in a useEffect that watches invoiceId to re-show the skeleton.

A boundary can only suspend once; nest a second <Suspense> around the same component to restore the fallback on later changes.

A dashboard header prints “12 invoices, $48k, last activity 3 minutes ago” — it aggregates three independent reads and can’t render until all three are in. The current code awaits them back-to-back in one component and the page is slow. What’s the right shape?

One Promise.all in one component behind one boundary — the reads run concurrently and the single summary reveals as one unit.

Three separate <Suspense> boundaries, one per read, so each streams in the moment it resolves.

Keep the serial awaits but wrap the component in <Suspense> so the boundary parallelizes them for you.

An error.tsx catches a Server Component data read that failed because the database was briefly unreachable. You wire the “Try again” button to reset(), but clicking it just shows the same error again. Why — and which props are wired correctly? Select all that apply.

reset() only clears the error state and re-renders with the same data, so a failed Server Component read just reproduces the error — wire the button to unstable_retry() instead, which re-fetches and re-renders.

The file must start with 'use client' — Error Boundaries are stateful class-component machinery, so error.tsx can’t be a Server Component.

Surface error.digest in the UI; for a Server Component throw the real message and stack stay on the server, and the digest is what correlates the failure with your logs.

error.tsx also catches a throw in the layout it sits beside, so the same file covers a crash in that segment’s layout.

global-error.tsx returns <html lang="en"><body>…</body></html> — tags no other component you write includes. Why must this one render its own document shell?

It fires because the root layout crashed, and the root layout is what normally renders <html> and <body> — so global-error.tsx replaces the layout and must reconstruct the document shell itself, or it ships a blank page.

Next.js renders every error file as a standalone document, so each error.tsx and not-found.tsx must also include its own <html> and <body>.

The tags are required boilerplate so the file passes the build’s directive check; they have no runtime effect.

Quiz complete

Score by topic