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.