📊 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... 1836ms
Loading #9... 1484ms
Loading #1... 2325ms
Loading #10... 1874ms
Loading #2... 2352ms
Loading #11... 917ms
Loading #3... 2407ms
Loading #12... 1598ms
Loading #4... 1496ms
Loading #13... 849ms
Loading #5... 1049ms
Loading #14... 2132ms
Loading #6... 1787ms
Loading #7... 2449ms
Loading #8... 1799ms

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.