flow
flow copied to clipboard
getMaximumAllowedItems should have a reasonable minimum
Description of the bug
The getMaximumAllowedItems() algorithm in DataCommunicator should have a reasonable minimum.
The current maximum allowed items / data request is determined with the pattern 10 * pageSize. With a very small page size (like 1), the limit becomes too small and can easily result in missing data.
For example, if you set the Grid's pageSize to be 1, the limit becomes 10 items / request. However, Grid will request enough many pages to try to cover the viewport + some additional padding and this easily exceeds the new safety limit of 10 items.
A reasonable minimum (for example 500 items) should be used in the algorithm so that the maximum is calculated with max((10 * pageSize), 500) instead of (10 * pageSize).
Issue extracted from https://github.com/vaadin/flow-components/issues/3708
Expected behavior
Small page size should not result in too small a limit for maximum allowed items
Minimal reproducible example
var grid = new Grid<Integer>();
grid.setPageSize(1);
grid.addColumn(ValueProvider.identity()).setHeader("Column 1");
grid.setItems(IntStream.range(0, 20).boxed().toArray(Integer[]::new));
add(grid);
results in:

With a warning:
[qtp1663626008-46] WARN com.vaadin.flow.data.provider.DataCommunicator - Attempted to fetch more items from server than allowed in one go: number of items requested '21', maximum items allowed '10'.
Versions
- Vaadin / Flow version: 21.0.4 upwards