ISR Mental Model
ISR in the App Router: time-based revalidation, on-demand tags, stale-while-revalidate behavior, and when to go fully dynamic.
- nextjs
- isr-mental
Incremental Static Regeneration (ISR) means: serve a cached page (or fetch result), and refresh it in the background after a time window or on-demand invalidation. Users rarely wait on rebuilds for the whole site.
Docs: Revalidating, Caching.
Time-based
export const revalidate = 60; // segment
// or per fetch
await fetch(url, { next: { revalidate: 60 } });
After 60 seconds, the next request can trigger regeneration; subsequent users get the new version (stale-while-revalidate style behavior depending on platform).
On-demand
import { revalidatePath, revalidateTag } from 'next/cache';
export async function updateProduct(id: string) {
await db.products.update(id);
revalidateTag('product');
revalidatePath(`/product/${id}`);
}
CMS webhooks often call a Route Handler that revalidates tags after publish.
Mental model
- Prefer static + revalidate for content that changes occasionally.
- Tag related fetches so one publish updates many surfaces.
- Use fully dynamic for per-user private data.
- Do not assume “ISR” is a single API — it is the outcome of caching + revalidation settings.
Pitfalls
- Forgetting tags → stale UI after CMS edit.
- Mixing
no-storewith ISR expectations. - Revalidating the wrong path (trailing slashes, locales).
Interview out-loud
“ISR serves cached output and regenerates after a time window or on-demand revalidation. In App Router I set revalidate on fetch or segments and call revalidateTag after mutations. Private personalized data stays dynamic instead.”
Related on this site
- Revalidate Path and Tag
- Caching in Next.js Overview
- Static vs Dynamic Rendering
- Server Actions Overview
Further reading
Edge cases worth rehearsing
Interviewers and production incidents cluster around the same edges: first render versus update, empty and loading states, Strict Mode double setup, concurrent interruptions, and what happens when identity (key, route params, user id) changes mid-edit. Walk one concrete user journey end-to-end — open, edit, navigate away, come back — and say which state survives.
Prefer fixing data flow and ownership before reaching for memoization or micro-optimizations. Prefer event handlers over effects when a user action is the trigger. Prefer deriving values during render over mirroring props into state. Prefer stable list keys from business ids. Measure with the profiler when performance is the claim.
When you cite an API, mention one failure mode: abort on unmount, serializable props across server/client boundaries, focus restoration for dialogs, or cache invalidation after a mutation. Specific beats generic every time.
Quick self-test
Explain the concept in 60 seconds, write a minimal code sample from memory, name one footgun, and point to the primary docs. If any of those fail, reread the worked example and rebuild it in a scratch file until the model sticks under interview pressure.
Edge cases worth rehearsing
Interviewers and production incidents cluster around the same edges: first render versus update, empty and loading states, Strict Mode double setup, concurrent interruptions, and what happens when identity (key, route params, user id) changes mid-edit. Walk one concrete user journey end-to-end — open, edit, navigate away, come back — and say which state survives.
Prefer fixing data flow and ownership before reaching for memoization or micro-optimizations. Prefer event handlers over effects when a user action is the trigger. Prefer deriving values during render over mirroring props into state. Prefer stable list keys from business ids. Measure with the profiler when performance is the claim.
When you cite an API, mention one failure mode: abort on unmount, serializable props across server/client boundaries, focus restoration for dialogs, or cache invalidation after a mutation. Specific beats generic every time.
Related guides
- Auth Patterns OverviewAuth in Next.js App Router: cookies/sessions, middleware gates, server checks, and avoiding client-only security theater.
- Caching in Next.js OverviewNext.js caching layers: request memoization, data cache, full route cache, and router cache — what invalidates each.
- Client Components in Next.jsClient Components in the App Router: use client, hydration, bundling boundaries, and patterns that keep JS small.
- Data Fetching Patterns App RouterFetch data in Server Components with async/await and fetch caching: colocation, parallel requests, and client fallbacks.
- Deploying Next on VercelDeploy Next.js on Vercel: git integration, env vars, previews, build cache, and production checklist.