Loomguides

Gallery targets

Browse many scenes at once — the `preview` export contract, discovery globs and error containment.

Gallery mode shows a sidebar of every scene in your project and mounts one at a time. Use it while building a component library. It is also the only mode loom build supports.

Enable gallery mode
pnpm exec loom preview ~/code/my-ui --targets

With --targets, loom doesn’t look for a client entry, and it serves its own page even if your project has an index.html.

In a project with its own Vite config, pass the same option to the plugin:

vite.config.ts
export default defineConfig({
plugins: [loomPreview({ targets: "src/scenes" })],
});

vite then serves the gallery, and vite build builds it as a static site.

The target contract

A target is any file matching the discovery glob that exports a preview object:

src/scenes/Counter.loom.tsx
import { useState } from "@rbxts/react";
function CounterScene() {
const [count, setCount] = useState(0);
return (
<screengui Name="CounterScene">
<frame
Size={UDim2.fromOffset(280, 0)}
AutomaticSize={Enum.AutomaticSize.Y}
Position={UDim2.fromScale(0.5, 0.5)}
AnchorPoint={Vector2.new(0.5, 0.5)}
BackgroundColor3={Color3.fromRGB(28, 32, 38)}
>
<uicorner CornerRadius={UDim.new(0, 12)} />
<uilistlayout Padding={UDim.new(0, 12)} />
<textlabel Text={`count: ${count}`} /* ... */ />
<textbutton
Text="click me"
Event={{ Activated: () => setCount((c) => c + 1) }}
/* ... */
/>
</frame>
</screengui>
);
}
export const preview = {
render: () => <CounterScene />,
title: "Counter (Activated)",
} as const;
FieldRequiredBehavior
renderyesA function returning a React element. It is rendered as a function component, so hooks inside it work.
titlenoReplaces the file path in the sidebar. Titles load in the background, so the sidebar shows paths first.

Anything else, such as a default export, a bare component export, or a preview with no render function, shows an error panel:

invalid preview export in src/scenes/Counter.loom.tsx
target must export `const preview = { render: () => <.../>, title: "..." } as const`

Discovery

--targets and the plugin’s targets option take three shapes:

InvocationResulting glob
--targets (no value), or targets: true**/*.loom.tsx
--targets src/scenes (no *)src/scenes/**/*.loom.tsx
--targets "apps/*/src/**/*.scene.tsx"used verbatim

The plugin option also takes an array. The CLI flag doesn’t.

Globs support only **/ (any depth, including none), ** and * (anything but /). There are no braces, ? or negation. node_modules and folders starting with . are skipped. The sidebar is sorted by path. See Glob semantics for the full rules.

Adding or deleting a *.loom.tsx file reloads the page and keeps the selected target. Editing a target hot-reloads it.

loom.config.ts

To stop typing flags, add a config file to the project root:

loom.config.ts
export default {
targets: "src/scenes",
port: 5204,
};

loom preview reads three fields: targets (a string or non-empty array of strings), port (a number) and shims. CLI flags win over the file. Node loads it with its built-in TypeScript support. A file that fails to import only prints a warning. loom build doesn’t read this file.

loom: loom.config.ts found, but its default export has no `targets` or `shims` field — skipping it (legacy config?). Use `--targets [glob]` or export `{ targets?: string | string[], port?: number, shims?: Record<string, string> }`.

Error containment

A target that throws can’t break the page. The error shows in a red panel with its stack, and the sidebar keeps working. There are three kinds:

  • Import failure: failed to import <path> (a syntax error, a missing module).
  • Bad contract: invalid preview export in <path>.
  • Render throw: render error in <path>.

Switching targets clears the panel. A target that throws on purpose makes a good regression check for this.

Inspecting a target

The sidebar’s debug button, Ctrl+Alt+D, or ?debug=1 opens a panel over the stage. It shows timings, the viewport the scene laid out against, the live instance tree, which fonts loaded, and a hover inspector. It runs nothing while closed. See The debug panel.

Routing

With the sidebar, selecting a target sets #/<relPath>, and the hash survives reloads. On first load, ?target=<relPath> picks the target when there is no hash. Docs-site iframes use this to deep link. See Static builds and embedding.