flow-components icon indicating copy to clipboard operation
flow-components copied to clipboard

Select component uses old instance to refresh item

Open heruan opened this issue 1 year ago • 1 comments

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

heruan avatar Aug 27 '24 12:08 heruan

Might need to be verified in e.g. ComboBox

yuriy-fix avatar Aug 29 '24 11:08 yuriy-fix

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:

  1. Select an option in both the select (above) and the combo box (below).
  2. Click the "Refresh items" button.
  3. Observe that the value is cleared in the select, but not in the combo box.

MatthewVaadin avatar Sep 30 '24 04:09 MatthewVaadin