Repository navigation
Description
🐞 Bug report
Command
- [x] serve
Description
In IVY v9 (see here), we'll need to add abstract @Directive() on abstracts classes we extends that contain Angular stuff (like Input, ViewChild, DI).
After add @Directive() on my abstract class and run ng serve everything works well.
But If I edit abstract directive file and save, browser autoreload but query results are not resolved anymore ?!?!
🔬 Minimal Reproduction
One line repro :
git clone https://github.com/elvisbegovic/issue-ivy-abstract-directive.git && cd issue-ivy-abstract-directive && npm i && ng s
Open browser localhost:4200, open devtools console, you will see consoel without error, viewchild is available.
Edit or comment anything in any-abstract-class.ts file (cli rebuild + autoreload browser) you can see error at runtime that viewchild this.myList is undefined.
🔥 Exception or Error
After browser auto reload :
ERROR TypeError: Cannot read property 'name' of undefined
at AppComponent.ngOnInit (any-abstract-class.ts:11)
at AppComponent.ngOnInit (app.component.ts:17)
at callHook (core.js:7864)
at callHooks (core.js:7828)
at executeInitAndCheckHooks (core.js:7769)
at refreshView (core.js:12199)
at renderComponentOrTemplate (core.js:12288)
at tickRootContext (core.js:13648)
at detectChangesInRootView (core.js:13683)
at RootViewRef.detectChanges (core.js:15205)
In CLI console :
ERROR in src/app/app.component.ts(8,5): error TS8001: 'my-list' is not a valid HTML element.
🌍 Your Environment
See environment
Angular CLI: 9.0.0-next.2 Node: 12.9.1 OS: win32 x64 Angular: 9.0.0-next.4 ... animations, common, compiler, compiler-cli, core, forms ... language-service, platform-browser, platform-browser-dynamic ... routerPackage Version
@angular-devkit/architect 0.900.0-next.2
@angular-devkit/build-angular 0.900.0-next.2
@angular-devkit/build-optimizer 0.900.0-next.2
@angular-devkit/build-webpack 0.900.0-next.2
@angular-devkit/core 9.0.0-next.2
@angular-devkit/schematics 9.0.0-next.2
@angular/cli 9.0.0-next.2
@ngtools/webpack 9.0.0-next.2
@schematics/angular 9.0.0-next.2
@schematics/update 0.900.0-next.2
rxjs 6.4.0
typescript 3.5.3
webpack 4.39.3
Anything else relevant?
Problem is only when you edit any-abstract-class.ts file, if after first build you edit other file = no error.
If I add selector to Directive and add it to NgModule declarations[], all works as before.
This is working in View Engine (jit and aot and without decorating abstract classes)
Maybe related to #31560 and all referenced issues
Maybe this can live on angular/angular ?

Activity
petebacondarwin commentedon Aug 30, 2019
I think this is a problem with ngtsc incremental compilation?
petebacondarwin commentedon Aug 30, 2019
I think the solution would be for ngtsc to include all ancestors of components as dependencies that would trigger a rebuild of that component.
alxhub commentedon Sep 5, 2019
This shouldn't need to be the case (for locality) but probably should be because of type-checking.
elvisbegovic commentedon Oct 2, 2019
Will this be solved for 9.0 final?
petebacondarwin commentedon Oct 3, 2019
I think it should. We just need someone with time to look into it. :-/
brgrz commentedon Oct 20, 2019
This also happens when no Directives are involved (only components). I have a setup of AppComponent and LayoutComponent and only included the LayoutComponent within the AppComponent markup and the project runs fine immediately after
ng servethen breaks down (meaning noth in LayoutComponent gets rendered) after the first CSS/Less/HTML change in any of the two components.Thankfully setting
enableIvytofalsesolves this.JoostK commentedon Oct 30, 2019
Here's a breakdown of the issue:
Abstract directives are not registered with an NgModule, so if the directive is updated the NgModule is not invalidated. The component subclass however is correctly tracked as being dependent on its parent. During incremental state reconciliation, this means that the change to the abstract directive has this effect:
During the subsequent compilation, the NgModule is considered to be safe to skip, which means that none of its metadata is analyzed and registered with
LocalModuleScopeRegistry. Basically, this code is not executed:angular/packages/compiler-cli/src/ngtsc/scope/src/local.ts
Lines 113 to 119 in a42057d
Notice how this is responsible for the knowledge of which declarations correspond with which NgModule.
The abstract directive and component are reanalyzed, because their source file is correctly deemed unsafe to skip analyzing. Consequently, the component requests its module scope:
LocalModuleScopeRegistrydoes not have the required information, as the NgModule was not analyzed so no metadata is present locally.IncrementalState.getScopeForComponentis considered, however the scope info that was set aside during the first compilation here:angular/packages/compiler-cli/src/ngtsc/scope/src/local.ts
Lines 129 to 131 in a42057d
is no longer available, as the component resides in a file for which no metadata was copied over during incremental state reconciliation as its metadata was deemed outdated (because of the dependency on the abstract directive).
fix(ivy): ensure module scope is rebuild on dependent change (#33522)
angular-automatic-lock-bot commentedon Dec 13, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.