Skip to content

Commit 30f8aaf

Browse files
authored
fix: do not deactivate expanded item keys (#19006) (#19047)
* fix: do not deactivate expanded item keys (#19006) * if unique key provider exists, remove items normally
1 parent 43447ae commit 30f8aaf

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

flow-data/src/main/java/com/vaadin/flow/data/provider/hierarchy/HierarchicalCommunicationController.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ public class HierarchicalCommunicationController<T> implements Serializable {
7979
// Update ids that have been confirmed since the last flush
8080
private final HashSet<Integer> confirmedUpdates = new HashSet<>();
8181

82+
private boolean hasUniqueKeyProviderSupplier;
83+
8284
/**
8385
* Constructs communication controller with support for hierarchical data
8486
* structure.
@@ -319,7 +321,8 @@ private void doUnregister(Integer updateId) {
319321
if (passivated != null) {
320322
passivated.forEach(key -> {
321323
T item = keyMapper.get(key);
322-
if (item != null) {
324+
if (item != null && (hasUniqueKeyProviderSupplier
325+
|| !mapper.isExpanded(item))) {
323326
dataGenerator.destroyData(item);
324327
keyMapper.remove(item);
325328
}
@@ -341,6 +344,11 @@ public JsonValue generateJson(T item) {
341344
return json;
342345
}
343346

347+
public void setHasUniqueKeyProviderSupplier(
348+
boolean hasUniqueKeyProviderSupplier) {
349+
this.hasUniqueKeyProviderSupplier = hasUniqueKeyProviderSupplier;
350+
}
351+
344352
private static final void withMissing(Range expected, Range actual,
345353
Consumer<Range> action) {
346354
Range[] partition = expected.partitionWith(actual);

flow-data/src/main/java/com/vaadin/flow/data/provider/hierarchy/HierarchicalDataCommunicator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ parentKey, getKeyMapper(), mapper,
196196
.startUpdate(getDataProviderSize()),
197197
(pkey, range) -> mapper.fetchChildItems(
198198
getKeyMapper().get(pkey), range)));
199-
199+
controller.setHasUniqueKeyProviderSupplier(
200+
uniqueKeyProviderSupplier.get() != null);
200201
Range range = computeRequestedRange(start, length);
201202
controller.setRequestRange(range.getStart(), range.length());
202203
requestFlush(controller);

0 commit comments

Comments
 (0)