Autocoder

Next.js Interview Questions and Answers (Next.js 15)

Last updated 2026-11-19

Next.js interviews now centre on the App Router: which components run where, how data is fetched and cached, and how mutations flow through Server Actions. Next.js 15 changed several defaults that older answers get wrong, notably caching of fetch requests and the shift of request APIs such as cookies, headers and params to asynchronous access. Knowing these specifics shows you work on the current version.

The App Router is built on React 19 features, so read the React interview questions for Server Components and Actions in general. For a wider view of how rendering strategies fit in a product, see the full stack developer questions.

Version coveredNext.js 15 with the App Router and React 19
Core topicsRendering, caching, Server Actions, routing, middleware, performance
Questions here18

Defaults that changed in Next.js 15

How to answer rendering questions

Explain rendering per route, not per app. A route is static if it uses no dynamic APIs and its data can be resolved at build time, and dynamic if it reads cookies, headers, search params or uncached data. Name the trade-off: static pages are fastest and cheapest, dynamic pages are fresh and personalised. Then mention streaming with Suspense as the way to send the shell early.

Next.js Interview Questions and Answers (Next.js 15): questions with worked answers

  1. 1

    What is the difference between the App Router and the Pages Router?

    easy

    The Pages Router maps files in pages to routes and uses getServerSideProps and getStaticProps for data. The App Router uses the app directory with nested layouts, Server Components by default, loading and error files, streaming and Server Actions. It is the recommended approach for new projects. Both can coexist during a migration, but the same route cannot exist in both.

  2. 2

    What are the special files in the App Router?

    easy

    page.tsx makes a route public, layout.tsx wraps pages and persists across navigation, loading.tsx shows a Suspense fallback, error.tsx is a client error boundary for the segment, not-found.tsx handles notFound(), route.ts defines an API handler and template.tsx re-mounts on navigation. Folders in brackets, such as [slug], create dynamic segments, and folders in parentheses group routes without affecting the URL.

  3. 3

    Server Components versus Client Components?

    medium

    Components in the app directory are Server Components by default: they render on the server, can read data directly and add no JavaScript to the client bundle, but cannot use state, effects or browser APIs. A file starting with "use client" marks a boundary, and the components it imports run on the client. Push the boundary down, keeping interactive leaves as client components and fetching in server parents. Props crossing the boundary must be serialisable.

    typescript
    // app/products/page.tsx (Server Component)
    export default async function Page() {
      const products = await db.product.findMany();
      return <ProductList products={products} />;
    }
    // ProductList.tsx has "use client" only if it needs state or handlers
  4. 4

    How do async request APIs work in Next.js 15?

    medium

    In Next.js 15, params and searchParams are promises, and cookies(), headers() and draftMode() return promises, so you await them in async components. This lets Next.js start rendering before the request data is needed. Synchronous access still works temporarily with a warning, and the next-async-request-api codemod migrates code. Client components read params with the use hook or useParams.

    typescript
    export default async function Page({ params }: { params: Promise<{ slug: string }> }) {
      const { slug } = await params;
      const theme = (await cookies()).get('theme')?.value;
      return <Post slug={slug} theme={theme} />;
    }
  5. 5

    How does data caching work in Next.js 15?

    medium

    Since 15, fetch is not cached by default, so each request fetches fresh data unless you set cache: "force-cache" or next: { revalidate: seconds } on the call. Static pages are still cached at build time when everything resolves statically. For data that does not use fetch, wrap the function in unstable_cache or use the use cache directive in versions where it is enabled. Revalidate on demand with tags.

    typescript
    const res = await fetch('https://api.example.com/posts', {
      next: { revalidate: 3600, tags: ['posts'] },
    });
  6. 6

    What are Server Actions and how do you secure them?

    medium

    A Server Action is an async function marked "use server" that runs on the server and can be passed to a form action or called from client code. Next.js exposes each as a POST endpoint, so treat every one like a public API: authenticate and authorise inside it, validate arguments with a schema, and never trust values from the client. After mutating, call revalidatePath or revalidateTag, or redirect.

    typescript
    'use server';
    import { revalidatePath } from 'next/cache';
    
    export async function addTodo(formData: FormData) {
      const session = await auth();
      if (!session) throw new Error('unauthorised');
      const title = z.string().min(1).max(200).parse(formData.get('title'));
      await db.todo.create({ data: { title, userId: session.userId } });
      revalidatePath('/todos');
    }
  7. 7

    Explain revalidatePath and revalidateTag.

    medium

    They invalidate cached data on demand after a mutation. revalidatePath("/blog") marks that route's cached output stale, so the next request regenerates it. revalidateTag("posts") invalidates every fetch tagged with posts, across routes. Tags are more precise for shared data. Time-based revalidate is the fallback for data that changes on a schedule.

  8. 8

    How do static and dynamic rendering differ, and what makes a route dynamic?

    medium

    A static route is rendered at build time and served from cache or a CDN. A route becomes dynamic when it uses a dynamic API such as cookies, headers or searchParams, performs an uncached fetch in a way that needs request time, or exports dynamic = "force-dynamic". For dynamic params, generateStaticParams pre-renders known values, and dynamicParams controls what happens to others.

    typescript
    export async function generateStaticParams() {
      const posts = await getPosts();
      return posts.map((p) => ({ slug: p.slug }));
    }
  9. 9

    How does streaming with Suspense and loading.tsx work?

    medium

    Next.js can send the layout and static parts immediately and stream slow parts as they resolve. loading.tsx wraps the page in a Suspense boundary automatically, and you can add finer boundaries around individual slow components so the rest of the page is not blocked. This improves perceived performance and Largest Contentful Paint without client-side fetching.

  10. 10

    What does middleware do and what are its limits?

    medium

    middleware.ts runs before a request is completed, on every matched route, so it suits redirects, rewrites, header changes, locale detection and simple auth checks on a cookie. It runs on the Edge runtime by default, so many Node.js APIs and heavy libraries are unavailable. Use a matcher to limit it. Do not rely on middleware alone for authorisation, and check permissions again close to the data. Next.js 15.2 added experimental Node.js runtime support for middleware.

    typescript
    export function middleware(req: NextRequest) {
      if (!req.cookies.get('session')) {
        return NextResponse.redirect(new URL('/login', req.url));
      }
    }
    export const config = { matcher: ['/dashboard/:path*'] };
  11. 11

    How do Route Handlers work?

    medium

    A route.ts file exports functions named after HTTP methods, such as GET and POST, taking a Request and returning a Response. In Next.js 15 GET handlers are not cached by default. They suit webhooks and endpoints for third-party clients, whereas internal mutations are usually better as Server Actions. The dynamic route parameters are passed as a promise.

    typescript
    export async function GET(req: Request, { params }: { params: Promise<{ id: string }> }) {
      const { id } = await params;
      const item = await db.item.findUnique({ where: { id } });
      return item ? Response.json(item) : new Response('Not found', { status: 404 });
    }
  12. 12

    How does next/image improve performance?

    medium

    It serves resized, modern-format images such as WebP or AVIF, generates a srcset, lazy loads by default, and reserves space through required width and height or fill, which prevents layout shift. Use the priority prop for the Largest Contentful Paint image. Remote images must be allowed in images.remotePatterns. See web performance interview questions.

  13. 13

    How are metadata and SEO handled in the App Router?

    hard

    Export a static metadata object or an async generateMetadata function from a layout or page to set title, description, Open Graph and canonical URLs, and the data fetched there is deduplicated with the page. File conventions such as sitemap.ts, robots.ts and opengraph-image generate those assets. Server rendering means crawlers receive full HTML.

  14. 14

    What are parallel and intercepting routes?

    hard

    Parallel routes use folders named with an at sign, such as @modal, to render several pages in one layout at once, each with its own loading and error states. Intercepting routes, with the (.) prefix conventions, show another route inside the current layout on client navigation, for example opening a photo in a modal while a direct visit shows the full page. Together they implement modal patterns with shareable URLs.

  15. 15

    What is the client Router Cache and how did it change in Next.js 15?

    hard

    The Router Cache stores visited route segments in the browser to make back and forward navigation instant. In Next.js 14 pages were kept for 30 seconds for dynamic routes and five minutes for static ones. In 15, page segments are not reused by default, because staleTime for pages is zero, though layouts and loading states are still shared and back and forward navigation restores scroll. You can opt in with experimental.staleTimes.

  16. 16

    How do you deploy and what are the runtime options?

    hard

    You can deploy to Vercel, or self-host with next start on Node.js or a Docker image using output: "standalone". Static export with output: "export" produces plain files, but drops server features such as Server Actions and dynamic routes without generateStaticParams. Route segments can choose the Node.js or Edge runtime. Configure environment variables per environment, and remember only NEXT_PUBLIC_ variables are exposed to the browser.

  17. 17

    How do you handle authentication in the App Router?

    hard

    Use a library such as Auth.js or a provider SDK, store a session in an HttpOnly cookie and verify it on the server. Check the session in Server Components and Server Actions, close to the data access, rather than only in middleware. Use a data access layer function that returns the current user or throws. Avoid passing secrets to Client Components and protect against CSRF, which Server Actions mitigate by comparing the Origin header.

Frequently asked questions

Do I need the Pages Router for interviews?

Know the basics, since many existing apps use it, but prepare mainly for the App Router, which is the recommended approach.

What is the biggest Next.js 15 change to mention?

Caching defaults: fetch and GET route handlers are not cached by default, and request APIs such as cookies and params became asynchronous.

Is Next.js a frontend or full stack framework?

Both. It renders React on the server and also provides route handlers, Server Actions and middleware, so it can serve as a full stack framework.

How is Next.js different from plain React?

React is a UI library. Next.js adds routing, server rendering, data fetching, bundling and deployment conventions on top of it.

Related guides

More in Role-wise Interview Questions by Job and Tech Stack

See all in this section