-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: update rows with __updateVisibleRows() when receiving a page #5733
Conversation
@@ -273,7 +273,7 @@ export const DataProviderMixin = (superClass) => | |||
el.index = index; | |||
const { cache, scaledIndex } = this._cache.getCacheAndIndex(index); | |||
const item = cache.items[scaledIndex]; | |||
if (item) { | |||
if (item !== undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: Without this change, the grid falls into an infinite loop if one of the items is 0
.
data.push({ index: 11 }); | ||
grid.size = newExpectedSize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: This size change triggered an immediate data provider request while the data array was only updated on the following line.
Kudos, SonarCloud Quality Gate passed!
|
@@ -770,7 +770,7 @@ describe('wrapped grid', () => { | |||
|
|||
container.dataProvider = (params, callback) => { | |||
expect(grid.loading).to.be.true; | |||
callback(Array(params.pageSize)); | |||
callback(Array.from({ length: params.pageSize }, (_, i) => i)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: The grid doesn't support using undefined
as an item.
@@ -791,7 +791,7 @@ describe('wrapped grid', () => { | |||
container.dataProvider = (params, callback) => { | |||
cb = callback; | |||
}; | |||
cb(Array(25)); | |||
cb(Array.from({ length: 25 }, (_, i) => i)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: The grid doesn't support using undefined
as an item.
@@ -812,14 +812,14 @@ describe('wrapped grid', () => { | |||
|
|||
it('should clear loading attribute from rows when data received', () => { | |||
container.dataProvider = (params, callback) => { | |||
callback([{}]); | |||
callback([{}], 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: The grid size should be updated when the data provider is going to return fewer items than specified by size
. Otherwise, the virtualizer will always try to request more items than the data provider can provide => infinite loop.
}; | ||
expect(getRows(grid.$.items)[0].hasAttribute('loading')).to.be.false; | ||
}); | ||
|
||
it('should remove loading from cells part attribute when data received', () => { | ||
container.dataProvider = (params, callback) => { | ||
callback([{}]); | ||
callback([{}], 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: The grid size should be updated when the data provider is going to return fewer items than specified by size
. Otherwise, the virtualizer will always try to request more items than the data provider can provide => infinite loop.
@@ -294,7 +294,7 @@ describe('row details', () => { | |||
beforeEach(async () => { | |||
dataset = buildDataSet(10); | |||
grid = fixtureSync(` | |||
<vaadin-grid style="width: 50px; height: 400px" size="100"> | |||
<vaadin-grid style="width: 50px; height: 400px" size="10"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: The grid size didn't match the number of items the data provider actually returned (10).
This ticket/PR has been released with Vaadin 24.1.0.alpha3 and is also targeting the upcoming stable 24.1.0 version. |
Description
There is an
__updateVisibleRows()
method that updates grid rows' content and the related a11y attributes. The custom implementations based onthis._getVisibleRows().forEach(...)
can be replaced with it.Type of change