Skip to content

fix(virtual-list): keep the cross size when layout effects re-run without a data change - #148

Merged
RuudBurger merged 1 commit into
mainfrom
ruud/virtuallist-cross-reset
Oct 15, 2026
Merged

RuudBurger merged 1 commit into
mainfrom
ruud/virtuallist-cross-reset

Conversation

@RuudBurger

Copy link
Copy Markdown
Member

VirtualList reset its cross size every time the layout effect fired, not only when data or extraData actually changed. In the Plex app Home sits under a Suspense based Freeze, so coming Back from a preplay screen re-runs every layout effect with the same data. Each inner row list dropped its cross size to the 200 default for one pass and measured itself short (poster rows 928 to 672, 892 to 636). Visible rows grow back, but a row that left the draw window first keeps 672, so everything below it sits 136px too high and the hero seeds shift. Visible layout shift after Back, plus hero text overlapping the row title after Down/Up.

Fix: the effect now remembers the data/extraData it last reset for and bails when both are unchanged. Moved the grow-only max, the reset and the generation into a small useContentCross hook so it can be tested on its own. Side effect: no more reset (and extra render) on mount, which was a no-op anyway since the max starts at 0.

The test renders the hook with a bare react-reconciler host (added as a devDependency, same version react-lightning uses) and hides/reveals it with Activity, which tears down and re-runs layout effects the same way the Freeze does. Fails without the guard, passes with it. Data and extraData changes still reset.

Verified in the app by swapping the change in at runtime: row and hero positions are identical before and after the Back round trip. Not checked on a real TV yet.

Left alone: handleContentCrossLayout is still a grow-only max per dataset, so when cells recycle between item types with different cross sizes it can keep a stale bigger value. Tracking cross per cell/key would fix that, but it changes when rows are allowed to shrink while scrolling, so I think it deserves its own PR.

@RuudBurger
RuudBurger merged commit 6ecc122 into main Oct 15, 2026
1 check passed
@RuudBurger
RuudBurger deleted the ruud/virtuallist-cross-reset branch October 15, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant