|
45 | 45 | import com.vaadin.flow.internal.ExecutionContext; |
46 | 46 | import com.vaadin.flow.internal.JsonUtils; |
47 | 47 | import com.vaadin.flow.internal.NodeOwner; |
| 48 | +import com.vaadin.flow.internal.NullOwner; |
48 | 49 | import com.vaadin.flow.internal.Range; |
49 | 50 | import com.vaadin.flow.internal.StateNode; |
50 | 51 | import com.vaadin.flow.internal.StateTree; |
@@ -115,9 +116,8 @@ public class DataCommunicator<T> implements Serializable { |
115 | 116 |
|
116 | 117 | private Registration dataProviderUpdateRegistration; |
117 | 118 | private HashSet<T> updatedData = new HashSet<>(); |
118 | | - |
119 | | - private SerializableConsumer<ExecutionContext> flushRequest; |
120 | | - private SerializableConsumer<ExecutionContext> flushUpdatedDataRequest; |
| 119 | + private FlushRequest flushRequest; |
| 120 | + private FlushRequest flushUpdatedDataRequest; |
121 | 121 |
|
122 | 122 | private CallbackDataProvider.CountCallback<T, ?> countCallback; |
123 | 123 | private int itemCountEstimate = -1; |
@@ -1093,28 +1093,27 @@ private void requestFlush() { |
1093 | 1093 | } |
1094 | 1094 |
|
1095 | 1095 | private void requestFlush(boolean forced) { |
1096 | | - if ((flushRequest == null || forced) && fetchEnabled) { |
1097 | | - flushRequest = context -> { |
| 1096 | + if ((flushRequest == null || !flushRequest.canExecute(stateNode) |
| 1097 | + || forced) && fetchEnabled) { |
| 1098 | + flushRequest = FlushRequest.register(stateNode, context -> { |
1098 | 1099 | if (!context.isClientSideInitialized()) { |
1099 | 1100 | reset(); |
1100 | 1101 | arrayUpdater.initialize(); |
1101 | 1102 | } |
1102 | 1103 | flush(); |
1103 | 1104 | flushRequest = null; |
1104 | | - }; |
1105 | | - stateNode.runWhenAttached(ui -> ui.getInternals().getStateTree() |
1106 | | - .beforeClientResponse(stateNode, flushRequest)); |
| 1105 | + }); |
1107 | 1106 | } |
1108 | 1107 | } |
1109 | 1108 |
|
1110 | 1109 | private void requestFlushUpdatedData() { |
1111 | | - if (flushUpdatedDataRequest == null) { |
1112 | | - flushUpdatedDataRequest = context -> { |
1113 | | - flushUpdatedData(); |
1114 | | - flushUpdatedDataRequest = null; |
1115 | | - }; |
1116 | | - stateNode.runWhenAttached(ui -> ui.getInternals().getStateTree() |
1117 | | - .beforeClientResponse(stateNode, flushUpdatedDataRequest)); |
| 1110 | + if (flushUpdatedDataRequest == null |
| 1111 | + || !flushUpdatedDataRequest.canExecute(stateNode)) { |
| 1112 | + flushUpdatedDataRequest = FlushRequest.register(stateNode, |
| 1113 | + context -> { |
| 1114 | + flushUpdatedData(); |
| 1115 | + flushUpdatedDataRequest = null; |
| 1116 | + }); |
1118 | 1117 | } |
1119 | 1118 | } |
1120 | 1119 |
|
@@ -1476,6 +1475,27 @@ public static Activation empty() { |
1476 | 1475 | } |
1477 | 1476 | } |
1478 | 1477 |
|
| 1478 | + private static class FlushRequest implements Serializable { |
| 1479 | + |
| 1480 | + private NodeOwner owner; |
| 1481 | + |
| 1482 | + static FlushRequest register(StateNode stateNode, |
| 1483 | + SerializableConsumer<ExecutionContext> action) { |
| 1484 | + FlushRequest request = new FlushRequest(); |
| 1485 | + request.owner = stateNode.getOwner(); |
| 1486 | + stateNode.runWhenAttached(ui -> { |
| 1487 | + request.owner = stateNode.getOwner(); |
| 1488 | + ui.getInternals().getStateTree().beforeClientResponse(stateNode, |
| 1489 | + action); |
| 1490 | + }); |
| 1491 | + return request; |
| 1492 | + } |
| 1493 | + |
| 1494 | + boolean canExecute(StateNode stateNode) { |
| 1495 | + return owner instanceof NullOwner || owner == stateNode.getOwner(); |
| 1496 | + } |
| 1497 | + } |
| 1498 | + |
1479 | 1499 | private static Logger getLogger() { |
1480 | 1500 | return LoggerFactory.getLogger(DataCommunicator.class); |
1481 | 1501 | } |
|
0 commit comments