---
title: "Editions"
description: "Choose the Slint release whose language behavior your project uses, so that a newer Slint doesn't break it."
---
import { Tabs, TabItem } from '@astrojs/starlight/components';
import LangRefLink from '@slint/common-files/src/components/LangRefLink.astro';

An edition is the Slint release whose language behavior your project uses, such as `1.19`.
A project is an application or a library.

When a Slint release changes the behavior of the language,
the change applies only if your edition is that release or newer.
Newer versions of Slint keep compiling your project the way your edition's release did,
until you raise the edition.
A library with its own [project file](../../../tooling/project-file/#libraries) keeps its edition
in an application that uses another one.
Each component follows the edition of the project it belongs to.
You can use new features with any edition.

## Choosing the Edition

Choose the major and minor version of the Slint release you write your project for, such as `1.19`.
It can be the version of Slint you build with, or an older one.
The oldest edition is `1.18`, with the language behavior of Slint 1.18 and earlier.
Slint refuses to compile your project if your edition is older than `1.18`,
or newer than your version of Slint.

### In the Project File

Set `edition` in the [project file](../../../tooling/project-file/).
Slint tools read it when you pass the project file or its directory.
Write it as a string, such as `"1.19"`, not as the number `1.19`:

```json
{
    "edition": "1.19"
}
```

### In Your Build

In Rust and C++, you can also set the edition where you compile your `.slint` files.
In Node.js and Python, set it in the project file.
An edition set there wins over the one in the project file.

<Tabs syncKey="dev-language">
<TabItem label="Rust" icon="seti:rust">
The `slint!` macro doesn't load a project file.
To set its edition, add an attribute at the start of the macro body; otherwise, the macro warns:

```rust
slint::slint! {
    #[edition = "1.19"]
    export component App inherits Window { }
}
```

The Slint extension for your editor and `slint-viewer` also read this attribute when you open the `.rs` file.

In `build.rs`, pass the edition to <LangRefLink lang="rust-slint-build" relpath="struct.CompilerConfiguration">`CompilerConfiguration::with_edition()`</LangRefLink>:

```rust
// build.rs
fn main() {
    let config = slint_build::CompilerConfiguration::new().with_edition((1, 19));
    slint_build::compile_with_config("ui/main.slint", config).unwrap();
}
```

With `slint-interpreter`, call <LangRefLink lang="rust-slint-interpreter" relpath="struct.Compiler">`Compiler::set_edition()`</LangRefLink>.
</TabItem>
<TabItem label="C++" icon="seti:cpp">
Pass `EDITION` to <LangRefLink lang="cpp" relpath="cmake-reference/slint-target-sources/">`slint_target_sources`</LangRefLink>:

```cmake
slint_target_sources(my_application ui/main.slint EDITION 1.19)
```
</TabItem>
</Tabs>

### On the Command Line

To set the edition on the command line, pass `--edition` to `slint-compiler` or `slint-viewer`:

```bash
slint-viewer --edition 1.19 ui/main.slint
```

### Without an Edition

Without an edition, Slint applies none of the behavior changes that depend on the edition.
The compiler reports that no edition is set.
To opt in, choose an edition as described above.

### In SlintPad

SlintPad and the previews in this documentation use the edition of their own release.
To select another one in [SlintPad](https://slintpad.com/), add it to the URL, such as `?edition=1.18`.
Links from "Share" always include the edition, so that they keep their behavior in later releases.

## Behavior Changes

Each section lists what a release changed, and how to update your code if the change breaks it.

### 1.19

#### `if` and `for` Elements Are Sized Like Other Elements

Before 1.19, wrapping an element in `if true:` could change the layout around it, which was a bug:

- A non-layout parent, such as a `Rectangle` or a `Flickable`, computes its minimum and preferred size from its children.
  It ignored any child created with `if` or `for`
  ([#407](https://github.com/slint-ui/slint/issues/407)).
- A word-wrapped `Text` with its own `width` in an `if` or `for` element was measured at the layout's width.
  When the layout was wider, the element came out short and the next element overlapped it
  ([#14705](https://github.com/slint-ui/slint/issues/14705)).

With edition 1.19, an element created with `if` or `for` gets the same size as one written without them.

In this example, both rectangles hold the same text.
Before, the layout gave the first one a height of `0px`, as if it were empty.
Now both are as tall as their text:

```slint
export component Example inherits Window {
    width: 200px;
    VerticalLayout {
        alignment: start;
        Rectangle {
            background: lightgray;
            if true: Text { text: "Quarterly Report"; }
        }
        Rectangle {
            background: lightblue;
            Text { text: "Quarterly Report"; }
        }
    }
}
```

If you wrote code for the old behavior, it might need these changes:

- A parent now grows to fit its `if` and `for` children,
  and an element holding wrapped text can grow by a line.
  This can change the size of the elements around it in a layout.
  Where an element should keep a size of its own, give it an explicit `width` or `height`.
- A child that computes its size, or another property, from that parent's size now forms a binding loop,
  which the compiler reports as an error.

In this example, the title's text depends on the width of the `Rectangle`,
and the `Rectangle` is now as wide as the text it contains:

```slint no-test
component Header {
    in property <bool> show-title: true;
    HorizontalLayout {
        Rectangle {
            if show-title: Text {
                // error: The binding for the property 'text' is part of a binding loop
                text: parent.width > 200px ? "Quarterly Report" : "Report";
            }
        }
        Rectangle { background: lightblue; }
    }
}
```

To fix the loop, size the child, or compute its properties, without reading the parent's size:

- Give the parent an explicit `width` or `height`:

  ```slint {5}
  component Header {
      in property <bool> show-title: true;
      HorizontalLayout {
          Rectangle {
              width: 150px;
              if show-title: Text {
                  text: parent.width > 200px ? "Quarterly Report" : "Report";
              }
          }
          Rectangle { background: lightblue; }
      }
  }
  ```

- Replace `width: parent.width` with `width: 100%`, and the same for `height`.
  Don't do this for an element placed in a layout: there, a percentage sets an exact size in the layout.
- When a layout already applies the padding and spacing, remove any size computed from the parent's size minus that padding.
- As a last resort, set `x` or `y` on the child, which keeps it out of its parent's size.
  This pins its position: a `Text` that was centered in its parent moves to `0, 0`.
  In a layout, where setting `x` is an error, wrap the child in a `Rectangle` and set `x` on that.

#### Properties Set Only by States Keep Their Default Value

Before 1.19, a `width`, `height`, `x`, or `y` that only some [states](../../coding/states/) set was `0px` while none of them applied.
It didn't keep the element's [default size and position](../../coding/positioning-and-layouts/).
Adding a state for one case changed every other case too, which was a bug
([#8852](https://github.com/slint-ui/slint/issues/8852)).
With edition 1.19, the property keeps its default while none of the states applies.

In this example, the `Rectangle` now covers the window unless `compact` is true.
Before, it disappeared whenever `compact` was false:

```slint
export component Example inherits Window {
    width: 200px;
    height: 100px;
    in property <bool> compact;
    Rectangle {
        background: blue;
        states [
            small when compact: { height: 20px; }
        ]
    }
}
```

If your code relied on the `0px`, set the value outside the states, such as `height: 0px;`.
If a parent follows the size that the states set, the two now form a binding loop,
because the element's default size follows the parent.
The compiler reports it even when one state always applies, because it can't prove the conditions cover every case:

```slint no-test
export component Example inherits Window {
    in property <bool> open;
    VerticalLayout {
        Rectangle {
            // error: The binding for the property 'height' is part of a binding loop
            height: panel.height;
            panel := VerticalLayout {
                states [
                    expanded when open: { height: self.preferred-height; }
                    collapsed when !open: { height: 0px; }
                ]
                animate height { duration: 100ms; }
                Text { text: "Details"; }
            }
        }
    }
}
```

To fix the loop, add `height: 0px;` to `panel`, or replace its states with `height: open ? self.preferred-height : 0px;`.

#### Binding Loops Inside a Longer Binding Loop Are Reported

Before 1.19, the compiler skipped a binding loop when all its bindings were part of a longer binding loop it had already reported:

- When the longer loop went through the window layout, it was only a warning, so the code compiled.
- When the longer loop was an error too, the shorter one only showed up after fixing the longer one.

With edition 1.19, the compiler reports the shorter loop as an error too.
In this example, the inner `Rectangle` is a cell of the `VerticalLayout` and also reads its width.
Before, the compiler only warned about the loop through the window layout:

```slint no-test
export component Example inherits Window {
    HorizontalLayout {
        Rectangle {
            VerticalLayout {
                // error: The binding for the property 'width' is part of a binding loop
                Rectangle { width: parent.width; }
            }
        }
    }
}
```

To fix the loop, remove `width: parent.width;`: a layout already stretches its cells to its width.