Replies: 1 comment
-
|
this is expected behavior with PPR (partial pre-rendering). the static shell is a delivery optimization, not a computation optimization. how PPR actually worksat build time, next.js pre-renders everything outside your at request time:
so yes, this is confirmed in discussion #58322 where it's explicitly stated that the server still renders the full tree at request time, even with PPR. what PPR optimizes
the server workload is roughly the same. the difference is when the user starts seeing content. if you want to actually skip re-executionuse the // /app/parent/layout.tsx
import { cacheLife } from 'next/cache'
export default async function ParentLayout({ children }: { children: React.ReactNode }) {
'use cache'
cacheLife('hours')
console.log('this only runs on first request, then served from cache')
return <div>{children}</div>
}with the mental model
you probably want both: docs |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a simple setup below (with cache component enabled, NextJS 16.1.4)
/app/parent/layout.tsx: Simply render the children/app/parent/child/layout.tsx: Simple render the children/app/parent/child/page.tsx: render a dynamic component using fetch, which is wrapped in Suspensenext buildsucceeds.next start, hittinglocalhost:3000/parent/childwill see a fallback from Suspense and later the correct data as expected. However, I also notice that the entire route is rendered on the server at request time too. Meaning, if you are to putconsole.login each file above, you'll see them all on your server's terminal.Is this the expected behavior? For a while, I assume that only the subtree that is wrapped within Suspense would be rendered on the server at request time.
Also, I think this behavior is necessary when using React API's use to stream data from server to client, since the promise is absolutely outside of Suspense.
Beta Was this translation helpful? Give feedback.
All reactions