Recap of Next.js 14 Announcement and 2023 Conference Highlights
Tags: nextjs, react, conference
Published: 2023-10-30 13:05:21

It’s that time of the year when React enthusiasts and Next.js fans tune into the annual Next.js Conference to hear from its creators and a team of talented engineers from both the company and the community about the latest additions to the framework and the directions it’s heading

Next.js Conf was followed by thousands of engineers online on Oct 26 and accompanied by the main event in San Francisco, as well as numerous watch parties around the world. We, as a [Next.js specialized agency](https://focusreactive.com/next-js-experts/), were right in the thick of it, soaking in the latest and greatest.

In this recap, we're bringing you the highlights, game-changing announcements, and expert insights that illuminated the event. We'll dive deep into the Next.js 14 release, exploring the newest trends and techniques that are poised to shape the future of web development.


## Let’s dive in

While the main conference theme was the focus on stability with “no new API’s” statement, there is a lot to unwrap as the key concepts that are now becoming stable, will be the foundation for future React and Next.js applications.

You can follow the full sessions in the live stream recordings on youtube: 

* [Main stage stream (Stage J)](https://www.youtube.com/watch?v=8q2q_820Sx4)
* [Stage S](https://www.youtube.com/watch?v=FdiX5rHS_0Y)

Agenda and conference page can be found [here](https://nextjs.org/conf).

_One of the fascinating facts shared in the opener, they’ve counted a whooping 850k monthly active users of Next.js. So you’re not alone on this journey!_


## Keynote by Guillermo Rauch, creator of Next.js and founder of Vercel

Important context that Guillermo emphasizes on is that Next.js strength is in it’s zero configuration concept and opinionated, yet powerful core feature set, all while it is fundamentally built on top of React (the library) own concepts that are applicable widely across different frameworks and JS apps.

The initial exposition made us feel that this presentation is the missing React keynote, rather than Next.js. And it is an important detail when it comes to React Server Components and React Server Actions which brings the React’s Component Model a big step further:

> One of my React favorite features is the ability to compose into reusable components (quote Guillermo Rauch)

Let’s first summarize the key points covered and break them down with more details below:

* Server Actions are now stable
* Announcement of partial (static) pre-rendering
* Update on Rust compiler status, [Turbopack](https://turbo.build/pack), for Next.js, that promises significant build and dev environment improvements
* Launch of new docs and learning hub - [nextjs.org/learn](https://nextjs.org/learn)

![image](https://cdn.sanity.io/images/vftxng62/production/15a2f9da6cf1662084ef581e3b148a8cb4caa383-1222x671.png?w=1000&fit=max&auto=format)

### Server Actions

React Server Actions has been earlier announced by the React core team, and just recently [landed into React Canary](https://twitter.com/reactjs/status/1716573234160967762) version. But what’s Canary in React, is Stable in Next.js. 

Next.js positions Server Actions as a stable API in its implementation, and has been highlighted as “the missing peace of the puzzle” by Guillermo through his talk.

> we were limited by the client side, but recently we got hooks and now the next step is server actions (by Guillermo Rauch)

> this required a bunch of things - new router, new data fetching system (with sophisticated caching), streaming architecture (by Guillermo Rauch)

It is one of the foundational pieces that will shape the React ecosystem going forward, and brings React’s composability concept even further, making it’s easier to share “full stack” components with encapsulated data SDK’s without requiring to accompany UI elements with own data fetching and unnecessary boilerplate code.

More on what’s expected from Server Actions covered in the following presentations.


### Partial Static Prerendering

While no new API’s announced, Next.js still packs a few underlying features that work out of the box, thanks to a sophisticated compiler that can now extract static shell for each entry points of the app, including dynamic pages.

This allows to greatly improve the loading of initial visual as fastest as you possibly can, with all placeholders rendered from a static cache, including Suspense fallbacks. Best part - it’ just works without requiring any boilerplate code.

As seen on the slide below, the initial load is instant, followed by the dynamic part of the page.


![image](https://cdn.sanity.io/images/vftxng62/production/cf840c498d9fa33d1dc92449876009e2ea0de751-1066x665.png?w=1000&fit=max&auto=format)


The ability to combine both dynamic and static in a hybrid manner was always the strongest part of Next.js compared to it’s rivals, now this feature brings the framework even further ahead in it’s ability to compile the best possible performant combination of various “chunks” sent over the wire.


![image](https://cdn.sanity.io/images/vftxng62/production/c8e2cfb49fa0ed63bba689e3f584b86ab7500a84-1204x664.png?w=1000&fit=max&auto=format)


More details about Partial Rendering in the [recap shared from a community member](https://twitter.com/0xGeegZ/status/1717599641800237170) and the [release blog post](https://nextjs.org/blog/next-14#partial-prerendering-preview).


### Turbopack

Following last year’s announcement of Rust compiler coming to replace Webpack, Guillermo shared updates on their continuous efforts of improving build and development runtime performance.

While it’s still work in progress they state that while testing on Vercel website, they’ve seen an improvement of:

* Up to 53.3% faster local server startup
* Up to 94.7% faster code updates with Fast Refresh

You can try it yourself behind the flag `next dev --turbo`, and with +90% of tests passing, it’s closer than ever to the stable release. You can follow the progress of how close is the Rust compiler to the stable release here [https://areweturboyet.com](https://areweturboyet.com)




## How Next.js is delivering React's vision for the future by Sam Selikof


In this presentation, Sam discusses the evolution of React and Next.js, introducing new features for developers that were previously either unavailable or less convenient.

The presentation kicks off with a React Single Page Application (SPA) code example and emphasizes the convenience of working with component composition, especially when leveraging hooks like useSWR.

![image](https://cdn.sanity.io/images/vftxng62/production/74c3ba36fc2bfcc5e0c9bac4c912c4b9e6c4a7ce-1600x853.jpg?w=1000&fit=max&auto=format)

If our application requires Server-Side Rendering (SSR), this approach is no longer applicable, as the data needs to be loaded on the server. Therefore, we need to utilize the getServerSideProps method.

![image](https://cdn.sanity.io/images/vftxng62/production/9d074cb1ebb3f4675dbdcaf0dbf6b701281bf1ee-1600x855.jpg?w=1000&fit=max&auto=format)

With this approach, we lose the composition that we all love in React, because we need to pass data and it's not as straightforward to insert these components anywhere.

Thanks to server-side components, now we can regain this capability and reap all the benefits of composition and SSR approach.

![image](https://cdn.sanity.io/images/vftxng62/production/9d074cb1ebb3f4675dbdcaf0dbf6b701281bf1ee-1600x855.jpg?w=1000&fit=max&auto=format)

We now have the ability to call server actions directly within the component, which makes the code more secure, convenient, and readable.

![image](https://cdn.sanity.io/images/vftxng62/production/950207100a9a30703cdbb1bdbf737b0b54be6a9c-1600x855.jpg?w=1000&fit=max&auto=format)
![image](https://cdn.sanity.io/images/vftxng62/production/e859d79741b73555ed3f125499f2e68989e7ea32-1600x855.jpg?w=1000&fit=max&auto=format)

In conclusion, Sam emphasizes that with modern tools, we not only have the capability to leverage the best aspects of existing approaches, but also to create new, unique features that were previously unavailable, treating them like ordinary UI packages from npm.

![image](https://cdn.sanity.io/images/vftxng62/production/698d26a6a5c6c2b6ddac90761b7980eb36e90a51-1600x852.jpg?w=1000&fit=max&auto=format)


## Optimizing Third-Party Loading in Next.js by Houssein Djerdeh


For several years now, Houssein and his team have been working in collaboration with Next.js. Through collective efforts, they have introduced tools such as `next/image`, `next/script`, and `next/font`, which are used in the majority of Next.js projects.

![image](https://cdn.sanity.io/images/vftxng62/production/c1d859f43cb7c43c1247a1a9d16536c7cd39d56f-1600x852.jpg?w=1000&fit=max&auto=format)

He addresses the issue of third-party dependencies, which are commonly used in most internet resources, as they have a significant impact on the overall performance of the resources. Here are a few examples of metrics dependencies on the amount of resources added to a project.

![image](https://cdn.sanity.io/images/vftxng62/production/8abe8c360a77491ff06449d1da7f1ec12c9f659c-1600x853.jpg?w=1000&fit=max&auto=format)

Incorporating such third-party resources can be made more efficient by utilizing the `next/script` component, as it encompasses a range of optimizations and tools, such as "strategy"' which greatly aids in optimizing the loading of these scripts.

![image](https://cdn.sanity.io/images/vftxng62/production/8d433ee2e485993be52f8900d9491ec4873d54da-1600x850.jpg?w=1000&fit=max&auto=format)

The only bottleneck with this approach is that it's not always clear how to precisely employ `next/script` with a specific third-party resource. Which strategy is best to choose? Where should the script itself be added?

To address this issue, Houssein and his team are working on the `@next/third-parties` library, which is currently in active development. They conduct their own performance research to ensure you get the best outcome. Consequently, adding, for example, Google Tag Manager can become incredibly straightforward, while also giving you confidence that this method of integration is the most effective and optimized.

![image](https://cdn.sanity.io/images/vftxng62/production/dd39cecc2ca89b6eaf95bb0afa8bd2f7fa0efecf-1600x857.jpg?w=1000&fit=max&auto=format)


## The Big Headless CMS Lie by James Mikrut

James gave a talk from the perspective of the founder of Payload, an Open Source Headless CMS platform. We found this topic to be especially close to us, as we specialize on a variety of different Headless CMS and[ consulted multiple clients](https://focusreactive.com/headless-cms-agency/) on the subject.

Building with Headless CMS was always a more complex technical process compared to traditional options Like Wordpress, trading convenience of complete system of tightly knit modules (like in Wordpress) for a full bespoke flexibility of Headless-first solutions, at a cost of development time and budget. The talk starts with a fair criticism of excuses developers and agencies made to convince their clients going for Headless, while pointing that the main goal was mostly about using Next.js as a decoupled frontend.


![image](https://cdn.sanity.io/images/vftxng62/production/c8e2cfb49fa0ed63bba689e3f584b86ab7500a84-1204x664.png?w=1000&fit=max&auto=format)


The story continued with some examples of how it would be more convenient for some Headless-first vendors, including themselves at Payload, to move back to more monolithic frameworks like Next.js.

It is true that at this level of performance and sophistication of web development, it makes sense to get back to the roots and centralize around frameworks, instead of rebuilding the same thing again. But the main idea is that the current iteration of Next.js enables best of both worlds - convenience of the framework and flexibility that would even allow running it as a pure Backend even for those who don’t want to have a client-facing Next.js app.

After going through some specific examples, that we won’t cover in this recap, the conclusions made were about the possibilities that React Server Components and Server Actions unlock, that would allow various vendors to build more solutions on top of Next.js not around it.


![image](https://cdn.sanity.io/images/vftxng62/production/775269b8d4f6ca76109dcab9667f057b480dee75-1375x618.png?w=1000&fit=max&auto=format)



## Performance in React and Next.js by Lydia Hallie

During the presentation, Lydia speaks about the concurrent features that have been introduced in React 18 and how NextJS leverages these features to provide better performance out of the box.

In this demo we have a very long list of cities which is being rerendered on each keystroke and since we have a lot of expensive calculations, the performance is suffering.

![image](https://cdn.sanity.io/images/vftxng62/production/4a2d141e111eca91fcf6f151d27cdc8a4437fba9-1600x767.jpg?w=1000&fit=max&auto=format)

We could use debounce libraries to resolve this, but no solution was built in React itself so far.\
React 18 introduces concurrent features which allow us to mark components as low priority to improve performance. While rendering such components React will yield to the main thread every 5ms to ensure that there are no more important tasks to execute.

For example, we can mark a state change as a low priority with useTransition. Then React will interrupt the render caused by this change if some more important interaction comes along.

![image](https://cdn.sanity.io/images/vftxng62/production/a619da3a7fceac0a7a1351570962831d6b9a27a8-1402x759.jpg?w=1000&fit=max&auto=format)

This demo uses Transition. The performance metrics got much better.

![image](https://cdn.sanity.io/images/vftxng62/production/e084afb93cfa29d908208151fced78646da46836-1600x780.jpg?w=1000&fit=max&auto=format)

Another way to manage components priority is to use Suspense boundary as it is always treated as low priority.

With SSR we are able to send one request for the page with all data in it, so there is no need to wait until the JS code is loaded and run the data request.

Besides rendering updates, React introduces new ways to memoize data or data fetching results. To do this we can either use the new cache function or the enhanced fetch API.

The new fetch API usage example:
![image](https://cdn.sanity.io/images/vftxng62/production/623f8a09519dd55ed4d6c23f3b8373daa228bac7-1600x747.jpg?w=1000&fit=max&auto=format)

In this case, React will store the results in an in-memory cache and reuse these results if some other component requires the same data.

### NextJS new features

NextJS prerenders the components that do not require request-based data at the build time. For the components that do require request-based data, we can create an implicit Suspense boundary just by adding a loading.js file. Its exported value will be used as the fallback. 

![image](https://cdn.sanity.io/images/vftxng62/production/d8e3a2f11756189e4b56f41d952e45b72c693969-1308x911.jpg?w=1000&fit=max&auto=format)

Also, NextJS introduces Partial prerendering. Up until now we could have either entirely static routes or pages rendered entirely dynamically. There was no way to give this dynamism to the child components of static routes. And Partial prerendering makes it possible. So it prerenders all the components outside of the Suspense boundary which contains the dynamic component statically and very quickly, and then, it renders the dynamic component as soon as it becomes ready.

## Unlocking Composable Content with the App Router by Kapehe and Grant Sander


Kapehe and Grant delve into their experiences and best practices using the `next-sanity` package inside the Next.js App Router and major challenges faced during the migration.

Grant mentioned that most of the challenges with migration to Next.js 13 were due to incompatibilities with some open-source libraries. Many of them were initially incompatible with React Server components, presenting a tricky migration path. However, with the help of the community, many early issues had been solved.

With the `next-sanity` package, developers can now embed the Sanity Studio directly into their Next.js applications. Grant described the simplicity of this integration, stating that it makes it easier for both developers and content editors. Now, they don't need separate repositories for the studio and frontend, streamlining the development and deployment process.

![image](https://cdn.sanity.io/images/vftxng62/production/2c91cc606f2cd78f09ef9e4c3f13f9c044f1099f-1600x852.jpg?w=1000&fit=max&auto=format)

Using Next.js Revalidate Tag, he showed how to revalidate Sanity data at the component level and explained how caching and revalidation work in tandem.

![image](https://cdn.sanity.io/images/vftxng62/production/89acadb57ab63cc030249f3072e080874fdf47e5-1600x853.jpg?w=1000&fit=max&auto=format)

`next-sanity` library simplifies many of these caching and invalidation processes. It provides functionalities like tagging fetch requests, handling security with payload validation, and abstracting the cache invalidation logic, making it much more streamlined for developers.

![image](https://cdn.sanity.io/images/vftxng62/production/dc7f40c1216f68a6e20f2804fd9d1df08382db79-1600x855.jpg?w=1000&fit=max&auto=format)

Grant explained the benefits of on-demand revalidation and shared implementation details. When content editors make changes in the Sanity Studio, webhooks are set up to ensure the updated content is immediately available on the website.

![image](https://cdn.sanity.io/images/vftxng62/production/f2d7c932b10d3cd8e0f0daa987ad4db0e7d7fcd3-1600x855.jpg?w=1000&fit=max&auto=format)



## The things Vercel won't show you by Theo 


Theo talks through the unique patterns, that are not typically recommended and could be problematic, but still, might be useful for the specific use cases.

Patterns are sorted in a specific order, from totally viable ones to the most cursed.

###  Pagination via server actions

![image](https://cdn.sanity.io/images/vftxng62/production/a61a1c3f741d10e181078e828265398ab0424ab2-1139x538.jpg?w=1000&fit=max&auto=format)

The first example is a simple next js app with the pagination `DataView` component. `DataView` takes initialData prop. The value provided to the `initialData` prop is a server action function call, that returns the pagination array as a result.

![image](https://cdn.sanity.io/images/vftxng62/production/f8a01da31541b5781db9f7cc19ab02210a5ecd34-1600x856.jpg?w=1000&fit=max&auto=format)
![image](https://cdn.sanity.io/images/vftxng62/production/2215fb9766eb670fef547fa2fa4d2480480138ed-407x107.jpg?w=1000&fit=max&auto=format)

The `DataView` component is a client component, that has a state, to store data after loading, and loadMore handler, that loads new data. Because of the provided initial data, the pagination UI is ready on the server. This prevents us from unpleasant layout shifts.

Server action can be called anywhere on the client, because it is effectively compiledinto into a rpc call. In addition to that, it's type-safe.

###  globalThis as an SSR helper

This pattern helps you to pass server context to the client, without directly passing the prop

The demo shows a page server component with fetched data, `GlobalThisEmbedder`, and a Client component. 

![image](https://cdn.sanity.io/images/vftxng62/production/ec31c6967a67ff17918f0a8724a5ec6c8c014c52-1600x852.jpg?w=1000&fit=max&auto=format)

Client component takes the data from globalThis, and render it on the client.

![image](https://lh7-us.googleusercontent.com/mr-YO1Y4C9epC_LCPPumA3Vwv8q53aG-dYMh5Y6DRG6Rwh4TKKl4cAhurJie3leETezxC0k1UB61bweyfONu43jcSI5fa6fNZgROIE3JVK4TmRIkEP8JUyLbo0MEI4tMtJkubW6myeakPnQdPIkxP_c?w=1000&fit=max&auto=format)

`GlobalThisEmbedder takes server fetched data as a props and set it to both server and client globalThisContexts. Fairly easy in case of server context: simply assigning prop value to the globalThis. A bit tricky for a client context: inside useServerInsertedHTML hook declare a script, that takes stringified server content (same as with server context, but with stringified value) data and return script tag with dangerously set inner html props equal to declared stringified script value. 

`useServerInsertedHTML` ensure code will be run on server even tho used in the client component.

![image](https://cdn.sanity.io/images/vftxng62/production/0c1af38f93125e1ce70ace2033f4d7913653614f-1600x891.jpg?w=1000&fit=max&auto=format)

Most of the time you will never need something like this, but if you do it's incredibly helpful.

###  function*  for streaming component updates

This pattern is exclicitelly not recomended by vercel team.

Demo shows how to stream updates to the component, using generator functions.

![image](https://cdn.sanity.io/images/vftxng62/production/739a924b49200246889a717a6b9e0450460bdcb8-1600x890.jpg?w=1000&fit=max&auto=format)

How does it work?

![image](https://cdn.sanity.io/images/vftxng62/production/c9dd2f772243a378eccbb0ff086ee9551f0143a6-1600x869.jpg?w=1000&fit=max&auto=format)

Generator component takes previous results and uses it as a fallback for Suspense. Then calls itself recursively with the generator, using values that are being yielded. In addition to that it doesn't resolve suspense until the last value inside generator is reached.

The use case for this could be a component, that fetches multiple different states on the server during one fetch, this could be useful.

This article has been also posted to our FocusReactive blog, [follow for more content on Next.js, Performance and Headless CMS](https://focusreactive.com/blog/).