KamoCRM

Read the scroll position from an observer, not from layout

Performancekamo-marketing
Ya
20 Agosti 2026, 22:18 UTC
Mwandishi
Kamo
Ahadi ya
861e159

The nav's scrolled/at-top state came from a scroll handler that read window.scrollY, and the mount effect called that handler synchronously during React's commit phase. Reading a scroll offset there forces the browser to compute layout on the spot, before the first paint has happened, which is precisely the forced reflow Lighthouse was reporting against the router chunk. An IntersectionObserver on a 1x20px sentinel at the top of the document answers the same question — is the page scrolled past 20px — without asking for geometry at all. The browser reports it out of a pass it was already going to do. The sentinel is absolutely positioned and pointer-events: none, so it is out of flow and cannot shift or intercept anything.

Mabadiliko yote

Je, unaona nini kuhusu usafiri?

Kila kitu kinaingia kwenye tovuti yako mwenyewe. Anza kwenye mpango wa bure na usome ukurasa huu tena katika mwezi mmoja.

Kuwa Huru MileleMtazamo wa bei