> For the complete documentation index, see [llms.txt](https://www.openclawbook.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.openclawbook.xyz/en/ch35-web-console-ui/35.1-ui-technology-selection.md). Agents can also search and read this documentation through its [MCP server](https://www.openclawbook.xyz/~gitbook/mcp).

# 35.1 UI Technology Selection

> **Generated by**: Claude Opus 4.6 (initial draft) / Claude Opus 5 (`v2026.3.9` revision) **Token usage**: Input \~115k tokens, Output \~6k tokens (this section) **Source baseline**: `v2026.3.9` (`v2026.3.8-170-g665f67726`)

***

OpenClaw's Web Console (Control UI) is a single-page application embedded within the Gateway, providing users with a visual management interface. This section introduces its technology stack—the Lit Web Components framework, Vite build tool, and decorator constraints.

## 35.1.1 Lit Web Components Framework

### Why Choose Lit

OpenClaw did not adopt mainstream frontend frameworks like React, Vue, or Svelte. Instead, it uses Google's **Lit** library (`lit@^3.3`). The core considerations for this choice are:

| Factor              | Lit                                       | React/Vue              |
| ------------------- | ----------------------------------------- | ---------------------- |
| Bundle Size         | \~7KB (gzip)                              | 40-100KB+              |
| Runtime             | Browser-native Web Components             | Virtual DOM            |
| Dependency Chain    | Minimal external dependencies             | Large ecosystem        |
| Embedded Deployment | Suitable for embedding in Gateway process | Larger build artifacts |
| Framework Lock-in   | Web standards (Custom Elements)           | Framework-specific     |

For a management interface embedded within a backend process, minimal size is the primary requirement—the Control UI's build artifacts (HTML, JS, CSS, SVG) are directly packaged into the Gateway and served as static files via HTTP, requiring no separate frontend server.

> **Sidebar — Web Components**
>
> Web Components is a browser-native component standard consisting of three technologies:
>
> * **Custom Elements**: Define custom HTML tags (e.g., `<openclaw-app>`)
> * **Shadow DOM**: Component internal DOM tree is isolated from the outside, CSS styles don't interfere
> * **HTML Templates**: `<template>` and `<slot>` tags declare component content structure
>
> Unlike React's virtual DOM, Web Components directly use the browser's native DOM API without an additional runtime abstraction layer.

> **Sidebar — Lit**
>
> Lit is a lightweight library developed by Google on top of the Web Components standard, successor to Polymer. Its core contributions are:
>
> 1. **Declarative Templates**: Use JavaScript tagged template literals (`` html`...` ``) to describe UI
> 2. **Reactive Properties**: Mark state with `@state()` / `@property()` decorators, automatically trigger local re-renders on changes
> 3. **Minimal Size**: Core runtime is only \~7KB

### Lit Application in OpenClaw

The entire Control UI is a Custom Element named `<openclaw-app>`:

```typescript
// ui/src/ui/app.ts
import { LitElement } from "lit";
import { customElement, state } from "lit/decorators.js";

@customElement("openclaw-app")
export class OpenClawApp extends LitElement {
  @state() connected = false;
  @state() tab: Tab = "chat";
  @state() chatMessages: unknown[] = [];
  // ... 100+ reactive state fields
  
  render() {
    return renderApp(this);  // Delegate to separate render module
  }
}
```

In `index.html`, only one line is needed:

```html
<openclaw-app></openclaw-app>
```

### Dependency Inventory

The Control UI's runtime dependencies are extremely minimal:

| Dependency       | Purpose                            | Size   |
| ---------------- | ---------------------------------- | ------ |
| `lit`            | Web Components framework           | \~7KB  |
| `marked`         | Markdown → HTML rendering          | \~40KB |
| `dompurify`      | HTML sanitization (XSS prevention) | \~15KB |
| `@noble/ed25519` | Device authentication signing      | \~5KB  |

Only 4 runtime dependencies total, making the entire UI's build artifact much smaller than a typical React application.

## 35.1.2 Vite Build Tool

### Build Configuration

The Control UI uses Vite 7 as its build tool:

```typescript
// ui/vite.config.ts
export default defineConfig(() => {
  const envBase = process.env.OPENCLAW_CONTROL_UI_BASE_PATH?.trim();
  const base = envBase ? normalizeBase(envBase) : "./";
  return {
    base,                                          // Configurable base path
    publicDir: path.resolve(here, "public"),        // Static assets directory
    optimizeDeps: {
      include: ["lit/directives/repeat.js"],        // Pre-bundle Lit directives
    },
    build: {
      outDir: path.resolve(here, "../dist/control-ui"),  // Output to main project dist/
      emptyOutDir: true,
      sourcemap: true,
    },
    server: {
      host: true,
      port: 5173,
      strictPort: true,
    },
  };
});
```

**Key Design Decisions**:

1. **Relative Path Base**: Default `base: "./"` allows build artifacts to be deployed at any URL path. Gateway controls the mount point via the `OPENCLAW_CONTROL_UI_BASE_PATH` environment variable.
2. **Output to Main Project dist**: `outDir` points to `../dist/control-ui/` (the main project's `dist/control-ui/` directory), so when Gateway is released, UI resources can be distributed as a subdirectory.
3. **Independent package.json**: The `ui/` directory has its own `package.json`, completely isolated from the main project's dependencies. The build command is `pnpm ui:build` (a script alias defined in the main project).

### Development Mode

During development, use `pnpm ui:dev` to start Vite's development server (port 5173), supporting HMR (Hot Module Replacement). Since UI code directly imports some types and utility functions from the main project's `src/` (e.g., `src/routing/session-key.js`), the development server automatically handles cross-directory imports through Vite's file system resolution.

## 35.1.3 Legacy Decorators Constraint

### Decorator Compatibility Issue

Lit uses TypeScript decorators to declare Custom Elements and reactive properties:

```typescript
@customElement("openclaw-app")   // Register custom element
export class OpenClawApp extends LitElement {
  @state() connected = false;     // Internal reactive state
  @property() title = "";         // External passed-in property
}
```

TypeScript has two implementations for decorators:

| Version               | TypeScript Config                  | Standard              |
| --------------------- | ---------------------------------- | --------------------- |
| Legacy (Experimental) | `experimentalDecorators: true`     | TC39 Stage 1          |
| Standard              | `"experimentalDecorators"` not set | TC39 Stage 3 / ES2024 |

Lit 3.x decorators (such as `@customElement`, `@state`) use **Legacy decorator** syntax. This means the UI project's TypeScript configuration must enable `experimentalDecorators`.

### Impact on Project

Since the main project (OpenClaw backend) might use standard decorators or no decorators, while the UI sub-project must use Legacy decorators, their `tsconfig.json` files need independent configuration. This is also why UI is a separate sub-project (with its own `package.json`)—to avoid TypeScript configuration conflicts.

### No Shadow DOM

It's worth noting that the `OpenClawApp` class doesn't override the `createRenderRoot()` method to enable Shadow DOM—this means the entire Control UI's styles are global (defined via `ui/src/styles.css` and `ui/src/styles/` directory), not component-level isolated. This is a practical choice: the management interface doesn't need strict style isolation encapsulation, and global styles make theme switching and unified adjustments easier.

***

## Section Summary

1. **Lit Web Components** is the core framework for the Control UI, chosen because of its minimal size (\~7KB), basis in browser-native standards, and suitability for embedded deployment scenarios.
2. **Only 4 runtime dependencies**: Lit, Marked (Markdown rendering), DOMPurify (XSS protection), ed25519 (device authentication).
3. **Vite 7** as the build tool, outputting to the main project's `dist/control-ui/`, supporting base path configuration via environment variables.
4. **Legacy decorators** are a mandatory requirement for Lit 3.x, requiring the UI sub-project to have independent TypeScript configuration.
5. **No Shadow DOM** design makes global styles and theme switching simpler, suitable for management interface needs.
