From e6ab55daa0c56f3ca6b9290f8d88e7844a4c9ed0 Mon Sep 17 00:00:00 2001 From: Olivier Combe Date: Thu, 3 Jan 2019 16:07:00 +0100 Subject: [PATCH] fix(ivy): don't throw in `i18nAttributes` when a component is re-rendered (#27911) `i18nAttributes` was throwing an error when it was called multiple times in the create part of the template function with the same index, for example when we create multiple components with the same template. It shouldn't throw in this case, and just use the cache when available. FW-903 #resolve PR Close #27911 --- packages/core/src/render3/i18n.ts | 3 --- packages/core/test/render3/i18n_spec.ts | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/core/src/render3/i18n.ts b/packages/core/src/render3/i18n.ts index 386af20d0a..cff91d2278 100644 --- a/packages/core/src/render3/i18n.ts +++ b/packages/core/src/render3/i18n.ts @@ -834,9 +834,6 @@ export function i18n(index: number, message: string, subTemplateIndex?: number): export function i18nAttributes(index: number, values: string[]): void { const tView = getLView()[TVIEW]; ngDevMode && assertDefined(tView, `tView should be defined`); - ngDevMode && - assertEqual( - tView.firstTemplatePass, true, `You should only call i18nEnd on first template pass`); if (tView.firstTemplatePass && tView.data[index + HEADER_OFFSET] === null) { i18nAttributesFirstPass(tView, index, values); } diff --git a/packages/core/test/render3/i18n_spec.ts b/packages/core/test/render3/i18n_spec.ts index 440e43eb93..0db5621dc7 100644 --- a/packages/core/test/render3/i18n_spec.ts +++ b/packages/core/test/render3/i18n_spec.ts @@ -1359,6 +1359,23 @@ describe('Runtime i18n', () => { expect(fixture.html) .toEqual( '

Je suis projeté depuis Parent

'); + + // it should be able to render a new component with the same template code + const fixture2 = new ComponentFixture(Parent); + expect(fixture2.html).toEqual(fixture.html); + + // Updating the fixture should work + fixture2.component.name = 'Parent 2'; + fixture.update(); + fixture2.update(); + expect(fixture2.html) + .toEqual( + '

Je suis projeté depuis Parent 2

'); + + // The first fixture should not have changed + expect(fixture.html) + .toEqual( + '

Je suis projeté depuis Parent

'); }); it('should re-project translations when multiple projections', () => {