X Tutup
Skip to content

Commit 92d5658

Browse files
committed
fix(shadow_dom): moves the imported nodes into the correct location.
1 parent 617d693 commit 92d5658

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

modules/angular2/src/render/dom/shadow_dom/emulated_scoped_shadow_dom_strategy.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,21 @@ export class EmulatedScopedShadowDomStrategy extends EmulatedUnscopedShadowDomSt
4646
.then((css) => {
4747
css = shimCssForComponent(css, hostComponentId);
4848
DOM.setText(styleEl, css);
49+
this._moveToStyleHost(styleEl);
4950
});
5051
} else {
5152
var css = shimCssForComponent(<string>inlinedCss, hostComponentId);
5253
DOM.setText(styleEl, css);
53-
DOM.remove(styleEl);
54-
insertStyleElement(this.styleHost, styleEl);
54+
this._moveToStyleHost(styleEl);
5555
return null;
5656
}
5757
}
5858

59+
_moveToStyleHost(styleEl) {
60+
DOM.remove(styleEl);
61+
insertStyleElement(this.styleHost, styleEl);
62+
}
63+
5964
processElement(hostComponentId: string, elementComponentId: string, element) {
6065
// Shim the element as a child of the compiled component
6166
if (isPresent(hostComponentId)) {

modules/angular2/test/render/dom/shadow_dom/emulated_scoped_shadow_dom_strategy_spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,20 @@ export function main() {
9797
expect(DOM.getText(styleElement)).not.toEqual(DOM.getText(styleElement2));
9898
});
9999

100+
it('should move the style element to the style host when @imports are present', inject([AsyncTestCompleter], (async) => {
101+
xhr.reply('http://base/one.css', '.one {}');
102+
103+
var compileElement = el('<div><style>@import "one.css";</style></div>');
104+
var styleElement = DOM.firstChild(compileElement);
105+
var stylePromise = strategy.processStyleElement('someComponent', 'http://base', styleElement);
106+
107+
stylePromise.then((_) => {
108+
expect(compileElement).toHaveText('');
109+
expect(styleHost).toHaveText('.one[_ngcontent-0] {\n\n}');
110+
async.done();
111+
});
112+
}));
113+
100114
it('should move the style element to the style host', () => {
101115
var compileElement = el('<div><style>.one {}</style></div>');
102116
var styleElement = DOM.firstChild(compileElement);

0 commit comments

Comments
 (0)
X Tutup