Skip to content

Commit

Permalink
fix: ensure virtualizer re-renders unhidden items (#3081) (#3083)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaadin-bot committed Nov 18, 2021
1 parent d231f6e commit cec9659
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/component-base/src/virtualizer-iron-list-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ export class IronListAdapter {
if (!el.hidden) {
el.__virtualIndex = vidx + (this._vidxOffset || 0);
this.__updateElement(el, el.__virtualIndex);
} else {
delete el.__lastUpdatedIndex;
}
}, itemSet);
}
Expand Down
22 changes: 22 additions & 0 deletions packages/component-base/test/virtualizer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,28 @@ describe('virtualizer', () => {
expect(firstIndexUpdatesCount).to.equal(1);
});

it('should re-render an unhidden item', async () => {
// Create a virtualizer with just one item (rendered content "foo-0")
let prefix = 'foo-';
const updateElement = (el, index) => (el.textContent = `${prefix}${index}`);
init({ size: 1, updateElement });

// Wait for a possible resize observer flush
await aTimeout(100);

// Reduce the size to 0 (the item gets hidden)
virtualizer.size = 0;

// Update the prefix used by the renderer to "bar-"
prefix = 'bar-';

// Increase the size back to 1
virtualizer.size = 1;

// Expect the unhidden item to be re-rendered with the new prefix even though its index hasn't changed
expect(elementsContainer.firstElementChild.textContent).to.equal('bar-0');
});

it('should have physical items once visible', async () => {
init({ size: 0 });
// Wait for possibly active resize observers to flush
Expand Down

0 comments on commit cec9659

Please sign in to comment.