Urgent.News

What's breaking now, across thousands of outlets.

Tech

SVG icons in React Server Components: what ships to the client

The App Router flipped the default. Every component you write is a Server Component until something opts it out, and one 'use client' at the top of a file opts out everything below it. That makes a question worth asking before you add an icon library: does importing a single icon pull your page into a client tree? For a lot of libraries the answer is yes. Nothing breaks when it happens, the page…

When adding SVG icons to a React Server Components (RSC) setup, it’s important to consider whether the library you choose will ship additional client-side JavaScript. The presence of a `use client` directive in the library determines if it will be executed on the client or server. If the library does not contain this directive, icons can be rendered on the server as plain markup, avoiding the need for client JavaScript.

GeoIcons, for example, uses this approach and does not require a `use client` directive in its components, allowing them to be rendered on the server and reducing the amount of client-side JavaScript. To verify if a library is safe to use in an RSC context, search for the `use client` directive in the library's source code. If any files contain this directive, importing an icon from that library will trigger client-side rendering for the page.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

This story

This is one outlet's version. Read the fullest account.

Read the original at dev.to →

More in Tech

The limits page is longer than the feature list

The README for the thing I'm building puts the limits above the features. Not as a humility move. Reading them first can save you the afternoon, and a limits page that quietly rewrites its own history…

How to add country icons to a React app

Geography is a blind spot in most icon libraries. They give you arrows and carets, not the shape of Japan or the outline of the EU, and the geographic packs that exist rarely fit a modern React bundle. GeoIcons does: 799 country, area, and subdivision icons, each its own named export.

More from Monday 31 August →