Difference between partial rendering(PPR) and the current streaming suspense? #58322
-
next.js 14 introduces new partial prerendering(PPR) feature. what's the difference with the current streaming and suspense? https://nextjs.org/docs/app/building-your-application/routing/loading-ui-and-streaming |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
The Partial Rendering, is, what I think Suspense, should've been all along... It applies at build time, and what it does is, pre-render everything that's not bounded by a Suspense tag. That means that these parts are effectively part of the HTML, just like
So for example, as an extreme simplification, you could pre-render various parts of a user dashboard, and then the React Server makes sure to place the user data where the Suspense boundaries were, whereas, before you'd need to defer rendering anything in the user dashboard, to on-demand rendering, ala Another example, a blog post, with a views counter. You'd need to either, render the blog post on demand, or pre-render it, and carve out an area where you'd use |
Beta Was this translation helpful? Give feedback.
-
PPR lets you render the entire page at build time, with the exception of Suspense wrapped components (likely other exceptions, but specific to this question that's the difference). With streaming/suspense, you render the entire page on request. Suspense lets you fetch data in parallel, and streaming lets you replace the suspense component with the fully rendered bits as each of them finish. But everything is done on request time. With PPR, you render part of the page at build time and part of it at request. Anything that can be rendered at build time, is rendered at build time. Everything else should be wrapped in Suspense (with a fallback to prevent jarring CSS behavior). So instead of needing to render the entire page (the current setup) or generate the entire page at build time (static pages), you can generate a "partial first page" at build time and render out the parts that are dynamic while the server sends that static page. Everything about the app that doesn't change gets to the user fast. This effectively gets the first paint more quickly, which feels faster even if the actual/real improvements in speed are negligible in some particular app. The user who sees things happening in 100ms increments is usually happier than the one waiting 700ms for something to happen, even if they both waited a total of 700ms. |
Beta Was this translation helpful? Give feedback.
-
While @Connor-Skudlarek 's answer is correct, I'm just going to describe what I understood about the PPR. Without PPR, there are only 2 options to render the entire page:
As mentioned here and here, Next.js uses static rendering by default and switch to dynamic rendering if any dynamic function or uncached data request is discovered during rendering or if the route or page is configured to force dynamic rendering. Streaming is a technique to progressively render UI and only works for dynamic rendering. PPR is a new concept that gives us a 3rd option to render the entire page by combining static rendering and dynamic rendering, which means part of the page is rendered at build time for a fast initial load, while the remaining part is rendered dynamically at request time with streaming. So I think they are different concepts but look similar because both of them use React's Suspense. |
Beta Was this translation helpful? Give feedback.
PPR lets you render the entire page at build time, with the exception of Suspense wrapped components (likely other exceptions, but specific to this question that's the difference).
With streaming/suspense, you render the entire page on request. Suspense lets you fetch data in parallel, and streaming lets you replace the suspense component with the fully rendered bits as each of them finish. But everything is done on request time.
With PPR, you render part of the page at build time and part of it at request. Anything that can be rendered at build time, is rendered at build time. Everything else should be wrapped in Suspense (with a fallback to prevent jarring CSS behavior).
So instead of n…