📊 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... 638ms
Loading #9... 638ms
Loading #1... 669ms
Loading #10... 1987ms
Loading #2... 1597ms
Loading #11... 966ms
Loading #3... 510ms
Loading #12... 1390ms
Loading #4... 522ms
Loading #13... 1833ms
Loading #5... 1644ms
Loading #14... 654ms
Loading #6... 2002ms
Loading #7... 867ms
Loading #8... 1241ms

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.