Skip to content

Commit c2f3ed7

Browse files
authored
fix: ensure virtualizer re-renders unhidden items (#3081)
1 parent 2bdd24b commit c2f3ed7

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ export class IronListAdapter {
272272
if (!el.hidden) {
273273
el.__virtualIndex = vidx + (this._vidxOffset || 0);
274274
this.__updateElement(el, el.__virtualIndex);
275+
} else {
276+
delete el.__lastUpdatedIndex;
275277
}
276278
}, itemSet);
277279
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,28 @@ describe('virtualizer', () => {
224224
expect(firstIndexUpdatesCount).to.equal(1);
225225
});
226226

227+
it('should re-render an unhidden item', async () => {
228+
// Create a virtualizer with just one item (rendered content "foo-0")
229+
let prefix = 'foo-';
230+
const updateElement = (el, index) => (el.textContent = `${prefix}${index}`);
231+
init({ size: 1, updateElement });
232+
233+
// Wait for a possible resize observer flush
234+
await aTimeout(100);
235+
236+
// Reduce the size to 0 (the item gets hidden)
237+
virtualizer.size = 0;
238+
239+
// Update the prefix used by the renderer to "bar-"
240+
prefix = 'bar-';
241+
242+
// Increase the size back to 1
243+
virtualizer.size = 1;
244+
245+
// Expect the unhidden item to be re-rendered with the new prefix even though its index hasn't changed
246+
expect(elementsContainer.firstElementChild.textContent).to.equal('bar-0');
247+
});
248+
227249
it('should have physical items once visible', async () => {
228250
init({ size: 0 });
229251
// Wait for possibly active resize observers to flush

0 commit comments

Comments
 (0)