Bagas measures a card on a real dashboard with a ResizeObserver as the sidebar, text and padding change, beside the teacher’s resize listener: who notices?…
Why it matters
The window resize event only fires when the viewport changes, not when a sidebar opens, a font loads late or content grows. Charts, canvases, virtual lists and components that live in many columns need their own size. Container queries cover styling; ResizeObserver covers JS logic.
The key idea
It observes the element, not the window
Common mistakes
The console keeps showing "ResizeObserver loop completed with undelivered notifications" Your callback resizes the element it observes (say, sets height from its width). The browser does not revisit that element in the same frame, so the report waits and this error fires. Defer the write with requestAnimationFrame, or use CSS (aspect-ratio) when that is enough.
The observers pile up, never dying when the component unmounts An observer that is never disconnect()ed lives on and keeps calling the old callback. In React, return () => ro.disconnect() from useEffect.
A sidebar opens or content grows, but the resize listener never fireswindow.onresize is only about the viewport. Layout changes inside the page (a sidebar, dynamic content, fonts) only show up through a ResizeObserver on the element.
Try it in this playground
Open the sidebar The card narrows and the callback gets a new entry. The window resize count stays 0.
Type a long sentence in "Card text" The text wraps, the card gets taller: the callback runs too, with the same width.
Pick border-box, then move padding-inline The card is box-sizing: border-box, so its border-box width stays put: the callback stays quiet while the content narrows.
Pick "right away" for writing the height The callback resizes the observed element: the browser throws the loop error (caught and counted on the board).