LearnFrenzy
Sign in Take a free test

Next.js Interview Prep · Lesson 24 of 24

Next.js Interview Questions

8 min read Updated Nov 8, 2026 Saurabh Samir

Next.js interviews have changed with the App Router: questions about getServerSideProps have given way to Server Components, streaming, caching and Server Actions. This lesson collects the questions frontend and full-stack candidates are asked most, with short answers you can explain in your own words – and pointers to the lessons that cover each topic in depth.

In this lesson

  • Fundamentals and routing
  • Rendering and Server Components
  • Data, caching and mutations
  • Performance, SEO, security and deployment

Fundamentals and routing

1. What is Next.js, and how is it different from React?

React is a UI library; Next.js is a full-stack framework built on it. It adds file-based routing, server rendering and prerendering, Server Components, data fetching and caching, Server Actions and Route Handlers, image/font optimisation and SEO metadata.

2. App Router vs Pages Router?

The App Router (app/) uses React Server Components, nested layouts, streaming, and Server Actions; data is fetched in async components. The Pages Router (pages/) uses getServerSideProps/getStaticProps and client-side React. New projects should use the App Router; both can coexist during a migration.

3. How does routing work in the App Router?

Folders are URL segments; page.tsx makes a segment routable; layout.tsx wraps it; [slug] creates dynamic segments, [...slug] catch-alls, (group) route groups and _folder private folders. Special files: loading, error, not-found, route, template.

4. Layout vs template?

A layout stays mounted across navigations between its pages and keeps state; a template remounts on every navigation. Layouts can't read searchParams.

Rendering and Server Components

5. What are Server Components?

Components that run only on the server (at build or request time). They can be async, access databases and secrets, and ship no JavaScript. They can't use state, effects, event handlers or browser APIs. They're the default in app/.

6. When do you use "use client"?

For interactivity: state, effects, event handlers, browser APIs, context, or client-only libraries. It marks a boundary – the file and its imports go to the browser – so keep it as low in the tree as possible and pass server content in as children.

7. Are Client Components rendered on the server?

Yes, for the initial HTML; then they hydrate in the browser. That's why reading secrets in a client file is dangerous – the value can end up in the server-rendered HTML.

8. Static, dynamic and Partial Prerendering – which route is which?

// app/about/page.tsx
export default function About() {
  return <h1>About us</h1>;                          // no data
}
// app/catalog/page.tsx
import { cacheLife } from "next/cache";

async function getCatalog() {
  "use cache";
  cacheLife("days");
  return ["React.js", "Next.js"];
}

export default async function Catalog() {
  return <ul>{(await getCatalog()).map((c) => <li key={c}>{c}</li>)}</ul>;   // cached data
}
// app/cart/page.tsx
import { Suspense } from "react";
import { cookies } from "next/headers";

async function CartCount() {
  const items = (await cookies()).get("cart")?.value?.split(",").length ?? 0;   // request data
  return <p>{items} items in your cart</p>;
}

export default function Cart() {
  return (
    <main>
      <h1>Your cart</h1>
      <Suspense fallback={<p>Loading cart…</p>}>
        <CartCount />
      </Suspense>
    </main>
  );
}
// app/api/time/route.ts
import { connection } from "next/server";

export async function GET() {
  await connection();
  return Response.json({ now: Date.now() });        // must run per request
}

next build

Route (app)      Revalidate  Expire
├ ○ /about
├ ƒ /api/time
├ ◐ /cart
└ ○ /catalog             1d      1w


○  (Static)             prerendered as static content
◐  (Partial Prerender)  prerendered as static HTML with dynamic server-streamed content
ƒ  (Dynamic)            server-rendered on demand

/about has no data and /catalog only cached data, so both are static. /cart reads cookies inside Suspense, so it's partially prerendered: a static shell with a dynamic hole. The API route must run per request, so it's dynamic (ƒ). Being able to predict this table is a strong interview signal.

9. What is streaming, and how does Suspense relate to it?

Next.js sends the parts of the page that are ready and streams slower parts into the same response as they resolve. Each <Suspense> boundary (or loading.tsx) marks a part that can stream with a fallback.

10. What is hydration, and what causes a hydration mismatch?

Hydration is React attaching event handlers to server-rendered HTML. A mismatch happens when the first client render differs from the server HTML – for example Date.now(), Math.random(), window checks or locale-dependent formatting during render. Fix it by rendering such values in an effect, on the server only, or with suppressHydrationWarning for unavoidable cases like timestamps.

Data, caching and mutations

11. How do you fetch data in the App Router?

With await in async Server Components – fetch, an ORM, or any server code. Start independent requests in parallel (Promise.all), deduplicate per request with React cache, and put request-time data inside Suspense.

12. How does caching work in Next.js 16?

With Cache Components, nothing is cached implicitly. Mark functions or components with "use cache", set a lifetime with cacheLife, label them with cacheTag, and invalidate with updateTag (immediate, in Server Actions), revalidateTag(tag, "max") (stale-while-revalidate) or revalidatePath. Cached and static content form the prerendered shell; request data streams in.

13. What are Server Actions, and how are they secured?

Async functions marked "use server", callable from forms and Client Components; Next.js turns calls into POST requests. They're public endpoints, so every action must authenticate, authorise and validate its input. Next.js adds encrypted action IDs, origin checks and body-size limits.

14. Server Actions or Route Handlers?

Actions for mutations from your own UI; Route Handlers (route.ts) for public APIs, webhooks, mobile clients and non-HTML responses. Don't fetch your own Route Handlers from Server Components – call the data function directly.

15. What is Proxy (formerly Middleware) used for?

Code in proxy.ts that runs before matched requests: redirects, rewrites, headers, cookies, locale detection, A/B buckets and optimistic auth redirects. Keep it fast and never rely on it as the only security check.

Performance, SEO, security and deployment

16. How does Next.js help with SEO?

Server-rendered or prerendered HTML, the Metadata API (metadata, generateMetadata, title templates, canonical URLs, Open Graph), sitemap.ts, robots.ts, generated OG images, and fast Core Web Vitals via next/image and next/font.

17. What does next/image do?

Prevents layout shift (width/height or fill), lazy-loads by default, generates responsive srcsets, converts to modern formats through the image optimiser, and supports blur placeholders. Mark the LCP image with loading="eager" and fetchPriority="high" (or preload).

18. How do you keep secrets safe?

Use them only in server code, mark such modules with import "server-only", never prefix them with NEXT_PUBLIC_, keep them in .env.local or the host's settings, and return only the data the UI needs.

19. How would you protect a dashboard?

A signed, httpOnly session cookie created in a login Server Action; a server-only data access layer with a cached verifySession() used by pages, actions and route handlers; optionally a Proxy redirect for logged-out users. Or an auth library such as Auth.js, Better Auth or Clerk.

20. How can you deploy a Next.js app?

Vercel (zero-config), any Node.js server with next start, Docker with output: "standalone", or a static export with output: "export" when no server features are needed.

How to stand out

  • Explain where code runs (server, client, build, request) – most Next.js questions reduce to that.
  • Know what changed in Next.js 15–16: async params, Cache Components and "use cache", Proxy, updateTag, Turbopack by default.
  • Mention trade-offs: static vs dynamic, Actions vs Route Handlers, Context vs a store, Vercel vs self-hosting.

Practise further with our Next.js interview question sets and React interview questions, and revisit the React course for hooks and state.

Practice

Try it yourself

  1. An interviewer shows a page that reads searchParams at the top of the page component, outside any Suspense boundary. What happens at build time, and what are your three options?

    Show answer

    With Cache Components, next build fails with "uncached or runtime data during prerendering". Options: wrap the part that reads it in <Suspense> (stream it), cache the data with "use cache" where possible (passing values as arguments), or deliberately allow a blocking route with export const instant = false.

  2. Why might a deleted product still appear on the product list after a Server Action removes it?

    Show answer

    The list is cached ("use cache") and the action didn't invalidate it. Call updateTag("products") (or revalidatePath) after the delete.

Quick check

What does ◐ mean in the build output?

Partial Prerender: a static shell with dynamic parts streamed in.

Is params a plain object in Next.js 16 pages?

No – it's a Promise; await it.

What replaced middleware.ts in Next.js 16?

proxy.ts.

Summary

  • Be fluent in the App Router: file conventions, layouts, Server vs Client Components.
  • Explain rendering (static, dynamic, Partial Prerendering, streaming) and Next.js 16 caching.
  • Cover mutations, security, SEO, performance and deployment with concrete examples.

Finished this lesson?

Mark it complete to track your progress. You have reached the end of this track — well done!

Search LearnFrenzy

Esc

Quick links