Skip to content

Documentation / @finchart/dom / observeElementSize

Function: observeElementSize() ​

observeElementSize(element): SizeObserver

Defined in: dom/src/observe-size.ts:23

The browser implementation that tracks the container's size with ResizeObserver — the element is pre-bound by browserDeps's autoSize: observeSize: observeElementSize(container).

It also reports the current size synchronously, before it returns. The first ResizeObserver callback arrives after the first frame is drawn, so a chart waiting for it would draw that frame at the size it was built with, and the fit would only land on the frame after. Reading the size lays the page out then, once per chart — with the chart's canvas already in it at that size, so a page scrollbar that canvas causes narrows the size read, and the observer's callback corrects it once the scrollbar is gone. The report can be zero (or, from rounding, slightly negative) where ResizeObserver would report an empty box.

In an environment without ResizeObserver, this does nothing and doesn't throw — browser wiring running under SSR is a normal path too; there's just nothing to observe, not a broken state.

Parameters ​

element ​

HTMLElement

Returns ​

SizeObserver