Skip to content

Commit a39db33

Browse files
committed
Simplify comments
1 parent 441493a commit a39db33

2 files changed

Lines changed: 15 additions & 15 deletions

File tree

‎packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -752,10 +752,8 @@ describe( 'DataViews component', () => {
752752

753753
describe( 'in grid view', () => {
754754
it( 'lays the grid out at its real column count on the first render', async () => {
755-
// The resize observer only reports after that first render has
756-
// painted. Without a measurement taken as the grid attaches, it
757-
// renders once at width 0, which puts every item in a row of its
758-
// own at full width before snapping to the real column count.
755+
// Without a measurement as the grid attaches, the first render runs
756+
// at width 0 and puts every item in a full-width row of its own.
759757
const offsetWidth = Object.getOwnPropertyDescriptor(
760758
window.HTMLElement.prototype,
761759
'offsetWidth'
@@ -774,8 +772,7 @@ describe( 'DataViews component', () => {
774772
// the three items make two rows rather than three.
775773
expect( screen.getAllByRole( 'row' ) ).toHaveLength( 2 );
776774

777-
// The observer then reports the same width, leaving the layout
778-
// as it is.
775+
// The observer reports the same width, so nothing changes.
779776
await act( async () => {
780777
vi.runOnlyPendingTimers();
781778
} );
@@ -788,6 +785,12 @@ describe( 'DataViews component', () => {
788785
'offsetWidth',
789786
offsetWidth
790787
);
788+
} else {
789+
// Nothing to put back, so remove the stub.
790+
Reflect.deleteProperty(
791+
window.HTMLElement.prototype,
792+
'offsetWidth'
793+
);
791794
}
792795
}
793796
} );

‎packages/dataviews/src/hooks/use-container-width.ts‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)