🫢Next.js 13 — Features, Changes and Improvements
https://medium.com/naukri-engineering/next-js-13-features-changes-and-improvements-1483831a1909
Last updated
Was this helpful?
https://medium.com/naukri-engineering/next-js-13-features-changes-and-improvements-1483831a1909
Last updated
Was this helpful?
·
Published inNaukri Engineering·5 min read·Mar 13, 2023
110
We at Naukri Engineering, use technologies that enable us to create efficient, scalable, and time-efficient tech products. As a result, we are constantly attempting to put cutting-edge industry updates to the test.
We recently moved to production with Next.js 13; the overall process was very smooth and easy, and we have seen an improvement in overall performance as well.
So, in this blog post, I’ll walk you through what’s new in Next.js 13 and how it can affect your development process based on our experience and knowledge.
I’ll also go over some of the changes made to the Next.js version 13 as well.
Next.js is a flexible React framework that gives you building blocks to create fast web applications.
Next.js v13 was released by Vercel at the Next.js conference on October 26 2022 packed with tons of new features.
Overall, the goal is to make the development process faster, easier, and more performant by improving code splitting, caching, and resource loading.
This means that your Next.js application will load and run faster, providing a better user experience..
Let’s talk about some of them in detail.
New App Directory (beta) & Router — Easier, Faster, Less client JS
Next.js 13 introduced the new App Router built on top of React Server Components with support for layouts, nested routing, loading states, error handling, and more.
I must say that using these features was a breeze and a pleasure to use. Next.js 13 now gives you the ability to control component states very easily and at a very granular level.
Component hierarchy within folder
Simplified Data Fetching — new data fetching system is built on top of the native
fetch()
We used to use special functions like getServerSideProps for real-time data and getStaticProps for cached data before Next.js 13.
Next.js 13 has removed these functions and replaced them with the fetching formats listed below:-
With cache data, Next.js will only do the actual HTTP request once, at the build time. The next time we are loading the page Next.js will reply with the initial data and will not do again the request.
When we want to run a new request for each page load we can use the no-store
value for the cache
parameter.
We can achieve a mix between Dynamic Data and Cached Data if we use the revalidate
flag:
New Rendering Strategies — Introducing Server and Client Components — JS bundle is a bit smaller — Rehydration process is quicker (fewer components to render on the client).
Each component decides whether or not to be a “server component”, or to stick with being a server and client component.
Sharing this Next Docs sketch which shows that combining server components and client components throughout the app is no problem:
To be clear, React Sever Component ( or RSC ) is a nice boost. We want our bundles to be as small as possible, and we want rehydration to happen as quickly as possible.
Toolkit Updates
Improved Next Link @next/link — simplified API without <a> inside
Now in Next.js 13, you need not to wrap link with <a>
element.
@next/image: Faster with native browser lazy loading.
Next.js 13 also features enhanced image optimization. This means that images will load faster, even on slow connections.
Font Optimization @next/font — Automatic self-hosted fonts with zero layout shift.
Does not send extra external network requests to google fonts.
Does not face a layout shift error in nextjs which is more important for SEO
There is no need to download the google fonts locally and no need for CDN links
The @next/font
package only works with Google Fonts. It does not work with other font providers. If you use any other font, you can download it locally and config with the @next/font
package.
Awesome.
Typescript by Default Next.js provides a TypeScript-first development experience for building your React application.
Server Components by Default
In Next.js 13, all components inside the app
directory are React Server Components by default allowing developers to better leverage server infrastructure.
Hooks only for Client components
useRouter
hook for programmatic redirects.
useSearchParams
hook for reading URL Search Parameters.
useSelectedLayoutSegment
hook for getting the current route segment.
useSelectedLayoutSegments
hook for getting all the child pages in the current layout segment.
usePathname
hook to read the current path name.
Special Functions for the Server Components
cookies
: Function to read cookies on the server side.
fetch
: Function to make requests on the server, it’s an extension of web fetch API.
headers
: Function to read HTTP headers on the server.
notFound
: Function to dynamically return 404 from the server.
redirect
: Function to redirect from the server.
Apart from the aforementioned features and improvements, Next.js 13 offers other features as well through the app router ; see the full documentation for a complete list.
It has the potential to be a complete Game Changer for you !!