You can compute className: ternaries, &&, arrays, template strings, props and state all work,
and every utility still applies. What changes is whether the compiler can read your classes, and so
whether it can check them.
Three degrees, not two
| What you wrote | Emitted as | Resolved by | Checked |
|---|---|---|---|
className="flex gap-2", or an array of literals | Your tag, plain props | The compiler | Yes |
A variant, a branch, a margin, a divide-* | VelaRuntimeHost with __velaRules | The compiler; the host only reads conditions | Yes |
| A string the compiler cannot read | VelaRuntimeHost with className | The host, in-game | No |
A const holding a string literal counts as the first row. A const holding anything else counts
as the third.
Only the third row has a real cost. The middle row is where variants and branches normally land,
including a plain literal like className="sm:w-full".
className={["flex", "gap-2"]} collapses to one class list and stays in the first row. A ternary lands in the middle row, with both branches resolved and checked.
The two paths resolve the same utilities
Every utility in the reference works the same in-game as at compile time, including opacity modifiers and arbitrary values.
One difference: in-game, a utility the element can’t carry is dropped, because writing TextColor3
onto a Frame is a Roblox error. The static path warns and writes it anyway.
opacity-* always hands the class list to the host, which applies one alpha to the children. See
opacity-*.
A branch lowers at compile time
When an expression spells out its classes, the compiler resolves every option, even though it can’t know which one applies:
<textlabel className={big ? "text-lg" : "text-sm"} />Inside a branch:
- The full utility set applies.
- A bad utility reports a diagnostic.
- A variant applies only when both it and the branch’s condition hold.
big && "hover:text-xl"needsbigand the pointer. - Each condition is evaluated once, however many branches use it.
The compiler reads ternaries, &&, the literal on the right of ||, arrays, object maps, and a
const holding a string literal. Branches combine with the classes around them, so
["w-40", tall && "h-10"] becomes one Size.
The element still renders through the runtime host, but the host only evaluates the conditions. Nothing is parsed in-game:
<VelaRuntimeHost __velaRules={[ { condition: { kind: "test", index: 0, expected: true }, effects: { props: [{ name: "TextSize", value: "18" }] } }, { condition: { kind: "test", index: 0, expected: false }, effects: { props: [{ name: "TextSize", value: "14" }] } }, ]} __velaTests={[big ? true : false]} __velaTag={"textlabel"}/>What sends a branch back to the runtime resolver
Three things, and only the affected branch moves. ["w-4", on && "mt-4"] keeps w-4 resolved and
hands the host on && "mt-4".
- A token no rule can carry:
m-*,divide-*,animate-*,transition*, the text transforms andopacity-*. - A value the source never spells out:
`size-${n}`, a bare variable, a call, a spread. - The left side of
||, which is the class value itself when truthy.
When branches overlap:
- Branches that set the same property apply in written order.
[a && "bg-red-500", b && "bg-blue-500"]is blue when both hold. - Branches that set different halves of one property don’t merge.
[a && "w-40", b && "h-10"]writesSizetwice, and the later one wins.
What the runtime path still costs
This is the third row: a class value the compiler can’t read, like cn(...), a template string, or
a prop passed through.
- No diagnostics. A typo like
bg-blu-600resolves to nothing, and the element renders without a background. In a literal or a branch, it would warnunknown-theme-key. - Less editor help. Completions and hover work on literal text, even inside an expression. A
token an interpolation cuts into, as in
`w-[${width}]`, gets none. - Theme values are re-parsed in-game. The host accepts only
Color3.fromRGB(r, g, b)andnew UDim(a, b)with plain numbers. Any other theme value compiles, then silently breaks. See theme values.
Code size isn’t a cost. @rbxts/vela-runtime is one ModuleScript the whole place shares, so each
file adds only an import and its config:
import { createVelaRuntimeHost } from "@rbxts/vela-runtime";const VelaRuntimeHost = createVelaRuntimeHost({ /* … */ });How to tell which row an element landed in
There’s no diagnostic for it, so read the emitted roblox-ts:
- The element kept its own tag and gained plain props: first row.
- It became
VelaRuntimeHostwith__velaRulesand__velaTests: middle row. - It became
VelaRuntimeHostand still has aclassNameprop: third row.
Writing for the checked rows
Use readable forms where a typo would hurt. Compute freely everywhere else.
Branch the classes, not the element
Put the branch inside the class value instead of in a template string:
<frame className={["flex flex-col items-center gap-2 p-4 rounded-lg", emphasized ? "bg-slate-700" : "bg-slate-800"]} />Duplicating the whole element instead keeps it fully static, with no host at all. That’s a leaner emit but no better checked, so save it for elements where performance matters.
Or use a variant instead of computing
If the state is something Vela can see (pointer, press, focus, viewport, input device or color scheme), use a variant:
<textbutton className="bg-slate-800 hover:bg-slate-700 active:bg-slate-600 transition" Text="Play" />Computing is fine for the rest
A computed className for your own state is normal, and every token in it resolves:
const tone = disabled ? "bg-slate-800 text-slate-500" : "bg-blue-600 text-white";return <frame className={`flex items-center gap-2 p-2 rounded-md ${tone}`} />;The interpolation is what loses the check, not the ternary. Move the ternary into an array to get it back:
return ( <frame className={[ "flex items-center gap-2 p-2 rounded-md", disabled ? "bg-slate-800 text-slate-500" : "bg-blue-600 text-white", ]} />);Components take the same rows
<Panel className={classes} /> is lowered exactly like <frame className={classes} />, branches
included. On the runtime host, __velaTag={Panel} holds the component itself, and the host renders
it with the resolved props and helper children.
Your component must forward the props and children it doesn’t use, or the styling is lost with no diagnostic. See How it works.
On the runtime path, helper instances such as UICorner are built in-game rather than passed as
JSX children.
See also
- The five rules: this page condensed to what to remember while writing code.
- Responsive and input variants: the other way onto the runtime path.
- How it works: the compile pipeline and where the two paths split.
- Vide: the same three rows under the other target.