Deeper StyleX integration should look like a compiler feature, not a runtime styling dependency.
The right model is:
tsx source
-> parse framework graph
-> parse StyleX calls
-> validate static style facts
-> merge styles into chunk/route/component plan
-> emit CSS + class/style DOM ops + manifest metadata
So authors write normal app code:
import * as stylex from '@stylexjs/stylex';
const styles = stylex.create({
card: {
padding: 16,
borderRadius: 8,
backgroundColor: 'white',
},
selected: {
borderColor: 'blue',
},
progress: (value: number) => ({
'--progress': `${value}%`,
}),
});
export function CatalogCard() {
const selected = useSignal(false);
const progress = useComputed(() => selected.value ? 100 : 25);
return (
<article
sx={[
styles.card,
selected.value && styles.selected,
styles.progress(progress.value),
]}
/>
);
}Then the compiler emits:
- static atomic CSS
classattrs for static/conditional stylesstyleCSS variable ops for dynamic StyleX functions- reactive DOM bindings for
selected.valueandprogress.value - CSS deps in
chunk_manifest.json
No browser StyleX runtime should be needed.
Where this gets interesting for this framework:
-
StyleX becomes another compiler IR Add
StyleFacts/StylePlanalongsideFrameworkGraph,OptimizationPlan, andEmitPlan. -
Chunk optimizer owns CSS too A component chunk should know its JS symbols and StyleX class dependencies. Route/component/symbol chunking should produce matching CSS preload/prefetch hints.
-
Signals drive styles without VDOM Static class decisions become compiled class ops. Dynamic StyleX functions become CSS custom property updates through
dom_ops.js. -
Themes become resumable metadata
stylex.defineVars()andstylex.createTheme()map well to a typed theme manifest. The server can serialize active theme ids inresume_manifest.json; the loader only applies a class/vars, not style objects. -
JSX types get cleaner Our JSX host element types can add
sx?: StyleXStyles | StyleXStyles[], while custom components can explicitly accept style props. StyleX docs also call outsxfor host JSX andstylex.attrs()for non-React environments, which fits us because we compile JSX ourselves.
The key rule: do not bolt StyleX on as a Vite/Babel sidecar that has its own worldview. Make it a first-class compiler pass so styles, chunks, DOM ops, signals, themes, and resumability all share the same manifest model.
Sources: StyleX defining styles, stylex.props / sx, stylex.defineVars.