Select component uses old instance to refresh item
Description
When Select reacts to a DataChangeEvent (i.e. DataProvider.refresh(item)) the callback does not take into account the new item instance but it just re-render the existing instance.
See in https://github.com/vaadin/flow-components/blob/700058106ddc1e9792016dc98e9d1c49e8410b9a/vaadin-select-flow-parent/vaadin-select-flow/src/main/java/com/vaadin/flow/component/select/Select.java#L1017-L1030
The updatedItem is only used to find the corresponding existing vaadinItem and then the updateItem is invoked with the existing vaadinItem instance, so that if anything has changed in updatedItem it’s just ignored.
Expected outcome
Upon DataChangeEvent the new data is used to update the item.
Minimal reproducible example
var select = new Select("Test");
select.setDataProvider(dp);
dp.refreshItem(newItem);
Steps to reproduce
The data provider needs to override the getId method so that the newItem instance matches an existing item, but the update still uses the old instance.
Environment
Vaadin version(s): 24.5.0.alpha10
Browsers
No response
Might need to be verified in e.g. ComboBox
There is possibly another issue with the onDataChange method. When a refreshAll() is called on the data provider, the select is reset (the else branch), which includes clearing the selected value. I would expect the selected value to remain selected if the value still exists. This is what happens with a combo box.
See minimal example here: https://github.com/MatthewVaadin/refresh-select
Steps to reproduce:
- Select an option in both the select (above) and the combo box (below).
- Click the "Refresh items" button.
- Observe that the value is cleared in the select, but not in the combo box.