Unistyles can render styles on the server-side, which is useful, for example, for SEO purposes.
Initial configuration
Configure your unistyles.ts file as it’s listed in the Getting started section.
Server side configuration
You just need to modify the __document.ts or __document.js file in your project’s root by importing
unistyles.ts file.
Client side configuration
To setup the listeners and Unistyles bindings, simply repeat the process,
but this time with _app.tsx file.
Some dynamic features like breakpoint are not available on the server. That’s why you need additional configuration with the isClient flag.
Adaptive themes with SSR
If you want to support adaptiveThemes in SRR you can’t set it on server, because the server is unaware of your client’s preferences.
Instead, manually select either light or dark theme on the server:
Then, on the client side, you can use the UnistylesRuntime to enable adaptiveThemes after the first render:
The client will not notice the difference, and you will avoid hydration errors.