Skip to content

Commit

Permalink
fix(platform-browser): insert APP_ID in styles, contentAttr and hostA…
Browse files Browse the repository at this point in the history
…ttr (#17745)

PR Close #17745
  • Loading branch information
petersalomonsen authored and IgorMinar committed Apr 11, 2019
1 parent 3ea8d65 commit 712d60e
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion modules/benchmarks/src/tree/ng2_next/tree.ts
Expand Up @@ -94,7 +94,7 @@ export class AppModule implements Injector, NgModuleRef<any> {
constructor() {
initServicesIfNeeded();
this.sanitizer = new DomSanitizerImpl(document);
this.renderer2 = new DomRendererFactory2(null, null);
this.renderer2 = new DomRendererFactory2(null, null, null);
trustedEmptyColor = this.sanitizer.bypassSecurityTrustStyle('');
trustedGreyColor = this.sanitizer.bypassSecurityTrustStyle('grey');
this.componentFactory =
Expand Down
3 changes: 2 additions & 1 deletion packages/core/test/bundling/todo_r2/todo_e2e_spec.ts
Expand Up @@ -27,7 +27,8 @@ describe('functional test for todo', () => {
const toDoAppComponent = (window as any).toDoAppComponent;
await whenRendered(toDoAppComponent);

const styleContent = findStyleTextForSelector('.todo-list\\\[_ngcontent-\\\w+\\\]');
const styleContent =
findStyleTextForSelector('.todo-list\\\[_ngcontent-[a-z]+-\\\w+\\\]');
expect(styleContent).toMatch(/font-weight:\s*bold;/);
expect(styleContent).toMatch(/color:\s*#d9d9d9;/);
}));
Expand Down
6 changes: 3 additions & 3 deletions packages/core/test/render3/component_spec.ts
Expand Up @@ -348,14 +348,14 @@ describe('encapsulation', () => {
renderComponent(WrapperComponent, {rendererFactory: getRendererFactory2(document)});
expect(containerEl.outerHTML)
.toMatch(
/<div host=""><encapsulated _nghost-c(\d+)="">foo<leaf _ngcontent-c\1=""><span>bar<\/span><\/leaf><\/encapsulated><\/div>/);
/<div host=""><encapsulated _nghost-[a-z]+-c(\d+)="">foo<leaf _ngcontent-[a-z]+-c\1=""><span>bar<\/span><\/leaf><\/encapsulated><\/div>/);
});

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

it('should encapsulate host and children with different attributes', () => {
Expand Down Expand Up @@ -401,7 +401,7 @@ describe('encapsulation', () => {
renderComponent(WrapperComponentWith, {rendererFactory: getRendererFactory2(document)});
expect(containerEl.outerHTML)
.toMatch(
/<div host="" _nghost-c(\d+)=""><leaf _ngcontent-c\1="" _nghost-c(\d+)=""><span _ngcontent-c\2="">bar<\/span><\/leaf><\/div>/);
/<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>/);
});

});
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/render3/imported_renderer2.ts
Expand Up @@ -35,7 +35,7 @@ export function getRendererFactory2(document: any): RendererFactory2 {
const fakeNgZone: NgZone = new NoopNgZone();
const eventManager = new EventManager([new SimpleDomEventsPlugin(document)], fakeNgZone);
const rendererFactory =
new ɵDomRendererFactory2(eventManager, new ɵDomSharedStylesHost(document));
new ɵDomRendererFactory2(eventManager, new ɵDomSharedStylesHost(document), 'dummyappid');
const origCreateRenderer = rendererFactory.createRenderer;
rendererFactory.createRenderer = function() {
const renderer = origCreateRenderer.apply(this, arguments);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/render3/providers_spec.ts
Expand Up @@ -1123,7 +1123,7 @@ describe('providers', () => {
fixture.update();
expect(fixture.html)
.toMatch(
/<host-cmp>foo<\/host-cmp><embedded-cmp _nghost-c(\d+)="">From module injector<\/embedded-cmp>/);
/<host-cmp>foo<\/host-cmp><embedded-cmp _nghost-[a-z]+-c(\d+)="">From module injector<\/embedded-cmp>/);
});

it('should cross the root view boundary to the parent of the host, thanks to the default root view injector',
Expand Down
2 changes: 1 addition & 1 deletion packages/platform-browser/src/browser.ts
Expand Up @@ -80,7 +80,7 @@ export const BROWSER_MODULE_PROVIDERS: StaticProvider[] = [
{
provide: DomRendererFactory2,
useClass: DomRendererFactory2,
deps: [EventManager, DomSharedStylesHost]
deps: [EventManager, DomSharedStylesHost, APP_ID]
},
{provide: RendererFactory2, useExisting: DomRendererFactory2},
{provide: SharedStylesHost, useExisting: DomSharedStylesHost},
Expand Down
18 changes: 10 additions & 8 deletions packages/platform-browser/src/dom/dom_renderer.ts
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

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

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

constructor(private eventManager: EventManager, private sharedStylesHost: DomSharedStylesHost) {
constructor(
private eventManager: EventManager, private sharedStylesHost: DomSharedStylesHost,
@Inject(APP_ID) private appId: string) {
this.defaultRenderer = new DefaultDomRenderer2(eventManager);
}

Expand All @@ -75,8 +77,8 @@ export class DomRendererFactory2 implements RendererFactory2 {
case ViewEncapsulation.Emulated: {
let renderer = this.rendererByCompId.get(type.id);
if (!renderer) {
renderer =
new EmulatedEncapsulationDomRenderer2(this.eventManager, this.sharedStylesHost, type);
renderer = new EmulatedEncapsulationDomRenderer2(
this.eventManager, this.sharedStylesHost, type, this.appId);
this.rendererByCompId.set(type.id, renderer);
}
(<EmulatedEncapsulationDomRenderer2>renderer).applyToHost(element);
Expand Down Expand Up @@ -243,13 +245,13 @@ class EmulatedEncapsulationDomRenderer2 extends DefaultDomRenderer2 {

constructor(
eventManager: EventManager, sharedStylesHost: DomSharedStylesHost,
private component: RendererType2) {
private component: RendererType2, appId: string) {
super(eventManager);
const styles = flattenStyles(component.id, component.styles, []);
const styles = flattenStyles(appId + '-' + component.id, component.styles, []);
sharedStylesHost.addStyles(styles);

this.contentAttr = shimContentAttribute(component.id);
this.hostAttr = shimHostAttribute(component.id);
this.contentAttr = shimContentAttribute(appId + '-' + component.id);
this.hostAttr = shimHostAttribute(appId + '-' + component.id);
}

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

0 comments on commit 712d60e

Please sign in to comment.