Third and final hit of the 'Recursion detected' panic class
(i-slint-core properties.rs:583), this time crashing DiscoverBrowse on
startup view-restore (and crash-looping via persistence). Root cause
symbolized from the field backtrace: every .slint 'changed x =>'
compiles to a ChangeTracker whose watched expression evaluates
SYNCHRONOUSLY at component instantiation, and conditional/repeated
components instantiate from ensure_updated INSIDE whatever property
evaluation triggered them — so a windowing band that reads layout
results (viewport-y, flick.height, self.width, absolute-position) can
re-enter a property mid-evaluation. Timing-sensitive: needs the model
filling in the same pass that instantiates the grid, which startup
view-restore hits deterministically.
Class-kill, uniform on every windowed surface (owner mandate — no
survivor exceptions): band state is now plain properties written ONLY
by an 80ms sampler Timer (event-loop context, nothing on the property
stack) in the shared AlbumGrid, the horizontal Carousel and the search
grid. No changed handlers, no init-time reads; the ±1-viewport margin
absorbs the sampling cadence; consumers' declarative wiring unchanged
(inputs are polled, never observed — contract documented in-file).
Startup crash-chain watchdog ('perro policía'): a counter file armed
before risky init and cleared by the same liveness signals as the
renderer sentinel. One pre-liveness death -> next boot resets exactly
ui_prefs last_nav/last_view (the field-verified surgical bypass) with
a recovery toast; two -> additionally bypasses the session-persist
queue restore for that boot, and the exit save keeps the preserved
snapshot instead of clobbering it with the empty queue. Recovers this
incident and the #558 loop automatically. One msgid x8.
cc
346 lines
16 KiB
Plaintext
346 lines
16 KiB
Plaintext
// Album collection content — renders a flat grid, a flat list, or
|
|
// group-by sections (each a title + grid). The surrounding view owns the
|
|
// toolbar and the loading / empty / load-more states; this component is
|
|
// purely the rendered collection, so the grid column math and the list
|
|
// header+rows live in one place. Shared by Discover Browse, Label
|
|
// Releases, and Favorites albums.
|
|
|
|
import { Theme } from "../foundation/semantic-colors.slint";
|
|
import { Typography } from "../foundation/typography.slint";
|
|
import { AlbumCardItem, DiscoverSection } from "../state.slint";
|
|
import { AlbumCard } from "AlbumCard.slint";
|
|
import { AlbumListRow, AlbumListHeader } from "../primitives/AlbumListRow.slint";
|
|
|
|
// Wrapping album grid over a model — column math in one place, shared by
|
|
// the flat grid and each group-by section.
|
|
component AlbumGrid inherits Rectangle {
|
|
in property <[AlbumCardItem]> albums;
|
|
in property <length> card-width: 200px;
|
|
in property <length> card-height: 246px;
|
|
in property <length> card-gap: 24px;
|
|
in property <bool> show-favorite: true;
|
|
in property <bool> show-source-badge: false;
|
|
in property <bool> select-mode: false;
|
|
// --- Viewport windowing (opt-in; default OFF = identical to before) ---
|
|
// With `windowed` on, only cards within ~one viewport of the visible band
|
|
// mount a real AlbumCard; the rest are same-footprint placeholders, so
|
|
// the height formula below (the scroll geometry) never changes.
|
|
// `visible-top`/`visible-height` arrive in the surrounding Flickable's
|
|
// CONTENT coordinates; `content-offset` is this grid's approximate y
|
|
// inside that content — small errors are absorbed by the margin.
|
|
//
|
|
// CONTRACT: these inputs are POLLED, never observed. The grid reads them
|
|
// only from its sampler Timer (see below); wiring them to live layout
|
|
// expressions (-flick.viewport-y / flick.height) is safe BECAUSE nothing
|
|
// here evaluates them from a binding or `changed` handler.
|
|
in property <bool> windowed: false;
|
|
in property <length> visible-top: 0px;
|
|
in property <length> visible-height: 0px;
|
|
in property <length> content-offset: 0px;
|
|
callback open-album(string);
|
|
callback open-artist(string);
|
|
callback media-action(string, string, string);
|
|
// Fired (windowed only) when the row band changes — [first, last] item
|
|
// indices, prefetch margin included. The consumer dispatches artwork.
|
|
callback window-changed(int /* first index */, int /* last index */);
|
|
|
|
property <int> columns: Math.max(
|
|
1,
|
|
Math.floor((self.width + root.card-gap) / (root.card-width + root.card-gap)));
|
|
property <int> rows: Math.ceil(root.albums.length / self.columns);
|
|
height: self.rows > 0
|
|
? self.rows * root.card-height + Math.max(0, self.rows - 1) * root.card-gap
|
|
: 0px;
|
|
|
|
// ------------------------------------------------------------------
|
|
// WINDOWING ENGINE — POST-LAYOUT SNAPSHOT SAMPLING. Read this before
|
|
// touching anything below; this is the THIRD hit of the "Recursion
|
|
// detected" panic class (i-slint-core properties.rs:583) and the sampler
|
|
// is the class-kill.
|
|
//
|
|
// The mechanism that crashes (field-hit 2026-07-07 on LL grouped via an
|
|
// absolute-position binding, and 2026-07-08 on DiscoverBrowse at startup
|
|
// view-restore when the album model filled): a `changed x => {}` handler
|
|
// compiles to a ChangeTracker whose watched expression is evaluated
|
|
// SYNCHRONOUSLY inside `user_init` at component instantiation — and a
|
|
// conditional/repeated component instantiates from `ensure_updated`,
|
|
// which runs INSIDE whatever property evaluation triggered it (a layout
|
|
// cache, a layout_info/preferred-height chain, the render pass). If the
|
|
// watched expression reads layout-RESULT properties (flick.viewport-y /
|
|
// flick.height / self.width / absolute-position), that read can land on
|
|
// a property that is mid-evaluation higher up the same stack → re-entry
|
|
// → panic. It is timing-sensitive: it needs the model to fill in the
|
|
// same pass that instantiates the grid (startup view-restore hits it
|
|
// deterministically; warm navigation usually mounts the grid empty
|
|
// first and survives).
|
|
//
|
|
// The kill: the band state below consists of PLAIN properties written
|
|
// ONLY by the sampler Timer. Timer callbacks run from the event loop
|
|
// with no property evaluation on the stack, so reading the live layout
|
|
// inputs there cannot re-enter anything. There are deliberately NO
|
|
// `changed` handlers and NO init-time reads of the inputs in this
|
|
// component. Do not "optimize" this back to reactive bindings.
|
|
// ------------------------------------------------------------------
|
|
property <length> row-stride: root.card-height + root.card-gap;
|
|
// Snapshot band — plain values, sampler-written. The pre-seed [0, 3]
|
|
// keeps roughly the first viewport of cards mounted for the <=80ms
|
|
// between mount and the first tick (placeholder tiles cover the rest).
|
|
property <int> target-first-row: 0;
|
|
property <int> target-last-row: 3;
|
|
// Mounted band = target band + contract hysteresis. Expansion follows the
|
|
// target immediately (a card must be mounted before it can reach the
|
|
// visible area); contraction lags by `hysteresis-rows`, so a few-px
|
|
// oscillation across a row boundary cannot mount/unmount a whole row of
|
|
// cards on every direction change.
|
|
property <int> hysteresis-rows: 1;
|
|
property <int> first-window-row: 0;
|
|
property <int> last-window-row: 3;
|
|
// Last column count reported through window-changed (columns shift on
|
|
// resize, which re-keys the band's ITEM indices).
|
|
property <int> notified-columns: 0;
|
|
pure function desired-first-row() -> int {
|
|
if (root.target-first-row < root.first-window-row) {
|
|
return root.target-first-row;
|
|
}
|
|
if (root.target-first-row > root.first-window-row + root.hysteresis-rows) {
|
|
return root.target-first-row - root.hysteresis-rows;
|
|
}
|
|
return root.first-window-row;
|
|
}
|
|
pure function desired-last-row() -> int {
|
|
if (root.target-last-row > root.last-window-row) {
|
|
return root.target-last-row;
|
|
}
|
|
if (root.target-last-row < root.last-window-row - root.hysteresis-rows) {
|
|
return root.target-last-row + root.hysteresis-rows;
|
|
}
|
|
return root.last-window-row;
|
|
}
|
|
function apply-window() {
|
|
if (root.desired-first-row() != root.first-window-row
|
|
|| root.desired-last-row() != root.last-window-row) {
|
|
root.first-window-row = root.desired-first-row();
|
|
root.last-window-row = root.desired-last-row();
|
|
root.notify-window();
|
|
}
|
|
}
|
|
// The sampler: reads the live inputs (safe here — event-loop context),
|
|
// recomputes the target band, applies hysteresis, and notifies on
|
|
// change. ~12.5 Hz is enough: the band carries a full-viewport margin,
|
|
// so a fling would have to cross more than one viewport in 80ms to
|
|
// outrun it — and then the placeholder tiles (the designed fast-scroll
|
|
// fallback) cover until the next tick.
|
|
function sample-window() {
|
|
if (!root.windowed) {
|
|
return;
|
|
}
|
|
root.target-first-row = Math.max(0, Math.floor(
|
|
((root.visible-top - root.content-offset) - root.visible-height)
|
|
/ root.row-stride));
|
|
root.target-last-row = Math.max(0, Math.floor(
|
|
((root.visible-top - root.content-offset) + 2 * root.visible-height)
|
|
/ root.row-stride));
|
|
root.apply-window();
|
|
if (root.columns != root.notified-columns) {
|
|
root.notified-columns = root.columns;
|
|
root.notify-window();
|
|
}
|
|
}
|
|
Timer {
|
|
interval: 80ms;
|
|
running: root.windowed;
|
|
triggered => { root.sample-window(); }
|
|
}
|
|
function notify-window() {
|
|
if (root.windowed) {
|
|
root.window-changed(
|
|
root.first-window-row * root.columns,
|
|
(root.last-window-row + 1) * root.columns - 1);
|
|
}
|
|
}
|
|
|
|
for album[i] in root.albums: card-slot := Rectangle {
|
|
x: Math.mod(i, root.columns) * (root.card-width + root.card-gap);
|
|
y: Math.floor(i / root.columns) * (root.card-height + root.card-gap);
|
|
width: root.card-width;
|
|
height: root.card-height;
|
|
property <bool> in-window: !root.windowed
|
|
|| (Math.floor(i / root.columns) >= root.first-window-row
|
|
&& Math.floor(i / root.columns) <= root.last-window-row);
|
|
// Placeholder tile while the real card is unmounted (fast scroll).
|
|
border-radius: 8px;
|
|
background: card-slot.in-window ? transparent : Theme.surface-elevated;
|
|
if card-slot.in-window: AlbumCard {
|
|
width: root.card-width;
|
|
height: root.card-height;
|
|
album: album;
|
|
show-favorite: root.show-favorite;
|
|
show-source-badge: root.show-source-badge;
|
|
select-mode: root.select-mode;
|
|
clicked(id) => {
|
|
root.open-album(id);
|
|
}
|
|
media-action(kind, id, action) => {
|
|
if (kind == "artist") {
|
|
root.open-artist(id);
|
|
} else {
|
|
root.media-action(kind, id, action);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
export component AlbumCollectionView inherits VerticalLayout {
|
|
in property <[AlbumCardItem]> albums; // flat set (grid/list)
|
|
in property <[DiscoverSection]> grouped; // group-by sections
|
|
in property <bool> is-grouped: false;
|
|
in property <string> view-mode: "grid"; // "grid" | "list"
|
|
in property <bool> show-source: false;
|
|
// Forwarded to AlbumCard — hide the favorite heart in non-favoritable
|
|
// contexts (Local Library albums).
|
|
in property <bool> show-favorite: true;
|
|
// Forwarded to AlbumCard — show the always-visible source badge on the
|
|
// grid card art (Local Library: local | qobuz-offline | plex).
|
|
in property <bool> show-source-badge: false;
|
|
// Forwarded to AlbumCard / AlbumListRow — checkbox + toggle-on-click
|
|
// (Local Library albums multi-select). Default false everywhere else.
|
|
in property <bool> select-mode: false;
|
|
in property <length> card-width: 200px;
|
|
in property <length> card-height: 246px;
|
|
in property <length> card-gap: 24px;
|
|
in property <length> list-row-gap: 4px;
|
|
// Viewport windowing — forwarded to the FLAT grid only. Grouped sections
|
|
// keep FULL mounts: deriving a section's offset from an absolute-position
|
|
// binding re-enters the layout solver ("Recursion detected" panic,
|
|
// field-hit 2026-07-07 — see the comment at the section grid below).
|
|
// OFF by default so untouched consumers keep full mounts.
|
|
in property <bool> windowed: false;
|
|
in property <length> visible-top: 0px;
|
|
in property <length> visible-height: 0px;
|
|
in property <length> content-offset: 0px;
|
|
callback window-changed(int /* first index */, int /* last index */);
|
|
callback open-album(string);
|
|
callback open-artist(string);
|
|
callback media-action(string, string, string);
|
|
|
|
spacing: 0px;
|
|
|
|
// --- Grouped (sections) — each section follows the grid/list mode --
|
|
if root.is-grouped && root.grouped.length > 0: VerticalLayout {
|
|
spacing: 0px;
|
|
// In list mode the column header sits once above all sections.
|
|
if root.view-mode == "list": AlbumListHeader {
|
|
show-source: root.show-source;
|
|
}
|
|
for section[s] in root.grouped: VerticalLayout {
|
|
spacing: 12px;
|
|
if s > 0: Rectangle { height: 24px; }
|
|
Text {
|
|
text: section.title;
|
|
color: Theme.text-primary;
|
|
font-size: Typography.heading;
|
|
font-weight: Typography.semibold;
|
|
}
|
|
// List view: rows for this section.
|
|
if root.view-mode == "list": VerticalLayout {
|
|
spacing: root.list-row-gap;
|
|
for album[i] in section.albums: AlbumListRow {
|
|
album: album;
|
|
index: i;
|
|
show-source: root.show-source;
|
|
select-mode: root.select-mode;
|
|
clicked(id) => {
|
|
root.open-album(id);
|
|
}
|
|
media-action(kind, id, action) => {
|
|
if (kind == "artist") {
|
|
root.open-artist(id);
|
|
} else {
|
|
root.media-action(kind, id, action);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// Grid view: a card grid for this section — FULL mounts, NOT
|
|
// windowed. Windowing a section needs its y inside the scroll
|
|
// content, and measuring that with an absolute-position BINDING
|
|
// is a proven runtime panic ("Recursion detected", field-hit on
|
|
// LL Albums grouped 2026-07-07): evaluating the target-row chain
|
|
// through absolute-position can re-enter the parent layout
|
|
// solver mid-pass (the grid's own height/columns read back
|
|
// self.width). A safe grouped windowing needs Rust-computed
|
|
// per-section offsets — backlog; sections are the smaller win.
|
|
if root.view-mode != "list": AlbumGrid {
|
|
albums: section.albums;
|
|
show-favorite: root.show-favorite;
|
|
show-source-badge: root.show-source-badge;
|
|
select-mode: root.select-mode;
|
|
card-width: root.card-width;
|
|
card-height: root.card-height;
|
|
card-gap: root.card-gap;
|
|
open-album(id) => {
|
|
root.open-album(id);
|
|
}
|
|
open-artist(id) => {
|
|
root.open-artist(id);
|
|
}
|
|
media-action(kind, id, action) => {
|
|
root.media-action(kind, id, action);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// --- Flat grid -----------------------------------------------------
|
|
if !root.is-grouped && root.view-mode == "grid" && root.albums.length > 0: AlbumGrid {
|
|
albums: root.albums;
|
|
show-favorite: root.show-favorite;
|
|
show-source-badge: root.show-source-badge;
|
|
select-mode: root.select-mode;
|
|
card-width: root.card-width;
|
|
card-height: root.card-height;
|
|
card-gap: root.card-gap;
|
|
windowed: root.windowed;
|
|
visible-top: root.visible-top;
|
|
visible-height: root.visible-height;
|
|
content-offset: root.content-offset;
|
|
window-changed(first, last) => {
|
|
root.window-changed(first, last);
|
|
}
|
|
open-album(id) => {
|
|
root.open-album(id);
|
|
}
|
|
open-artist(id) => {
|
|
root.open-artist(id);
|
|
}
|
|
media-action(kind, id, action) => {
|
|
root.media-action(kind, id, action);
|
|
}
|
|
}
|
|
|
|
// --- Flat list -----------------------------------------------------
|
|
if !root.is-grouped && root.view-mode == "list" && root.albums.length > 0: VerticalLayout {
|
|
spacing: root.list-row-gap;
|
|
AlbumListHeader {
|
|
show-source: root.show-source;
|
|
}
|
|
for album[i] in root.albums: AlbumListRow {
|
|
album: album;
|
|
index: i;
|
|
show-source: root.show-source;
|
|
select-mode: root.select-mode;
|
|
clicked(id) => {
|
|
root.open-album(id);
|
|
}
|
|
media-action(kind, id, action) => {
|
|
if (kind == "artist") {
|
|
root.open-artist(id);
|
|
} else {
|
|
root.media-action(kind, id, action);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|