📊 CLS Visualization

This page demonstrates how the masonry layout handles Cumulative Layout Shift (CLS). The CSS container queries ensure the correct number of columns render immediately, even before JavaScript measures the container width.

Hydration Status

Hydrated: ⏳ Pending
Hydration time: ...
Container width: measuring...
SSR columns (max): 9
Actual columns: 9
Column match: ✓ CSS covers

Controls

Loading #0... 1904ms
Loading #9... 1500ms
Loading #1... 1749ms
Loading #10... 1566ms
Loading #2... 679ms
Loading #11... 2125ms
Loading #3... 647ms
Loading #12... 2344ms
Loading #4... 2350ms
Loading #13... 1340ms
Loading #5... 942ms
Loading #14... 1654ms
Loading #6... 1488ms
Loading #7... 1884ms
Loading #8... 1035ms

How CLS Prevention Works

1
SSR renders maximum columns

On the server, masonryWidth is 0. Instead of defaulting to 1 column, we calculate the maximum columns that could fit a 1920px viewport.

2
CSS container queries hide excess

Dynamic @container rules immediately hide columns that don't fit the actual container width. This happens purely in CSS, before any JS runs.

3
JS hydrates and confirms

After hydration, JavaScript measures the actual width and calculates the correct column count. Since CSS was already showing the right number, there's no shift.