Next.js Discord

Discord Forum

ISR in Ecommerce for Product routes

Unanswered
Northeast Congo Lion posted this in #help-forum
Open in Discord
Northeast Congo LionOP
Hey everyone 🙂 I'm running Next.js 16.2 (no cache components enabled yet), and I am having trouble understanding how to properly implement ISR on my /products/[handle]/page.tsx routes.

Here's my current setup and the issues I'm having:
export const revalidate = 604800 at the top for a 7 day cache revalidation period
export async function generateStaticParams() {
....
const handles = [];
  while(true) {
   const { products, count } = await listProductsDetails({
        limit: STATIC_PARAMS_PAGE_SIZE,
        offset,
        fields: ["id", "handle"],
        strict: true,
        retry: BUILD_TIME_RETRY,
      })
    for(const product of products) {
      handles.push({handle: product.handle})
    }
  }
...
return handles;
}

Then in the actual function component, I run a:
import { unstable_noStore as noStore } from "next/cache"

 if (!product) {
    // Opt this single render out of the Full Route Cache so a missing/draft
    // product doesn't poison the slot for `revalidate` (7 days). The next
    // visit re-runs the page and self-heals as soon as the product publishes.
    // Using unstable_noStore (vs connection()) so a null product during
    // build-time prerender gracefully halts static generation for that path
    // instead of erroring — without PPR, connection() throws here.
    noStore()
    return notFound()
  }


The issue I am having is that when there's an error fetching the product details for whatever reason, I get the error DYNAMIC_SERVER_USAGE.

My current understanding is the following:
1. Generate static params gets all the product handles, then runs the rendering function for each product on build time using workers concurrently to build out the static pages
2. Each page is cached and revalidates every 7 days or via the tag revalidation

However, if a page errors out while building, the 404 gets saved into the cache and can't be revalidated unless manually triggered.

1 Reply

Northeast Congo LionOP
Adding the unstable_noStore helped me branch out the 404s into dynamic rendering, so that when the page gets requested next time, it gets a successful response, gets written into cache, and gets cached for 7 days.

Since I am hosting on Vercel, I have been looking through the logs and have been getting a bunch of
[Error: An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.] {
  digest: 'DYNAMIC_SERVER_USAGE'
}

errors on product pages, though most are cache HITs now.

Is this the intended behavior? Is there something else I could do besides using the new cache components api?