Upgrade to Pro — share decks privately, control downloads, hide ads and more …

TechTalk__8_-_First_look_at_Next.js_13__1_.pdf

 TechTalk__8_-_First_look_at_Next.js_13__1_.pdf

Next.js has quickly become one of the most in-demand skills in the web development space. In version 13, the experimental releases were big and took over the spotlight. This caused many people to consider the whole release unstable and experimental — but it’s not. Next.js 13 is actually quite stable and allows for a smooth upgrade from version 12 if you don’t intend to adopt any experimental API. Most changes can be incrementally adopted, which we’ll get into detail in this talk.

Marko Arsić

December 15, 2022
Tweet

More Decks by Marko Arsić

Other Decks in Programming

Transcript

  1. HypeTech Jobs Job opportunities at hype tech companies hypetechjobs.com |

    hypetech.io | reactweek.dev Marko Arsić Founder and CEO @ HypeTech Founder of HypeTech Education Lecturer @ ReactWeek.dev Independent Tech Consultant Helping companies set up teams and standardize the development process github.com/marsicdev
  2. o1 Relatively easy to learn. o2 Built-in CSS support. o3

    Automatic TypeScript support. o4 Multiple data fetching technique. o5 File-system routing.
  3. Next.js has quickly become one of the most in demand

    skills in the web development space.
  4. It may be confusing to distinguish the hype, the misinformation,

    and what’s stable for your production apps
  5. As with all Next.js releases, there are a few APIs

    that are moved into the stable core and for recommended use, and there are others still in the experimental channel.
  6. The main functionality is there, but the question of how

    these APIs behave and how they can be used is still susceptible to change as there may be bugs or unexpected side effects.
  7. In version 13, the experimental releases were big and took

    over the spotlight. This caused many people to consider the whole release unstable and experimental
  8. Stable • “New” Image Component to replace legacy Image component

    as default; • ES Module Support for next.config.mjs • “New” Link component.
  9. Next Image has been living a double life since Next.js

    12 in @next/image and @next/future/image
  10. In Next.js 13, the default component is switched: • next/image

    moves to next/legacy/image • next/future/image moves to next/image
  11. This change comes with a codemod to allow for a

    smooth migration when upgrading Next.js npx @next/codemod next-image-to-legacy-image ./pages
  12. Share configuration between configuration files and other files that may

    be used in runtime was not easy. That’s because next.config.js is written with CommonJS as the module system, which can’t import from ESM files
  13. Now Next.js supports ESM simply by adding type: "module" to

    your package.json and renaming next.config.js → next.config.mjs The “m” in “mjs” stands for “module” and is part of the Node.js spec for ESM support.
  14. For Monorepos using internal packages a special plugin was necessary

    to transpile those modules on build-time when consuming them. From Next.js 13, this can be arranged without a plugin by simply passing an (experimental) property to your next.config.mjs
  15. const nextConfig = { experimental: { transpilePackages: ['@hype/design-system'], }, };

    With these settings, it is possible to develop both the dependency component and your app simultaneously without any publishing or workaround.
  16. New routing system and router hooks (under next/navigation instead of

    next/router), and flips the entire data-fetching story
  17. app directory is powered by Server Components. Each component is

    in charge of its own data, meaning you can now fetch-then-render every component you need and cache them individually This will perform Incremental Static Regeneration (ISR) at a much more granular level.
  18. In Next.js 13 all components inside the app directory are

    React Server Components by default, including special files (tests, styles, other components, etc.) you are set up to achieve performance gains without doing any work or rewriting your components
  19. You can use Client Components by specifying a "use client"

    directive at the top of the component meant for the client.
  20. You should add "use client" directive when • using useState

    or useEffect client hooks • you depend on certain browser APIs • you want to add certain event listeners
  21. In other cases, when you don't need things from the

    client, it is best to leave components as they are and let them be rendered as Server Components by Next.js
  22. The transition from the /pages architecture to /app can be

    done incrementally. Both solutions can coexist as long as routes don’t overlap. No mention in Next.js’ roadmap about deprecating support for /pages
  23. Q & A As everything good in life, knowledge is

    great only when shared https://discord.gg/94uhCAkFKf