@@ -4,13 +4,10 @@ import { useMergeRefs, useResizeObserver } from '@wordpress/compose';
44/**
55 * Tracks the width of the element the returned ref is attached to.
66 *
7- * The element is measured as soon as it attaches, during the commit phase, so
8- * the first paint already knows its width. A resize observer alone reports
9- * only after that first paint, which leaves a frame rendered at width `0`: the
10- * grid layout derives its column count from this width, so it lays every item
11- * out in a single full-width column before snapping to the real one.
7+ * The element is measured when it attaches, so a width is available for the
8+ * first paint. The resize observer keeps the width up to date from then on.
129 *
13- * The observer then keeps the width current as the element resizes .
10+ * Detaching leaves the last width in place; reattaching measures again .
1411 *
1512 * @return The element's width, and the ref to attach to it.
1613 */
@@ -20,9 +17,9 @@ export default function useContainerWidth< T extends HTMLElement >(): [
2017] {
2118 const [ width , setWidth ] = useState ( 0 ) ;
2219
23- // `offsetWidth` rather than `getBoundingClientRect()`: both are border-box
24- // widths, matching what the observer reports, but `offsetWidth` ignores any
25- // transform an ancestor may be animating with .
20+ // `inlineSize` is only available on an observer entry, so it can't be read
21+ // here. `offsetWidth` reports the same border box and, like
22+ // `borderBoxSize`, is unaffected by transforms .
2623 const measureRef = useCallback ( ( element ?: T | null ) => {
2724 if ( element ) {
2825 setWidth ( element . offsetWidth ) ;
0 commit comments