Skip to content

Commit f563bfd

Browse files
authored
refactor: remove usage of Flow component renderer from Popover (#7791)
1 parent 294d17e commit f563bfd

3 files changed

Lines changed: 0 additions & 314 deletions

File tree

  • vaadin-ordered-layout-flow-parent/vaadin-ordered-layout-flow-integration-tests
  • vaadin-popover-flow-parent/vaadin-popover-flow/src

vaadin-ordered-layout-flow-parent/vaadin-ordered-layout-flow-integration-tests/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,6 @@
8080
<version>${project.version}</version>
8181
<scope>test</scope>
8282
</dependency>
83-
<dependency>
84-
<groupId>com.vaadin</groupId>
85-
<artifactId>vaadin-renderer-flow</artifactId>
86-
<version>${project.version}</version>
87-
</dependency>
8883
<dependency>
8984
<groupId>com.vaadin</groupId>
9085
<artifactId>vaadin-testbench-core</artifactId>

vaadin-popover-flow-parent/vaadin-popover-flow/src/main/java/com/vaadin/flow/component/popover/Popover.java

Lines changed: 0 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,10 @@
1616
package com.vaadin.flow.component.popover;
1717

1818
import java.util.Arrays;
19-
import java.util.Collection;
20-
import java.util.HashMap;
21-
import java.util.Map;
2219
import java.util.Objects;
2320
import java.util.Optional;
2421
import java.util.concurrent.atomic.AtomicBoolean;
25-
import java.util.stream.Collectors;
2622

27-
import com.vaadin.flow.component.AttachEvent;
2823
import com.vaadin.flow.component.Component;
2924
import com.vaadin.flow.component.ComponentEvent;
3025
import com.vaadin.flow.component.ComponentEventListener;
@@ -40,9 +35,6 @@
4035
import com.vaadin.flow.component.shared.HasThemeVariant;
4136
import com.vaadin.flow.component.shared.internal.OverlayClassListProxy;
4237
import com.vaadin.flow.dom.ClassList;
43-
import com.vaadin.flow.dom.Element;
44-
import com.vaadin.flow.dom.ElementDetachEvent;
45-
import com.vaadin.flow.dom.ElementDetachListener;
4638
import com.vaadin.flow.dom.Style;
4739
import com.vaadin.flow.server.VaadinService;
4840
import com.vaadin.flow.shared.Registration;
@@ -82,8 +74,6 @@ public class Popover extends Component implements HasAriaLabel, HasComponents,
8274
* Constructs an empty popover.
8375
*/
8476
public Popover() {
85-
getElement().getNode().addAttachListener(this::attachComponentRenderer);
86-
8777
// Workaround for: https://github.com/vaadin/flow/issues/3496
8878
getElement().setProperty("opened", false);
8979

@@ -771,110 +761,6 @@ public void setHeight(String height) {
771761
getElement().setProperty("contentHeight", height);
772762
}
773763

774-
/**
775-
* Adds the given components into this popover.
776-
* <p>
777-
* The elements in the DOM will not be children of the
778-
* {@code <vaadin-popover>} element, but will be inserted into an overlay
779-
* that is attached into the {@code <body>}.
780-
*
781-
* @param components
782-
* the components to add
783-
*/
784-
@Override
785-
public void add(Collection<Component> components) {
786-
HasComponents.super.add(components);
787-
788-
updateVirtualChildNodeIds();
789-
}
790-
791-
/**
792-
* Adds the given component into this popover at the given index.
793-
* <p>
794-
* The element in the DOM will not be child of the {@code <vaadin-popover>}
795-
* element, but will be inserted into an overlay that is attached into the
796-
* {@code <body>}.
797-
*
798-
* @param index
799-
* the index, where the component will be added.
800-
*
801-
* @param component
802-
* the component to add
803-
*/
804-
@Override
805-
public void addComponentAtIndex(int index, Component component) {
806-
HasComponents.super.addComponentAtIndex(index, component);
807-
808-
updateVirtualChildNodeIds();
809-
}
810-
811-
private void attachComponentRenderer() {
812-
getElement().executeJs(
813-
"Vaadin.FlowComponentHost.patchVirtualContainer(this)");
814-
815-
String appId = UI.getCurrent().getInternals().getAppId();
816-
817-
getElement().executeJs(
818-
"this.renderer = (root) => Vaadin.FlowComponentHost.setChildNodes($0, this.virtualChildNodeIds, root)",
819-
appId);
820-
}
821-
822-
private Map<Element, Registration> childDetachListenerMap = new HashMap<>();
823-
824-
// Must not use lambda here as that would break serialization. See
825-
// https://github.com/vaadin/flow-components/issues/5597
826-
private ElementDetachListener childDetachListener = new ElementDetachListener() {
827-
@Override
828-
public void onDetach(ElementDetachEvent e) {
829-
var child = e.getSource();
830-
var childDetachedFromContainer = !getElement().getChildren()
831-
.anyMatch(containerChild -> Objects.equals(child,
832-
containerChild));
833-
834-
if (childDetachedFromContainer) {
835-
// The child was removed from the popover
836-
837-
// Remove the registration for the child detach listener
838-
childDetachListenerMap.get(child).remove();
839-
childDetachListenerMap.remove(child);
840-
841-
updateVirtualChildNodeIds();
842-
}
843-
}
844-
};
845-
846-
@Override
847-
protected void onAttach(AttachEvent attachEvent) {
848-
super.onAttach(attachEvent);
849-
850-
updateVirtualChildNodeIds();
851-
}
852-
853-
/**
854-
* Updates the virtualChildNodeIds property of the popover element.
855-
* <p>
856-
* This method is called whenever the popover's child components change.
857-
* <p>
858-
* Also calls {@code requestContentUpdate} on the popover element to trigger
859-
* the content update.
860-
*/
861-
private void updateVirtualChildNodeIds() {
862-
// Add detach listeners (child may be removed with removeFromParent())
863-
getElement().getChildren().forEach(child -> {
864-
if (!childDetachListenerMap.containsKey(child)) {
865-
childDetachListenerMap.put(child,
866-
child.addDetachListener(childDetachListener));
867-
}
868-
});
869-
870-
getElement().setPropertyList("virtualChildNodeIds",
871-
getElement().getChildren()
872-
.map(element -> element.getNode().getId())
873-
.collect(Collectors.toList()));
874-
875-
getElement().callJsFunction("requestContentUpdate");
876-
}
877-
878764
/**
879765
* Sets the CSS class names of the popover overlay element. This method
880766
* overwrites any previous set class names.

vaadin-popover-flow-parent/vaadin-popover-flow/src/test/java/com/vaadin/flow/component/popover/PopoverChildrenTest.java

Lines changed: 0 additions & 195 deletions
This file was deleted.

0 commit comments

Comments
 (0)