How to Use React. Hello, everyone. Thanks for joining me today. Obviously, my name is Wyatt Johnson. I'm a software engineer on the Next.js team at Vercel.
Today's talk is a deeper exploration of some of the changes that we've introduced with Next.js 16, specifically Cache Components. Cache Components is the future of the Next.js app router that combines many of the experimental features we've been developing over the last few years into a single concept. Now, with a single configuration option, you can get the rendering techniques of partial pre-rendering, the dynamic detection of Dynamic I.O., and the new caching directives, like Use Cache.
Together, these features paint a much more complete future of the app router. I actually went on stage last year at Next.js Conf to discuss partial pre-rendering and Dynamic I.O. We wanted developers to understand the reasoning behind some of the technical decisions that we made, along with providing some concrete examples of how Dynamic I.O. improved the developer experience. Just like then, today we're going to talk about how Cache Components solves many of the problems that developers face today.
When we started development of the app router, our goal was to create a new way of developing React applications that offered fast and dynamic experiences for their users. App Router took advantage of React Server Components to enable everything from co-located data loading within their components, to data mutations powered by server actions. It meant that now, instead of writing GetStatic Props or GetServerSide Props, developers could just write React.
They could query their databases inside of their components, or access request data, like cookies. Next.js used this information it collected at build time to determine if a page could be rendered statically, or if it needed to render each request dynamically. But, there was a problem with this design. As developers started to build more and more complex applications, they had to be increasingly vigilant to ensure that they didn't introduce performance regressions.
Adding a component to a page that accessed request data meant that the entire page could not be rendered statically, leaving users waiting for their page to load. We had created a mountain road without any guardrails. Small mistakes could result in big impacts to performance. We needed a way to guide developers so that their applications were still fast, without sacrificing the flexibility offered by dynamic rendering.
After years of development, literally years, we think that Cache Components has that solution. It's not just a configuration option, it's actually a new programming model, as it provides a new way for static and dynamic parts of your React applications to compose together. Under this new model, components don't just co-locate their data, they also co-locate their caching. To help developers, Next.js now provides more feedback to ensure that they're guided towards creating the best version of their applications.
Now, when a component attempts to access request-specific data, like cookies, Next.js produces a build error if that component, or its parents, is not wrapped in a suspense boundary. This ensures that applications that want to show dynamic data can still have something static to send for initial load, streaming the dynamic content in afterwards.
Comments