#13726·slint

GridLayout: a repeated Row's inner repeater mispairs cell constraints and placement across an empty slot (C++ and interpreter)

Author: tilladamCreated Sep 30, 2026Updated Sep 30, 2026
Labelsa:layoutsneed triaging

Bug: In a repeated Row that contains an inner repeater, the C++ generator and the interpreter enumerate the inner repeater differently for the row's two grid inputs. The constraint list is indexed by slot: len() counts every slot, and a slot whose instance isn't created yet yields a phantom "unconstrained" entry at its position. The grid input data, which carries each cell's column, row and spans, only walks the populated instances and pads at the end. The grid solver pairs the two lists by position, so an empty slot in the middle shifts every following cell's column and span onto the wrong constraint.

Rust codegen walks 0..len() on both sides and keeps an empty slot's position, so it isn't affected.

An empty slot in the middle exists between a model insert before an existing row and the instantiation pass. Any layout read in that window observes the mispairing: a changed handler, an init, or application code reading a size right after the insert. Before #13724 the layout bindings weren't invalidated until the instantiation pass, so such a read returned the previous layout instead; with #13724 it recomputes and the mispairing becomes visible. The asymmetry itself predates both.

Reproducer

slint
export component TestCase inherits Window {
    width: 300px;
    height: 300px;

    in property <[[int]]> rows;

    grid := GridLayout {
        spacing: 0px;
        // Pins columns 0, 1 and 3. A span that lands on column 3 is absorbed by the pin,
        // so a mispaired constraint changes the total width.
        Row {
            Rectangle { min-width: 20px; min-height: 10px; }
            Rectangle { min-width: 30px; min-height: 10px; }
            Rectangle { min-height: 10px; }
            Rectangle { min-width: 30px; min-height: 10px; }
        }
        for cells in root.rows: Row {
            for c in cells: Rectangle { min-width: 5px; min-height: 10px; }
            Rectangle { colspan: 2; min-width: 50px; min-height: 10px; }
        }
    }

    out property <length> grid-preferred-width: grid.preferred-width;
}

Start with rows = [[1, 1]], run one frame, then inner.insert(1, 2) and read grid-preferred-width before the next frame:

runtime before insert after insert, before the frame after the frame
Rust codegen 100 105 105
C++ codegen 100 130 105
interpreter (on #13724) 100 130 105
interpreter (master) 100 100, stale

With the empty slot kept in place the row is [cell, empty, cell, span]: the span sits on columns 3 and 4, the pinned column 3 absorbs part of it, and the total is 20 + 30 + 5 + 50 = 105. With the empty slot skipped, the constraints [5, phantom, 5, 50] are paired with the data of [cell, cell, span, padding]: the second cell's 5 px gets the span over columns 2 and 3, the 50 px cell lands on a fresh column 4, and the total is 20 + 30 + 30 + 50 = 130.

Test case with Rust and C++ blocks: tests/cases/layout/grid_nested_row_hole_pairing.slint (Rust passes, C++ reads 130). Interpreter: internal/interpreter/tests/grid_nested_row_hole_pairing.rs, the same scenario through the public API (reads 130). Both are on the branch of the fix PR.

Where

  • C++: internal/compiler/generator/cpp.rs, the grid_layout_input_for_repeated emission for RowChildTemplateInfo::Repeated uses for_each, which visits only populated slots, while layout_item_info indexes len() slots.
  • Interpreter: internal/interpreter/eval.rs, the grid input walk over instances_vec(), versus instance.rs layout_item_info indexing range().len() slots.

Fix

Walk 0..len() on the input-data side too, and advance the write index for an empty slot, as rust.rs does in grid_layout_input_data.