Server-side rendering

The components render on the server and hydrate in the browser without a mismatch: Angular SSR, prerendered or per request, works as it is. The user's choices — theme, sidebar, language — are cookies, so the server draws the page as they left it.

Nothing to set up

Add Angular's SSR to your app as usual (ng add @angular/ssr); the library needs nothing more. No part touches a browser global — window, document, localStorage, matchMedia, observers, sizes — as it is created: those wait for the browser (after the first render, in an event), so the server renders every part and its markup, and the browser takes it over.

The same page on both sides

Hydration keeps the server's HTML, so what changes classes or markup must be known to the server too. The choices the library keeps — the mode and the theme, the sidebar open or closed, the language — are cookies (with a localStorage copy for where cookies aren't kept), read from the request on the server: a dark page is drawn dark from the first paint, with no flash. Keep your own choices the same way.

import { ScStorage } from '@semantic-components/ui';
const storage = inject(ScStorage);storage.get('my-app-density'); // the request's cookie on the server; the browser's otherwisestorage.set('my-app-density', 'compact'); // a cookie for a year, and its localStorage copy

A prerendered page has no request: it is drawn with the defaults, and the browser applies the choices as it starts. The mode and the theme don't wait for it: a small script in the page's head sets them before the first paint — the system's mode, which only the browser knows, included.

Allowed hosts

Angular's server answers only the hosts you list (its protection against server-side request forgery): add your domains to the build's security.allowedHosts, or every page answers 400.

"security": {  "allowedHosts": ["example.com", "*.example.com"]}

Checking

Build and serve the server build, and watch the browser's console: a hydration mismatch shows as an NG05xx message in development. The library's own components are tested this way — every demo rendered on the server, then hydrated.

One warning there is Angular's, not yours: NG02952, "the height of the fill-mode image is zero", on a fill image in a box sized by bound classes (a carousel slide, a masonry item). The server's page has loaded the image, so NgOptimizedImage measures it as hydration starts, before the bindings put the box's classes back. The page is right once hydrated, and the check runs in development only (angular/angular#69636). Without SSR the same check is a real one.