Loomgetting started

How it works

From a roblox-ts component to DOM nodes — Scene IR, the WASM layout engine, the renderer and the plugin.

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 once
const result = computeLayout(scene, viewport); // synchronous after that

The 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:

  • renderScene rebuilds everything in one pass. The vide adapter uses it, and so does anything that needs a static picture.
  • createDomSession patches 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 LayerCollector are never painted.
  • Visible = false hides the node with CSS; it keeps its rect.
  • Text is painted in an aligned overlay layer.
  • UICorner and UIStroke become border-radius and box-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 Frame with an InputBegan handler still gets its events. Active controls 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:

  1. Page generation. With no index.html, it generates one around your client entry, or around the gallery shell when targets is set.
  2. Aliasing. @rbxts/react-roblox becomes a browser client with createRoot and createPortal. @rbxts/services becomes service singletons backed by game.GetService. @rbxts/react becomes React plus the React.Event and React.Change namespaces. @rbxts/vide becomes the vide adapter. Bare react and both JSX runtimes point at one path, so only one React loads.
  3. Globals. installGlobals() runs before your entry. It defines UDim2, Color3, Enum, game and the Luau standard library, and loads the engine’s typefaces. The dev server adds it as a script tag; vite build prepends it to the entry modules.
  4. Import-equals rewriting. roblox-ts uses import X = require("m"), which would throw in a browser. The plugin rewrites it to import * as X from "m".
  5. Luau-main fallback. A roblox-ts package points "main" at compiled Luau. The plugin redirects it to the package’s src/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.