Scenario contact: @ilonatommy
Scenario
A virtualized list that loads items on demand can make the viewport jump when the underlying data changes, and the cause is hard to trace: the component cannot tell one item from another, so it cannot work out whether items arrived before or after what the user is looking at. This validates that the build now warns about it, and that following the advice actually fixes the behavior.
Minimum build
.NET 11 Preview 7 or later.
Configurations to cover
These diagnostics are produced by the compiler, so they do not vary by render mode. The configuration below is the one needed to reproduce the runtime behavior the warning predicts, not a matrix to work through.
Also exercise
Setup
The diagnostic this scenario covers is:
| Id |
Title |
Code fix |
BL0011 |
Virtualize with ItemsProvider requires ItemComparer |
No |
What to build
A page with a long virtualized list whose items come from an ItemsProvider, so that you can insert items at the top and at the bottom while the user is scrolled into the middle of the list. Write it first without setting ItemComparer, and make the item type a class rather than a record, since the default comparer falls back to reference equality for classes and that is what the warning is about.
Add controls to insert items above and below the visible range, and show each item's index so you can tell where the viewport ended up.
Things to try
- Building at the command line and in an IDE, and reading the messages that appear.
- Scrolling into the middle of the list and then adding items above and below the visible range.
- Setting
ItemComparer, then repeating the scrolling test.
- A
Virtualize that supplies Items directly rather than through ItemsProvider, to see whether it is flagged.
- An item type that is a record rather than a class, to see whether that changes the warning.
- The same list rendered through
QuickGrid rather than Virtualize.
Expected behavior
The problem is reported at build time, and setting ItemComparer fixes the runtime behavior the warning predicted.
Must hold
- The list written without
ItemComparer produces a BL0011 warning at the correct line.
- Before
ItemComparer is set, inserting items above the visible range moves the scroll position.
- After
ItemComparer is set, the list keeps its scroll position when items are inserted above the visible range.
- A
Virtualize that supplies Items directly, rather than through ItemsProvider, produces no BL0011 warning.
- The warning appears both at the command line and in the IDE, at the same line.
Expected differences between configurations
- None. The warning is produced at compile time and is identical in every configuration.
Documentation to use
What to report
Report results using the format described in the validation testing manual. Include link to a repository with the test app.
Scenario contact: @ilonatommy
Scenario
A virtualized list that loads items on demand can make the viewport jump when the underlying data changes, and the cause is hard to trace: the component cannot tell one item from another, so it cannot work out whether items arrived before or after what the user is looking at. This validates that the build now warns about it, and that following the advice actually fixes the behavior.
Minimum build
.NET 11 Preview 7 or later.
Configurations to cover
These diagnostics are produced by the compiler, so they do not vary by render mode. The configuration below is the one needed to reproduce the runtime behavior the warning predicts, not a matrix to work through.
Also exercise
Setup
The diagnostic this scenario covers is:
BL0011VirtualizewithItemsProviderrequiresItemComparerWhat to build
A page with a long virtualized list whose items come from an
ItemsProvider, so that you can insert items at the top and at the bottom while the user is scrolled into the middle of the list. Write it first without settingItemComparer, and make the item type a class rather than a record, since the default comparer falls back to reference equality for classes and that is what the warning is about.Add controls to insert items above and below the visible range, and show each item's index so you can tell where the viewport ended up.
Things to try
ItemComparer, then repeating the scrolling test.Virtualizethat suppliesItemsdirectly rather than throughItemsProvider, to see whether it is flagged.QuickGridrather thanVirtualize.Expected behavior
The problem is reported at build time, and setting
ItemComparerfixes the runtime behavior the warning predicted.Must hold
ItemComparerproduces aBL0011warning at the correct line.ItemCompareris set, inserting items above the visible range moves the scroll position.ItemCompareris set, the list keeps its scroll position when items are inserted above the visible range.Virtualizethat suppliesItemsdirectly, rather than throughItemsProvider, produces noBL0011warning.Expected differences between configurations
Documentation to use
What to report
Report results using the format described in the validation testing manual. Include link to a repository with the test app.