Render-as-You-Fetch
Render-as-You-Fetch starts data fetching before a component reaches the point where it needs the data, allowing network activity and rendering work to overlap. In React applications, this pattern helps reduce request waterfalls and can improve perceived loading performance.
Render-as-You-Fetch separates the start of a data request from the moment a component renders its data-dependent UI. Instead of waiting for rendering to begin before starting the request, the application initiates the request as early as the relevant data dependency is known.
The main benefit is avoiding sequential work. In a render-then-fetch approach, rendering can discover that data is missing, trigger a request, and then wait; nested components can repeat this process and create a waterfall. With Render-as-You-Fetch, the request can already be in flight while React performs other rendering work.
This pattern is particularly useful with Suspense-oriented data fetching. A component can read from a resource that represents an already-started request; if the result is not ready, the component can suspend while other work continues. The exact APIs for implementing this depend on the framework and data-fetching library.
Render-as-You-Fetch does not mean every request should begin immediately. Starting requests too early can waste bandwidth or fetch data that the user never needs. A good implementation starts fetching when the application has enough information to know that the data is likely to be required.
The key performance distinction is timing: the goal is to move network initiation earlier so it overlaps with useful CPU and rendering work, rather than making fetching a prerequisite for beginning all rendering.
Key points
- Start data requests before the dependent render needs their results.
- Reduce request waterfalls by overlapping network and rendering work.
- Suspense can represent an in-flight dependency while rendering proceeds elsewhere.
- Start early enough to create overlap, but not so early that unnecessary data is fetched.
- The pattern concerns request timing, not a specific React API.
Interview questions
What problem does Render-as-You-Fetch solve?
It reduces the time lost when rendering has to wait before a data request can even start. Starting the request earlier lets network latency overlap with rendering and other computation. This is especially useful for avoiding sequential request waterfalls. The result can be faster loading of data-dependent UI.
How does Render-as-You-Fetch relate to Suspense?
A Suspense-compatible data source can expose an in-flight request to a component without requiring the component to start that request itself. If the result is unavailable, reading the resource can suspend rendering of that part of the tree. Because the request was started earlier, network latency can overlap with other rendering work. Suspense provides the coordination mechanism, while the data layer determines how the request is initiated and represented.
How would you prevent Render-as-You-Fetch from causing unnecessary requests?
I would start fetching when there is a strong indication that the data will be needed, rather than eagerly fetching every possible dependency. I would also use caching and request deduplication so multiple consumers can share the same request. Route- or interaction-level preloading can be useful when the next destination is predictable. The trade-off is between earlier latency reduction and wasted bandwidth or server work.
How does Render-as-You-Fetch improve performance compared with Fetch-on-Render?
The central improvement is request timing. Fetch-on-Render can create a dependency chain in which rendering discovers data requirements and only then starts network work, while nested dependencies can extend the chain. Render-as-You-Fetch moves request initiation toward the earliest point where the dependency is known, allowing network latency to overlap with CPU and rendering work. The actual benefit depends on network latency, server response time, caching, and how much work can proceed concurrently.