vaadin / flow

Vaadin Flow is a Java framework binding Vaadin web components to Java. This is part of Vaadin 10+.
Apache License 2.0
618 stars 167 forks source link

Add a warning about attaching the same component twice #4368

Open paulroemer opened 6 years ago

paulroemer commented 6 years ago

We stumbled over an issue with an UIScope'd component (template + Java companion) that we used in two of our templates (sub-templates and referencing it via @Id). Flow did not warn us that the component was attached twice, so we ended up with a fully rendered component at two different places. BUT this.$server was not defined in one of them.

It would be nice if Flow could log a fat warning when something like that happens.

After understanding the reason the fix was quite simple. We just changed the scope of the component so that different instances have been registerred in the DOM.

Legioth commented 6 years ago

Warning (or maybe even throwing) about reattaching should not be triggered in the usual case since it's a completely valid operation to move an element or component from one parent to another. Rather, this special protection logic should only be used in cases with e.g. @Id when the element will still remain in its original location in the DOM since it's an element that is managed by e.g. Polymer in the browser.