From fc813f67f4ef7334bfab3487931e9ac118382cc4 Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Wed, 4 Apr 2018 14:40:06 +0200 Subject: [PATCH] fix(ivy): fix issue with refreshing embedded views (#23164) PR Close #23164 --- packages/core/src/render3/instructions.ts | 5 +++-- packages/core/test/render3/view_container_ref_spec.ts | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/core/src/render3/instructions.ts b/packages/core/src/render3/instructions.ts index febcba33bc..127a34721b 100644 --- a/packages/core/src/render3/instructions.ts +++ b/packages/core/src/render3/instructions.ts @@ -442,6 +442,7 @@ export function renderEmbeddedTemplate( renderer: Renderer3): LViewNode { const _isParent = isParent; const _previousOrParentNode = previousOrParentNode; + let oldView: LView; try { isParent = true; previousOrParentNode = null !; @@ -456,14 +457,14 @@ export function renderEmbeddedTemplate( viewNode = createLNode(null, LNodeType.View, null, view); cm = true; } - enterView(viewNode.data, viewNode); + oldView = enterView(viewNode.data, viewNode); template(context, cm); refreshDirectives(); refreshDynamicChildren(); } finally { - leaveView(currentView && currentView !.parent !); + leaveView(oldView !); isParent = _isParent; previousOrParentNode = _previousOrParentNode; } diff --git a/packages/core/test/render3/view_container_ref_spec.ts b/packages/core/test/render3/view_container_ref_spec.ts index 0dc09cc7b4..5e7ee86aa0 100644 --- a/packages/core/test/render3/view_container_ref_spec.ts +++ b/packages/core/test/render3/view_container_ref_spec.ts @@ -119,6 +119,10 @@ describe('ViewContainerRef', () => { directiveInstance !.insertTpl(); expect(fixture.html).toEqual('before
From a template.after'); + // run change-detection cycle with no template insertion / removal + fixture.update(); + expect(fixture.html).toEqual('before
From a template.after'); + directiveInstance !.insertTpl(); expect(fixture.html) .toEqual('before
From a template.From a template.after'); @@ -178,6 +182,10 @@ describe('ViewContainerRef', () => { directiveInstance !.insertTpl({name: 'World'}); expect(fixture.html).toEqual('before|Hello, World|after'); + // run change-detection cycle with no template insertion / removal + fixture.update(); + expect(fixture.html).toEqual('before|Hello, World|after'); + directiveInstance !.remove(0); expect(fixture.html).toEqual('before||after'); });