Skip to the page

Rendering strategies · senior

Streaming with loading.tsx and Suspense

Streaming sends the page shell first and each Suspense boundary's content later in the same response; loading.tsx is a route-level Suspense boundary, and pushing slow or request-time work down into small boundaries keeps the rest of the page fast.

The notes

What you must know

  • loading.tsx automatically wraps the segment's page in <Suspense>; inline <Suspense> lets you place boundaries anywhere.
  • A top-level await on cookies(), headers() or a session check in a layout delays the first streamed chunk and holds {children} behind it. Move it into a small component (like <UserMenu>) inside Suspense.
  • Start fetches in parallel and pass promises down so boundaries resolve independently.
  • Fallbacks should reserve space (skeletons with fixed size) to avoid CLS.
  • The HTTP status is sent with the shell; call notFound()/redirect() before streaming starts where possible.
  • Dynamic pages stream metadata after the shell; bots that need metadata in <head> (detected by user agent, configurable with htmlLimitedBots) get a blocking render.
  • Self-hosting: proxies must not buffer (X-Accel-Buffering: no for nginx), otherwise the shell and content arrive together and PPR loses its benefit.
  • With Partial Prefetching, loading shells are prefetched so clicks show UI instantly.

The red pen

Common traps: mistake → fix

  • Mistake: "One loading.tsx at the root is enough"

    Fix: the whole page shows one spinner; place boundaries around slow parts.

  • Mistake: "Streaming needs WebSockets"

    Fix: it is one HTTP response sent in chunks.

  • Mistake: "notFound() deep in a streamed boundary still returns 404"

    Fix: the status may already be committed.

Easy to hard

Questions interviewers ask, easy to hard

  1. How does streaming work in the App Router?
  2. What is the difference between loading.tsx and an inline <Suspense>?
  3. Our dashboard header awaits the session and the whole page waits. Fix it.
  4. What happens to status codes once streaming has started?
  5. Why does streaming not work behind our nginx?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview