How SVG icon libraries can silently add client JavaScript to Next.js Server Components
With Next.js App Router, every component defaults to a Server Component unless a 'use client' directive opts it out, meaning icon libraries that include this directive can unintentionally push entire page trees to the client. A developer guide explains that importing from such libraries ships unnecessary JavaScript to browsers even for purely static SVG drawings. Libraries like GeoIcons avoid this by omitting the 'use client' directive from their icon modules, allowing icons to render server-side and arrive as plain HTML markup. Developers can verify any icon library's behavior by running a grep search for the directive within installed package files. Confirming the result in built client chunks ensures no icon path data is bundled into client-side JavaScript.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in