Why does the root layout.tsx server render on every request? #81337
Replies: 1 comment 1 reply
-
Great question! This behavior is expected and relates to how the In the App Router architecture, the Even if your page is static (SSG), Next.js still needs to wrap that static content in a dynamically rendered document structure. This ensures proper support for per-request features, like internationalization, headers, middleware rewrites, and more. In contrast, nested layouts that don’t participate in the full document structure can often be cached or pre-rendered and reused without server-rendering every time. Key points:
Hope this helps clarify the behavior! 😊 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I am trying to learn as much as possible on how Next.js app router works (ISR, SSR, SSG, PPR etc.) and I stumbled upon an unintuitive behavior - the root layout.tsx (only the root one) renders on the server with every request, even when everything else (and the layout's contents) are static (SSG).
I tested it out with the create-next-app (with Next.js 15.3.4) and even stripped down the
layout.tsx
to be as barebones as possible:Now when I run
npm run build
andnpm run start
, with every reload,RootLayout
is printed out into the console, meaning the root layout is server rendered with every request. This is not the case with nested layouts, which run only during the build phase and do not server render.Why is that? And shouldn't this fact be explained a bit more in the docs? Putting heavier computation into the
layout.tsx
, expecting to happen only once during build, would lead to degraded performance, since it would be re-computed with every request.Thanks a lot for the clarification! 🙏
Beta Was this translation helpful? Give feedback.
All reactions