Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 2e40350

Browse files
pavelgjmhevery
authored andcommitted
fix(block_factory): should not load template or call onShadowRoot when scope is destroyed
1 parent 72708e3 commit 2e40350

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

lib/core_dom/block_factory.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,13 +356,19 @@ class _ComponentFactory {
356356
shadowDom.setInnerHtml('<style>${filteredCssList.join('')}</style>', treeSanitizer: treeSanitizer);
357357
}
358358
if (blockFuture != null) {
359-
return blockFuture.then((BlockFactory blockFactory) => attachBlockToShadowDom(blockFactory));
359+
return blockFuture.then((BlockFactory blockFactory) {
360+
if (!shadowScope.isAttached) return shadowDom;
361+
return attachBlockToShadowDom(blockFactory);
362+
});
360363
}
361364
return shadowDom;
362365
}));
363366
controller = createShadowInjector(injector, templateLoader).get(type);
364367
if (controller is NgShadowRootAware) {
365-
templateLoader.template.then((controller as NgShadowRootAware).onShadowRoot);
368+
templateLoader.template.then((_) {
369+
if (!shadowScope.isAttached) return;
370+
(controller as NgShadowRootAware).onShadowRoot(shadowDom);
371+
});
366372
}
367373
return controller;
368374
}

test/core_dom/compiler_spec.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,14 +484,16 @@ main() => describe('dte.compiler', () {
484484
expect(element.textWithShadow()).toEqual('WORKED');
485485
})));
486486

487-
it('should should not call attach after scope is destroyed', async(inject((Logger logger) {
487+
it('should should not call attach after scope is destroyed', async(inject((Logger logger, MockHttpBackend backend) {
488+
backend.whenGET('foo.html').respond('<div>WORKED</div>');
488489
var element = $('<simple-attach></simple-attach>');
489490
var scope = rootScope.createChild({});
490491
$compile(element, directives)(injector.createChild([new Module()..value(Scope, scope)]), element);
491492
expect(logger).toEqual(['SimpleAttachComponent']);
492493
scope.destroy();
493494

494495
rootScope.apply();
496+
microLeap();
495497

496498
expect(logger).toEqual(['SimpleAttachComponent']);
497499
})));
@@ -857,11 +859,14 @@ class ExprAttrComponent {
857859
}
858860
}
859861

860-
@NgComponent(selector: 'simple-attach')
861-
class SimpleAttachComponent implements NgAttachAware {
862+
@NgComponent(
863+
selector: 'simple-attach',
864+
templateUrl: 'foo.html')
865+
class SimpleAttachComponent implements NgAttachAware, NgShadowRootAware {
862866
Logger logger;
863867
SimpleAttachComponent(this.logger) {
864868
logger('SimpleAttachComponent');
865869
}
866870
attach() => logger('attach');
871+
onShadowRoot(_) => logger('onShadowRoot');
867872
}

0 commit comments

Comments
 (0)