Skip to content

Commit 65569bf

Browse files
authored
fix: make sure virtualizer clears item placeholder height (#4793)
1 parent 3d4723a commit 65569bf

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

‎packages/component-base/src/virtualizer-iron-list-adapter.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ export class IronListAdapter {
155155
// Assign a temporary placeholder sizing to elements that would otherwise end up having
156156
// no height.
157157
el.style.paddingTop = `${this.__placeholderHeight}px`;
158+
159+
// Manually schedule the resize handler to make sure the placeholder padding is
160+
// cleared in case the resize observer never triggers.
161+
requestAnimationFrame(() => this._resizeHandler());
158162
} else {
159163
// Add element height to the queue
160164
this.__elementHeightQueue.push(elementHeight);

‎packages/component-base/test/virtualizer-item-height.test.js‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,27 @@ describe('virtualizer - item height', () => {
6767
expect(item.offsetHeight).to.be.above(EVEN_ITEM_HEIGHT);
6868
expect(item.offsetHeight).to.be.below(ODD_ITEM_HEIGHT);
6969
});
70+
71+
it('should clear the temporary placeholder padding from the item', async () => {
72+
// Wait for the content to update (and resize observer to fire)
73+
await aTimeout(200);
74+
75+
// Cache the height of the first item
76+
const firstItem = elementsContainer.querySelector(`#item-0`);
77+
const firstItemHeight = firstItem.offsetHeight;
78+
79+
// Update the first item. Due to how the test updateElement function is implemented,
80+
// the item height will first be set to 0, which causes the virtualizer to
81+
// temporarily add padding to the element.
82+
virtualizer.update(0, 0);
83+
84+
// Manually restore the item's height
85+
firstItem.style.height = `${firstItemHeight}px`;
86+
87+
// Give some time for the resize observer to fire
88+
await aTimeout(100);
89+
90+
// The padding should have been be cleared and the item should have its original height.
91+
expect(firstItem.offsetHeight).to.equal(firstItemHeight);
92+
});
7093
});

0 commit comments

Comments
 (0)