A preview passes through four stages, each with one job:
@rbxts/react ─┐ ├─► Frontend adapter ─► Scene IR ─► Layout engine ─► DOM renderer ─► Browser DOM vide ───────┘ (TypeScript) (contract) (Rust → WASM) (TypeScript)The Scene IR in the middle is a framework-agnostic description of a Roblox GUI tree. It is mirrored
between a Rust crate, loom-scene, and a TypeScript package, @loom-dev/scene. The layout engine
and the renderer only see the IR, so neither knows React exists. That is how the vide adapter was
added without touching either.
1. The frontend adapter
@loom-dev/react is a custom react-reconciler host config. It creates no DOM. It creates and
updates live loom instances: an in-browser model of Roblox’s Instance tree with real properties,
children and signals, as @rbxts/react-roblox does in Studio.
The vide adapter does the same job with signals instead of a reconciler, and produces the same IR.
2. Scene IR
The instance tree is serialized into plain data: UDim, UDim2, Vector2, Color3 (0–1
channels), and enum items as { enumType, name }. Nothing is a class, so it crosses the WASM
boundary cleanly.
3. Layout
@loom-dev/layout wraps the WASM engine:
await initLayout(); // load the wasm module onceconst result = computeLayout(scene, viewport); // synchronous after thatThe engine implements Roblox’s layout rules, not CSS’s: UIListLayout and UIGridLayout flow,
UIPadding, UISizeConstraint, UIAspectRatioConstraint, AutomaticSize, anchor points,
scale-plus-offset sizing and text measurement. It returns an absolute rect for every node.
This is why loom exists. Flexbox gets close enough to UIListLayout to be misleading. Running the
real algorithm gives you a preview you can trust.
4. DOM rendering
@loom-dev/renderer walks the IR with the layout result and emits nested, absolutely positioned
<div>s. It has two entry points:
renderScenerebuilds everything in one pass. The vide adapter uses it, and so does anything that needs a static picture.createDomSessionpatches incrementally and handles pointer input. Elements persist across frames, so listeners and focus survive a re-render. React uses this one.
A few rendering rules:
- The layout root and any
LayerCollectorare never painted. Visible = falsehides the node with CSS; it keeps its rect.- Text is painted in an aligned overlay layer.
UICornerandUIStrokebecomeborder-radiusandbox-shadow.
Input
The renderer hit-tests each DOM event, maps it back to a live instance through data-loom-id, and
fires that instance’s signals. Activated, InputBegan and UserInputService fire as they do in
Roblox.
Pointer capture follows Roblox’s input sinking, not the DOM’s. Only TextButton, ImageButton,
TextBox, ScrollingFrame and GuiObjects with Active = true sink pointer events:
- A plain
Framewith anInputBeganhandler still gets its events.Activecontrols sinking, not hearing. - Frames and labels with no listeners are click-through, so a transparent full-screen frame doesn’t swallow clicks meant for the control underneath.
- A modal scrim, usually a
TextButton, still blocks.
What the Vite plugin does
loomPreview() prepares your source so the stages above can run:
- Page generation. With no
index.html, it generates one around your client entry, or around the gallery shell whentargetsis set. - Aliasing.
@rbxts/react-robloxbecomes a browser client withcreateRootandcreatePortal.@rbxts/servicesbecomes service singletons backed bygame.GetService.@rbxts/reactbecomes React plus theReact.EventandReact.Changenamespaces.@rbxts/videbecomes the vide adapter. Barereactand both JSX runtimes point at one path, so only one React loads. - Globals.
installGlobals()runs before your entry. It definesUDim2,Color3,Enum,gameand the Luau standard library, and loads the engine’s typefaces. The dev server adds it as a script tag;vite buildprepends it to the entry modules. - Import-equals rewriting. roblox-ts uses
import X = require("m"), which would throw in a browser. The plugin rewrites it toimport * as X from "m". - Luau-main fallback. A roblox-ts package points
"main"at compiled Luau. The plugin redirects it to the package’ssrc/index.ts(x), so packages work even when never compiled.
The plugin doesn’t compile roblox-ts. esbuild transpiles the TSX and drops the types. There is no
rbxtsc and no Luau in the browser.
Next step
Scope and status covers what this pipeline handles today, and what it doesn’t.