fix(ivy): only generate TViews once per embedded template (#23385)
PR Close #23385
This commit is contained in:

committed by
Igor Minar

parent
b76f5a6a7d
commit
c5cfc3a1b6
@ -102,18 +102,18 @@ describe('instructions', () => {
|
||||
elementStart(0, 'div', ['style', 'height: 10px']);
|
||||
elementEnd();
|
||||
}
|
||||
const fixture = new TemplateFixture(createDivWithStyle);
|
||||
|
||||
it('should add style', () => {
|
||||
const fixture = new TemplateFixture(createDivWithStyle);
|
||||
fixture.update(() => elementStyle(0, {'background-color': 'red'}));
|
||||
expect(fixture.html).toEqual('<div style="height: 10px; background-color: red;"></div>');
|
||||
});
|
||||
});
|
||||
|
||||
describe('elementClass', () => {
|
||||
const fixture = new TemplateFixture(createDiv);
|
||||
|
||||
it('should add class', () => {
|
||||
const fixture = new TemplateFixture(createDiv);
|
||||
fixture.update(() => elementClass(0, 'multiple classes'));
|
||||
expect(fixture.html).toEqual('<div class="multiple classes"></div>');
|
||||
});
|
||||
@ -132,34 +132,34 @@ describe('instructions', () => {
|
||||
|
||||
static ngComponentDef = defineComponent({
|
||||
type: NestedLoops,
|
||||
selectors: [['todo-app']],
|
||||
selectors: [['nested-loops']],
|
||||
factory: function ToDoAppComponent_Factory() { return new NestedLoops(); },
|
||||
template: function ToDoAppComponent_Template(rf: RenderFlags, ctx: NestedLoops) {
|
||||
if (rf & 1) {
|
||||
if (rf & RenderFlags.Create) {
|
||||
container(0, ToDoAppComponent_NgForOf_Template_0, null, _c0);
|
||||
}
|
||||
if (rf & 2) {
|
||||
if (rf & RenderFlags.Update) {
|
||||
elementProperty(0, 'ngForOf', bind(ctx.rows));
|
||||
}
|
||||
function ToDoAppComponent_NgForOf_Template_0(
|
||||
rf: RenderFlags, ctx0: NgForOfContext<any>) {
|
||||
if (rf & 1) {
|
||||
if (rf & RenderFlags.Create) {
|
||||
elementStart(0, 'ul');
|
||||
container(1, ToDoAppComponent_NgForOf_NgForOf_Template_1, null, _c0);
|
||||
elementEnd();
|
||||
}
|
||||
if (rf & 2) {
|
||||
if (rf & RenderFlags.Update) {
|
||||
const row_r2 = ctx0.$implicit;
|
||||
elementProperty(1, 'ngForOf', bind(row_r2));
|
||||
}
|
||||
function ToDoAppComponent_NgForOf_NgForOf_Template_1(
|
||||
rf: RenderFlags, ctx1: NgForOfContext<any>) {
|
||||
if (rf & 1) {
|
||||
if (rf & RenderFlags.Create) {
|
||||
elementStart(0, 'li');
|
||||
text(1);
|
||||
elementEnd();
|
||||
}
|
||||
if (rf & 2) {
|
||||
if (rf & RenderFlags.Update) {
|
||||
const col_r3 = ctx1.$implicit;
|
||||
textBinding(1, interpolation1('', col_r3, ''));
|
||||
}
|
||||
@ -171,8 +171,8 @@ describe('instructions', () => {
|
||||
}
|
||||
const fixture = new ComponentFixture(NestedLoops);
|
||||
expect(ngDevMode).toHaveProperties({
|
||||
// Expect: host view + component + *ngForRow + *ngForCol
|
||||
tView: 7, // should be: 4,
|
||||
// Expect: fixture view/Host view + component + ngForRow + ngForCol
|
||||
tView: 4, // should be: 4,
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -830,7 +830,7 @@ describe('render3 integration test', () => {
|
||||
|
||||
const oldTemplateData = (Template as any).ngPrivateData;
|
||||
const oldContainerData = (oldTemplateData as any).data[0];
|
||||
const oldElementData = oldContainerData.data[0][0];
|
||||
const oldElementData = oldContainerData.tViews[0][0];
|
||||
expect(oldContainerData).not.toBeNull();
|
||||
expect(oldElementData).not.toBeNull();
|
||||
|
||||
@ -839,7 +839,7 @@ describe('render3 integration test', () => {
|
||||
|
||||
const newTemplateData = (Template as any).ngPrivateData;
|
||||
const newContainerData = (oldTemplateData as any).data[0];
|
||||
const newElementData = oldContainerData.data[0][0];
|
||||
const newElementData = oldContainerData.tViews[0][0];
|
||||
expect(newTemplateData === oldTemplateData).toBe(true);
|
||||
expect(newContainerData === oldContainerData).toBe(true);
|
||||
expect(newElementData === oldElementData).toBe(true);
|
||||
|
@ -19,7 +19,7 @@ function testLStaticData(tagName: string, attrs: string[] | null): TNode {
|
||||
initialInputs: undefined,
|
||||
inputs: undefined,
|
||||
outputs: undefined,
|
||||
data: null,
|
||||
tViews: null,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -147,30 +147,24 @@ describe('ViewContainerRef', () => {
|
||||
const tplRef = getOrCreateTemplateRef(getOrCreateNodeInjectorForNode(load(0)));
|
||||
elementProperty(0, 'tplRef', bind(tplRef));
|
||||
containerRefreshStart(0);
|
||||
let rf1 = embeddedViewStart(1);
|
||||
if (rf1 & RenderFlags.Create) {
|
||||
elementStart(0, 'header');
|
||||
elementEnd();
|
||||
}
|
||||
embeddedViewEnd();
|
||||
containerRefreshEnd();
|
||||
}
|
||||
|
||||
const fixture = new TemplateFixture(createTemplate, updateTemplate, [DirectiveWithVCRef]);
|
||||
expect(fixture.html).toEqual('<header></header><footer></footer>');
|
||||
expect(fixture.html).toEqual('<footer></footer>');
|
||||
|
||||
createView('A');
|
||||
fixture.update();
|
||||
expect(fixture.html).toEqual('<header></header>A<footer></footer>');
|
||||
expect(fixture.html).toEqual('A<footer></footer>');
|
||||
|
||||
createView('B');
|
||||
createView('C');
|
||||
fixture.update();
|
||||
expect(fixture.html).toEqual('<header></header>ABC<footer></footer>');
|
||||
expect(fixture.html).toEqual('ABC<footer></footer>');
|
||||
|
||||
createView('Y', 0);
|
||||
fixture.update();
|
||||
expect(fixture.html).toEqual('<header></header>YABC<footer></footer>');
|
||||
expect(fixture.html).toEqual('YABC<footer></footer>');
|
||||
|
||||
expect(() => { createView('Z', -1); }).toThrow();
|
||||
expect(() => { createView('Z', 5); }).toThrow();
|
||||
|
Reference in New Issue
Block a user