fix(ivy): creation mode not run on view detached from change detection (#29741)

Fixes the creation mode block not being run on components which have been detached from change detection.

This PR resolves FW-1217.
Fixes #29645.

PR Close #29741
This commit is contained in:
Kristiyan Kostadinov 2019-04-06 10:10:54 +02:00 committed by Igor Minar
parent cb9ee3411f
commit 98cf3e8fcd
2 changed files with 28 additions and 3 deletions

View File

@ -1292,8 +1292,9 @@ export function componentRefresh(adjustedElementIndex: number): void {
const hostView = getComponentViewByIndex(adjustedElementIndex, lView);
ngDevMode && assertNodeType(lView[TVIEW].data[adjustedElementIndex] as TNode, TNodeType.Element);
// Only attached CheckAlways components or attached, dirty OnPush components should be checked
if (viewAttachedToChangeDetector(hostView) &&
// Only components in creation mode, attached CheckAlways
// components or attached, dirty OnPush components should be checked
if ((viewAttachedToChangeDetector(hostView) || isCreationMode(lView)) &&
hostView[FLAGS] & (LViewFlags.CheckAlways | LViewFlags.Dirty)) {
syncViewWithBlueprint(hostView);
checkView(hostView, hostView[CONTEXT]);

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Component, Directive} from '@angular/core';
import {ChangeDetectorRef, Component, Directive} from '@angular/core';
import {TestBed} from '@angular/core/testing';
import {expect} from '@angular/platform-browser/testing/src/matchers';
@ -57,6 +57,30 @@ describe('projection', () => {
expect(fixture.nativeElement).toHaveText('6|7|8|');
});
it('should project content if the change detector has been detached', () => {
@Component({selector: 'my-comp', template: '<ng-content></ng-content>'})
class MyComp {
constructor(changeDetectorRef: ChangeDetectorRef) { changeDetectorRef.detach(); }
}
@Component({
selector: 'my-app',
template: `
<my-comp>
<p>hello</p>
</my-comp>
`
})
class MyApp {
}
TestBed.configureTestingModule({declarations: [MyComp, MyApp]});
const fixture = TestBed.createComponent(MyApp);
fixture.detectChanges();
expect(fixture.nativeElement).toHaveText('hello');
});
describe('on inline templates (e.g. *ngIf)', () => {
it('should work when matching the element name', () => {
let divDirectives = 0;