Question presented to candidate:
"Our product page takes about a second and a half to render because of a slow API. Users stare at a blank screen. What does adding loading.tsx change, and how does streaming actually work under the hood?"
What a strong answer should cover:
loading.tsxbecomes a React<Suspense>boundary around the segment page (inside the layout), with the loading component as the fallback.- With it, the server sends the layout and the fallback in the first chunk and streams the page HTML into the same response when it is ready; without it, nothing is sent until the page finishes.
- On client navigation the fallback is prefetched, so the URL changes and the skeleton shows immediately, and the shared layout stays interactive.
- Manual
<Suspense>boundaries give finer control: independent parts stream in any order as each one resolves. - Limits:
loading.tsxdoes not cover the layout of the same segment, so awaiting request data at the top of that layout still blocks; the status code is fixed (200) once streaming starts. - Streaming is server-rendered HTML, so it does not hurt SEO; static export does not support it.
Clarifying questions expected:
- "Is the slow part in the page or in the layout?" β
loading.tsxonly helps with the page and below. - "Do all parts of the page depend on the slow call?" β if not, smaller Suspense boundaries show more content sooner.
Code / implementation expected: Yes β a loading.tsx, a page with two Suspense boundaries, and a layout that keeps request data inside its own boundary.