📊 CLS Visualization

This page demonstrates how the masonry layout reduces Cumulative Layout Shift (CLS). It passes a deterministic initialCols value for SSR. When that value matches the first measured client column count, stable order modes can hydrate with the same masonry column tree; otherwise CSS container queries still hide excess columns before JavaScript runs.

Hydration Status

Hydrated: ⏳ Pending
Hydration time: ...
Container width: measuring...
SSR columns: 4
Actual columns: 4
Column match: ✓ Exact SSR

Controls

Loading #0... 500ms
Loading #4... 2088ms
Loading #8... 1676ms
Loading #12... 1264ms
Loading #1... 897ms
Loading #5... 2485ms
Loading #9... 2073ms
Loading #13... 1661ms
Loading #2... 1294ms
Loading #6... 882ms
Loading #10... 2470ms
Loading #14... 2058ms
Loading #3... 1691ms
Loading #7... 1279ms
Loading #11... 867ms

How CLS Mitigation Works

1
SSR renders initial columns

On the server, masonryWidth is 0. This demo passes initialCols so SSR can render the same number of columns the client will use after its first width measurement.

2
CSS container queries hide excess

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

3
JS hydrates and measures

After hydration, JavaScript measures the actual width and calculates the client column count. Once masonryWidth is greater than 0, the measured calcCols result wins over initialCols; stable order modes avoid item redistribution when both counts match.