diff --git a/lib/core_dom/light_dom.dart b/lib/core_dom/light_dom.dart
index 3bb666dad..12c094cc3 100644
--- a/lib/core_dom/light_dom.dart
+++ b/lib/core_dom/light_dom.dart
@@ -24,7 +24,9 @@ class LightDom implements SourceLightDom, DestinationLightDom {
void pullNodes() {
_lightDomRootNodes.addAll(_componentElement.nodes);
+ }
+ void clearComponentElement() {
// This is needed because _lightDomRootNodes can contains viewports,
// which cannot be detached.
final fakeRoot = new dom.DivElement();
diff --git a/lib/core_dom/transcluding_component_factory.dart b/lib/core_dom/transcluding_component_factory.dart
index 71063d862..56e5a21e4 100644
--- a/lib/core_dom/transcluding_component_factory.dart
+++ b/lib/core_dom/transcluding_component_factory.dart
@@ -53,15 +53,14 @@ class BoundTranscludingComponentFactory implements BoundComponentFactory {
var childInjectorCompleter; // Used if the ViewFuture is available before the childInjector.
var component = _component;
- var lightDom = new LightDom(element, scope);
+ var lightDom = new LightDom(element, scope)..pullNodes();
// Append the component's template as children
var elementFuture;
if (_viewFuture != null) {
elementFuture = _viewFuture.then((ViewFactory viewFactory) {
- lightDom.pullNodes();
-
+ lightDom.clearComponentElement();
if (childInjector != null) {
lightDom.shadowDomView = viewFactory.call(childInjector.scope, childInjector);
return element;
@@ -74,7 +73,7 @@ class BoundTranscludingComponentFactory implements BoundComponentFactory {
}
});
} else {
- elementFuture = new async.Future.microtask(() => lightDom.pullNodes());
+ elementFuture = new async.Future.microtask(lightDom.clearComponentElement);
}
TemplateLoader templateLoader = new TemplateLoader(elementFuture);
diff --git a/test/core_dom/compiler_spec.dart b/test/core_dom/compiler_spec.dart
index 08078dd9c..7d06adfff 100644
--- a/test/core_dom/compiler_spec.dart
+++ b/test/core_dom/compiler_spec.dart
@@ -303,7 +303,8 @@ void main() {
..bind(OneTimeDecorator)
..bind(OnceInside)
..bind(OuterShadowless)
- ..bind(InnerShadowy);
+ ..bind(InnerShadowy)
+ ..bind(TemplateUrlComponent);
});
describe("distribution", () {
@@ -467,8 +468,35 @@ void main() {
expect(element).toHaveText('OUTER(INNER(INNERINNER(A,BC)))');
}));
- });
+ it("should not duplicate elements when using components with templateUrl", async((MockHttpBackend backend) {
+ backend.expectGET("${TEST_SERVER_BASE_PREFIX}test/core_dom/template.html").respond(200, "