|
44 | 44 | import com.vaadin.flow.function.SerializableConsumer; |
45 | 45 | import com.vaadin.flow.internal.StateTree.BeforeClientResponseEntry; |
46 | 46 | import com.vaadin.flow.internal.StateTree.ExecutionRegistration; |
| 47 | +import com.vaadin.flow.internal.change.MapPutChange; |
47 | 48 | import com.vaadin.flow.internal.change.NodeAttachChange; |
48 | 49 | import com.vaadin.flow.internal.change.NodeChange; |
49 | 50 | import com.vaadin.flow.internal.change.NodeDetachChange; |
| 51 | +import com.vaadin.flow.internal.nodefeature.ElementAttributeMap; |
50 | 52 | import com.vaadin.flow.internal.nodefeature.ElementData; |
51 | 53 | import com.vaadin.flow.internal.nodefeature.InertData; |
52 | 54 | import com.vaadin.flow.internal.nodefeature.NodeFeature; |
53 | 55 | import com.vaadin.flow.internal.nodefeature.NodeFeatureRegistry; |
| 56 | +import com.vaadin.flow.internal.nodefeature.NodeProperties; |
54 | 57 | import com.vaadin.flow.server.Command; |
55 | 58 | import com.vaadin.flow.shared.Registration; |
56 | 59 |
|
@@ -676,6 +679,7 @@ public void collectChanges(Consumer<NodeChange> collector) { |
676 | 679 | if (hasFeature(ElementData.class)) { |
677 | 680 | doCollectChanges(collector, |
678 | 681 | Stream.of(getFeature(ElementData.class))); |
| 682 | + collectStructuralAttributeChanges(collector); |
679 | 683 | } |
680 | 684 | return; |
681 | 685 | } |
@@ -708,6 +712,30 @@ private void doCollectChanges(Consumer<NodeChange> collector, |
708 | 712 | } |
709 | 713 | } |
710 | 714 |
|
| 715 | + /** |
| 716 | + * Emits only structural attribute changes for invisible elements. This |
| 717 | + * sends a filtered subset of {@link ElementAttributeMap} values to avoid |
| 718 | + * leaking data attributes to the client while preserving attributes needed |
| 719 | + * for CSS selectors. |
| 720 | + * <p> |
| 721 | + * This does not consume the feature's change tracker, so the full attribute |
| 722 | + * set is still available when the element becomes visible and gets fully |
| 723 | + * bound. |
| 724 | + */ |
| 725 | + private void collectStructuralAttributeChanges( |
| 726 | + Consumer<NodeChange> collector) { |
| 727 | + if (!hasFeature(ElementAttributeMap.class)) { |
| 728 | + return; |
| 729 | + } |
| 730 | + ElementAttributeMap attributeMap = getFeature( |
| 731 | + ElementAttributeMap.class); |
| 732 | + String attr = NodeProperties.SLOT_ATTRIBUTE; |
| 733 | + if (attributeMap.has(attr)) { |
| 734 | + collector.accept(new MapPutChange(attributeMap, attr, |
| 735 | + attributeMap.get(attr))); |
| 736 | + } |
| 737 | + } |
| 738 | + |
711 | 739 | private boolean hasChangeTracker(NodeFeature nodeFeature) { |
712 | 740 | return changes != null && changes.containsKey(nodeFeature.getClass()); |
713 | 741 | } |
|
0 commit comments