I have a Next.js app (v14.1.2
) which uses the app router.
One of my pages uses a dynamic route:
./src/app/c/[id]/page.tsx
This page
- Is a client component with
"use client";
- Does not use any dynamic functions.
- Does use
{params}
to get ‘id’ from the route but the value is only referenced inside a client-onlyuseEffect(...)
callback (all data-fetching is client-side).
As a result, the server should be able to send identical data to the client on each request because all data fetching is done in client components. However, I noticed in the output of next build
that the page is rendered dynamically (even with export const dynamic = 'error';
)
Route (app) Size First Load JS
┌ ○ / 2.36 kB 97.4 kB
├ ○ /_not-found 882 B 85.2 kB
├ λ /c/[id] 3.03 kB 98 kB
...
○ (Static) prerendered as static content
λ (Dynamic) server-rendered on demand using Node.js
It seems pretty wasteful to re-render static content on each request. When the payload will be the same on each render is it possible to opt in to static rendering of a dynamic route? What about static routes that use query parameters in client components?
Bonus points for references to the Next.js documentation that explain the intersection of static/dynamic rendering with static/dynamic routes.