Skip to content

Commit 712d60e

Browse files
petersalomonsenIgorMinar
authored andcommittedApr 11, 2019
fix(platform-browser): insert APP_ID in styles, contentAttr and hostAttr (#17745)
PR Close #17745
1 parent 3ea8d65 commit 712d60e

File tree

7 files changed

+19
-16
lines changed

7 files changed

+19
-16
lines changed
 

‎modules/benchmarks/src/tree/ng2_next/tree.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export class AppModule implements Injector, NgModuleRef<any> {
9494
constructor() {
9595
initServicesIfNeeded();
9696
this.sanitizer = new DomSanitizerImpl(document);
97-
this.renderer2 = new DomRendererFactory2(null, null);
97+
this.renderer2 = new DomRendererFactory2(null, null, null);
9898
trustedEmptyColor = this.sanitizer.bypassSecurityTrustStyle('');
9999
trustedGreyColor = this.sanitizer.bypassSecurityTrustStyle('grey');
100100
this.componentFactory =

‎packages/core/test/bundling/todo_r2/todo_e2e_spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ describe('functional test for todo', () => {
2727
const toDoAppComponent = (window as any).toDoAppComponent;
2828
await whenRendered(toDoAppComponent);
2929

30-
const styleContent = findStyleTextForSelector('.todo-list\\\[_ngcontent-\\\w+\\\]');
30+
const styleContent =
31+
findStyleTextForSelector('.todo-list\\\[_ngcontent-[a-z]+-\\\w+\\\]');
3132
expect(styleContent).toMatch(/font-weight:\s*bold;/);
3233
expect(styleContent).toMatch(/color:\s*#d9d9d9;/);
3334
}));

‎packages/core/test/render3/component_spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -348,14 +348,14 @@ describe('encapsulation', () => {
348348
renderComponent(WrapperComponent, {rendererFactory: getRendererFactory2(document)});
349349
expect(containerEl.outerHTML)
350350
.toMatch(
351-
/<div host=""><encapsulated _nghost-c(\d+)="">foo<leaf _ngcontent-c\1=""><span>bar<\/span><\/leaf><\/encapsulated><\/div>/);
351+
/<div host=""><encapsulated _nghost-[a-z]+-c(\d+)="">foo<leaf _ngcontent-[a-z]+-c\1=""><span>bar<\/span><\/leaf><\/encapsulated><\/div>/);
352352
});
353353

354354
it('should encapsulate host', () => {
355355
renderComponent(EncapsulatedComponent, {rendererFactory: getRendererFactory2(document)});
356356
expect(containerEl.outerHTML)
357357
.toMatch(
358-
/<div host="" _nghost-c(\d+)="">foo<leaf _ngcontent-c\1=""><span>bar<\/span><\/leaf><\/div>/);
358+
/<div host="" _nghost-[a-z]+-c(\d+)="">foo<leaf _ngcontent-[a-z]+-c\1=""><span>bar<\/span><\/leaf><\/div>/);
359359
});
360360

361361
it('should encapsulate host and children with different attributes', () => {
@@ -401,7 +401,7 @@ describe('encapsulation', () => {
401401
renderComponent(WrapperComponentWith, {rendererFactory: getRendererFactory2(document)});
402402
expect(containerEl.outerHTML)
403403
.toMatch(
404-
/<div host="" _nghost-c(\d+)=""><leaf _ngcontent-c\1="" _nghost-c(\d+)=""><span _ngcontent-c\2="">bar<\/span><\/leaf><\/div>/);
404+
/<div host="" _nghost-[a-z]+-c(\d+)=""><leaf _ngcontent-[a-z]+-c\1="" _nghost-[a-z]+-c(\d+)=""><span _ngcontent-[a-z]+-c\2="">bar<\/span><\/leaf><\/div>/);
405405
});
406406

407407
});

‎packages/core/test/render3/imported_renderer2.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function getRendererFactory2(document: any): RendererFactory2 {
3535
const fakeNgZone: NgZone = new NoopNgZone();
3636
const eventManager = new EventManager([new SimpleDomEventsPlugin(document)], fakeNgZone);
3737
const rendererFactory =
38-
new ɵDomRendererFactory2(eventManager, new ɵDomSharedStylesHost(document));
38+
new ɵDomRendererFactory2(eventManager, new ɵDomSharedStylesHost(document), 'dummyappid');
3939
const origCreateRenderer = rendererFactory.createRenderer;
4040
rendererFactory.createRenderer = function() {
4141
const renderer = origCreateRenderer.apply(this, arguments);

‎packages/core/test/render3/providers_spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ describe('providers', () => {
11231123
fixture.update();
11241124
expect(fixture.html)
11251125
.toMatch(
1126-
/<host-cmp>foo<\/host-cmp><embedded-cmp _nghost-c(\d+)="">From module injector<\/embedded-cmp>/);
1126+
/<host-cmp>foo<\/host-cmp><embedded-cmp _nghost-[a-z]+-c(\d+)="">From module injector<\/embedded-cmp>/);
11271127
});
11281128

11291129
it('should cross the root view boundary to the parent of the host, thanks to the default root view injector',

‎packages/platform-browser/src/browser.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export const BROWSER_MODULE_PROVIDERS: StaticProvider[] = [
8080
{
8181
provide: DomRendererFactory2,
8282
useClass: DomRendererFactory2,
83-
deps: [EventManager, DomSharedStylesHost]
83+
deps: [EventManager, DomSharedStylesHost, APP_ID]
8484
},
8585
{provide: RendererFactory2, useExisting: DomRendererFactory2},
8686
{provide: SharedStylesHost, useExisting: DomSharedStylesHost},

‎packages/platform-browser/src/dom/dom_renderer.ts

+10-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Injectable, Renderer2, RendererFactory2, RendererStyleFlags2, RendererType2, ViewEncapsulation} from '@angular/core';
9+
import {APP_ID, Inject, Injectable, Renderer2, RendererFactory2, RendererStyleFlags2, RendererType2, ViewEncapsulation} from '@angular/core';
1010

1111
import {EventManager} from './events/event_manager';
1212
import {DomSharedStylesHost} from './shared_styles_host';
@@ -63,7 +63,9 @@ export class DomRendererFactory2 implements RendererFactory2 {
6363
private rendererByCompId = new Map<string, Renderer2>();
6464
private defaultRenderer: Renderer2;
6565

66-
constructor(private eventManager: EventManager, private sharedStylesHost: DomSharedStylesHost) {
66+
constructor(
67+
private eventManager: EventManager, private sharedStylesHost: DomSharedStylesHost,
68+
@Inject(APP_ID) private appId: string) {
6769
this.defaultRenderer = new DefaultDomRenderer2(eventManager);
6870
}
6971

@@ -75,8 +77,8 @@ export class DomRendererFactory2 implements RendererFactory2 {
7577
case ViewEncapsulation.Emulated: {
7678
let renderer = this.rendererByCompId.get(type.id);
7779
if (!renderer) {
78-
renderer =
79-
new EmulatedEncapsulationDomRenderer2(this.eventManager, this.sharedStylesHost, type);
80+
renderer = new EmulatedEncapsulationDomRenderer2(
81+
this.eventManager, this.sharedStylesHost, type, this.appId);
8082
this.rendererByCompId.set(type.id, renderer);
8183
}
8284
(<EmulatedEncapsulationDomRenderer2>renderer).applyToHost(element);
@@ -243,13 +245,13 @@ class EmulatedEncapsulationDomRenderer2 extends DefaultDomRenderer2 {
243245

244246
constructor(
245247
eventManager: EventManager, sharedStylesHost: DomSharedStylesHost,
246-
private component: RendererType2) {
248+
private component: RendererType2, appId: string) {
247249
super(eventManager);
248-
const styles = flattenStyles(component.id, component.styles, []);
250+
const styles = flattenStyles(appId + '-' + component.id, component.styles, []);
249251
sharedStylesHost.addStyles(styles);
250252

251-
this.contentAttr = shimContentAttribute(component.id);
252-
this.hostAttr = shimHostAttribute(component.id);
253+
this.contentAttr = shimContentAttribute(appId + '-' + component.id);
254+
this.hostAttr = shimHostAttribute(appId + '-' + component.id);
253255
}
254256

255257
applyToHost(element: any) { super.setAttribute(element, this.hostAttr, ''); }

0 commit comments

Comments
 (0)
Please sign in to comment.