---
title: "Live Preview in Your Application"
description: "Reload .slint files at run time while your application is running"
---
import { Steps, Tabs, TabItem } from '@astrojs/starlight/components';
import Link from '@slint/common-files/src/components/Link.astro';
import LangRefLink from '@slint/common-files/src/components/LangRefLink.astro';

When building a Slint application in Rust or C++,
`.slint` files are normally compiled ahead of time into native code.
This means every UI change requires recompiling and restarting the application.
A Node.js application compiles them when it loads them, so every UI change requires restarting it.

The **live preview** feature lets your running application watch `.slint` files on disk
and reload them automatically when they change.
Your business logic stays connected, so you can iterate on the UI without restarting.

It's the same live preview as the one in [VS Code](/master/docs/slint/guide/tooling/vscode.md),
the [Slint LSP](/master/docs/slint/guide/tooling/manual-setup.md#slint-lsp), and the [Slint Viewer](/master/docs/slint/guide/tooling/slint-viewer.md).
The same interpreter loads and renders your `.slint` files, so the UI looks and behaves the same.
What differs is the surroundings:
here the preview runs inside your application, wired up to your business logic.

## How It Works

When live preview is enabled,
the Slint interpreter loads your components at runtime, instead of the code compiled ahead of time in Rust and C++.
It reloads `.slint` files from disk whenever they change.
The application keeps running during reloads,
and the properties, callbacks, and models that your code set are preserved.
If a `.slint` file has a syntax error, the previous version stays on screen until the error is fixed.

If you change the Slint API that your code interacts with, for example by renaming a property or callback it uses,
the application may stop working.
Recompile and restart to pick up those changes.

This feature is intended for development only.
Don't ship release builds with live preview enabled.

## Setup

<Tabs>
<TabItem label="Rust" icon="seti:rust">

Live preview requires the `live-preview` Cargo feature and the `SLINT_LIVE_PREVIEW` environment variable.

Build your application with both:

```bash
SLINT_LIVE_PREVIEW=1 cargo run --features slint/live-preview
```

Don't add `live-preview` to the `[features]` section of your `Cargo.toml`.
Use the `--features` flag on the command line instead,
so it stays out of your regular builds.

See the <LangRefLink lang="rust-slint" relpath="docs/cargo_features/">`live-preview` feature documentation</LangRefLink> for more details.

</TabItem>
<TabItem label="C++" icon="seti:cpp">

Live preview for C++ requires building Slint from source with the interpreter enabled.

<Steps>

1. **Build Slint from source** with the `SLINT_FEATURE_LIVE_PREVIEW` CMake option enabled:

   ```bash
   mkdir build && cd build
   cmake -GNinja -DSLINT_FEATURE_LIVE_PREVIEW=ON path/to/slint
   cmake --build .
   ```

2. **Compile your application** with the `SLINT_LIVE_PREVIEW` environment variable set:

   ```bash
   SLINT_LIVE_PREVIEW=1 cmake --build path/to/your/build
   ```

3. **Run your application.**
   Slint loads `.slint` files from disk and reloads them whenever you save changes.

</Steps>

See the <LangRefLink lang="cpp" relpath="live-preview/">C++ live preview documentation</LangRefLink> for more details.

</TabItem>
<TabItem label="NodeJS" icon="node">

Live preview for Node.js requires the `slint-ui-dev` package and the `SLINT_LIVE_PREVIEW` environment variable.

<Steps>

1. **Install `slint-ui-dev`** as a dev dependency, at the same version as `slint-ui`:

   ```bash
   npm install --save-dev slint-ui-dev
   ```

2. **Run your application** with the `SLINT_LIVE_PREVIEW` environment variable set:

   ```bash
   SLINT_LIVE_PREVIEW=1 node main.js
   ```

   Slint reloads the `.slint` files that you import or load with `loadFile()` whenever you save changes.

</Steps>

</TabItem>
</Tabs>