Runtime Strategy
The runtime strategy is a wrapper that can run Boss CSS fully in the browser or in hybrid mode. You configure runtime once, and it selects the underlying behavior (inline-first, classname-first, or classic) at runtime.
When to use
- Runtime-only: skip server CSS output and inject rules on the client.
- Hybrid: keep server CSS output and still run the runtime handler for dynamic values.
Configuration
import * as fontsource from 'boss-css/fontsource/server'
import * as reset from 'boss-css/reset/server'
import * as at from 'boss-css/prop/at/server'
import * as child from 'boss-css/prop/child/server'
import * as css from 'boss-css/prop/css/server'
import * as pseudo from 'boss-css/prop/pseudo/server'
import * as jsx from 'boss-css/parser/jsx/server'
import * as classname from 'boss-css/parser/classname/server'
import * as runtime from 'boss-css/strategy/runtime/server'
import * as token from 'boss-css/use/token/server'
export default {
plugins: [fontsource, reset, token, at, child, css, pseudo, classname, jsx, runtime],
runtime: {
only: true,
strategy: 'inline-first', // or 'classname-first' | 'classic'
globals: 'inline', // inline | file | none
},
}
Notes:
- Use only the
runtimestrategy plugin; do not includeinline-firstorclassname-firstdirectly. runtime.only: truedisables server CSS output and skips the.bo$$/styles.cssimport (unlessruntime.globals: 'file').runtime.only: falseenables hybrid mode (server CSS + runtime handling).runtime.strategyselects the underlying semantics at runtime.runtime.globalscontrols reset/fontsource/$$.css output in runtime-only:inlineinjects globals into a runtime style tag (default).fileemitsstyles.csseven in runtime-only.noneskips all global CSS output.
- In runtime-only, tokens resolve to CSS variables and the runtime injects token vars on first use (even if
runtime.globalsisnone). - In runtime-only mode, the className parser is disabled (className strings are not converted into CSS).
What happens at runtime
- The runtime wrapper initializes the client CSS injector (
RuntimeCSS) ononInit. - The runtime wrapper dispatches to
inline-first,classname-first, orclassicruntime-only handlers. - Runtime-only selector helpers for
at,pseudo, andchildare wired automatically whenruntimeconfig is enabled.
Classic runtime behavior
classic computes a stable hash of the full prop tree at runtime, assigns a className, and injects the full rule set (including nested contexts).
It is runtime-only behavior; server output falls back to inline-first when runtime.only is false.
Hybrid mode behavior
In hybrid mode, server CSS is still emitted by the selected strategy, and the runtime still processes props at render time. This keeps server output intact while allowing runtime-only features and dynamic values.