From 05d7c575e47c05c47cad446bb7bcf94767de3147 Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Thu, 7 Nov 2019 11:25:26 +0100 Subject: [PATCH] fix(ivy): properly insert views in front of empty views (#33647) PR Close #33647 --- packages/core/src/render3/node_manipulation.ts | 7 ++++++- .../core/test/acceptance/view_insertion_spec.ts | 14 +++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/packages/core/src/render3/node_manipulation.ts b/packages/core/src/render3/node_manipulation.ts index 2c1ed5c056..1dba574c07 100644 --- a/packages/core/src/render3/node_manipulation.ts +++ b/packages/core/src/render3/node_manipulation.ts @@ -671,7 +671,12 @@ function getFirstNativeNode(lView: LView, tNode: TNode | null): RNode|null { const lContainer = lView[tNode.index]; if (lContainer.length > CONTAINER_HEADER_OFFSET) { const firstView = lContainer[CONTAINER_HEADER_OFFSET]; - return getFirstNativeNode(firstView, firstView[TVIEW].firstChild); + const firstTNodeOfView = firstView[TVIEW].firstChild; + if (firstTNodeOfView !== null) { + return getFirstNativeNode(firstView, firstTNodeOfView); + } else { + return lContainer[NATIVE]; + } } else { return lContainer[NATIVE]; } diff --git a/packages/core/test/acceptance/view_insertion_spec.ts b/packages/core/test/acceptance/view_insertion_spec.ts index fadc44211c..862e23c725 100644 --- a/packages/core/test/acceptance/view_insertion_spec.ts +++ b/packages/core/test/acceptance/view_insertion_spec.ts @@ -263,15 +263,7 @@ describe('view insertion', () => { } describe('before embedded view', () => { - @Component({ - selector: 'test-cmpt', - template: ` - insert - |before - -
- ` - }) + @Component({selector: 'test-cmpt', template: ''}) class TestCmpt { @ViewChild('before', {static: true}) beforeTpl !: TemplateRef<{}>; @ViewChild('insert', {static: true}) insertTpl !: TemplateRef<{}>; @@ -348,8 +340,8 @@ describe('view insertion', () => { }); it('should insert before a view with an empty container as the first root node', () => { - expect(createAndInsertViews(``).textContent) - .toBe('insert'); + expect(createAndInsertViews(`|before`).textContent) + .toBe('insert|before'); });