How to gracefully handle cache misses in a Next.js 15 page and trigger reset()?
Unanswered
Snowshoe posted this in #help-forum
SnowshoeOP
I'm using the App Router in Next.js 15 and I have a page.tsx like this:
The issue is: this throw causes the build to fail if data is missing at build time . But in my case, a missing value is often just a transient cache miss, and after retrying the render (like reset() does), the data would likely be available.
I know error.tsx is meant for unexpected errors, but I want to leverage the reset() function from error.tsx as a fallback when I detect a cache miss — basically:
➡️ “If this request failed, allow the user to retry it via reset().”
Since throwing inside page.tsx doesn't work, what’s the best practice here?
export default async function Page({ searchParams }: SomeParamsType) {
const result = await fetchSomeData();
if (!result?.data || result?.error) {
throw new Error("Data is required to render this page.");
}
return <SomeComponent data={result.data} />;
}
The issue is: this throw causes the build to fail if data is missing at build time . But in my case, a missing value is often just a transient cache miss, and after retrying the render (like reset() does), the data would likely be available.
I know error.tsx is meant for unexpected errors, but I want to leverage the reset() function from error.tsx as a fallback when I detect a cache miss — basically:
➡️ “If this request failed, allow the user to retry it via reset().”
Since throwing inside page.tsx doesn't work, what’s the best practice here?