Preloading data
A request waterfall happens when a component's data request cannot start until earlier, unrelated work has finished. If a child renders only after a slow check completes, its own fetch begins late — even though its inputs were known all along.
Preloading starts that request early, so it runs in parallel with the
blocking work. Export a preload helper next to the component that consumes the
data, and call the fetching function without await:
export const preload = (id: string) => {
void getItem(id);
};
Then call it before the slow work, and render the component afterwards:
export default async function Page({ params }) {
const { id } = await params;
preload(id);
const isAvailable = await checkIsAvailable(id);
return isAvailable ? <Item id={id} /> : null;
}
The item request continues while checkIsAvailable() runs. When <Item>
finally renders and calls getItem(id) again, it must reuse the request that
preloading started. That deduplication is what makes the pattern work: identical
fetch calls are memoised automatically, and non-fetch access must be wrapped
in React.cache (or, with Cache Components, a 'use cache' function).
Keep the preload helper beside the component so the dependency stays easy to find. The goal is simple: start the fetch as early as the inputs are known.
You are about to answer a short quiz on avoiding request waterfalls.