-
Notifications
You must be signed in to change notification settings - Fork 25.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(core): Allow modification of lifecycle hooks any time before bootstrap #35464
Conversation
Thank you so much for fixing this. Angular Ivy is awesome - Being able to upgrade our app, which heavily uses custom decorators, will be possible once this PR is merged. |
12cff19
to
3d53368
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Eagerly waiting for this MR to get merged. Once this get merged so many issue must get resolved i think. |
When using Angular 9.1.1 with Ivy now when I "ng serve" all of my custom class decorators are called and working the way they did with view engine but when I run "ng build --prod" and run the application only a few of my custom decorators are called. @mhevery will this pull request fix that? Meaning will all my decorators get called when the application is first loaded. |
This comment has been minimized.
This comment has been minimized.
@hakimio it seems like different members of the team have different opinions about how important Metaprogramming is for users of Angular. Thankfully @mhevery seems to realize just how important it is to us; but he might have a challenge convincing other members. Hopefully everyone on the Angular team will realize just how prevalent metaprogramming is among Angular users. |
This comment has been minimized.
This comment has been minimized.
Without this MR, Ivy misses a little bit to be backward compatible :) That'd really help us too at CloudNC to work on a new version of ngx-sub-form where we're trying to get rid of inheritance. 🤞 for this to get merged soon |
⬆️ Please don't kill component features. Please stop worrying about custom decorators. Custom decorators are experimental and should be treated as such. The original ECMAScript decorators proposal has been abandoned. There's a new proposal in early stages, but it has different syntax and semantics. |
AFAIK it's Angular private API and they can do whatever they want with private APIs.
Yet they are one of the most widely used TypeScript features and many TypeScript libraries depend on them. |
It's private now, but because of the phase for stabilization inner structures and finalize the public API. It was always mentioned as the public API at some point.
Yep, but it was meant from the official ECMAScript spec point of view. |
Why is everyone fixating on decorators only? The point is, that components are JS classes. Methods on classes are members of prototype. Overwriting a prototype method is an absolutely valid thing to do. Angular currently makes this impossible. And yes, sure, decorators are one use case of it and I wouldn't make custom decorators for reasons you mentioned, but there are many more use cases. |
If we can't use custom decorators, you might as well get rid of them across the board in Angular. No It's not a good look when libraries are built around the idea that developers have to use a subset of a language. |
4ac5a60
to
269c093
Compare
…strap Currently we read lifecycle hooks eagerly during `ɵɵdefineComponent`. The result is that it is not possible to do any sort of meta-programing such as mixins or adding lifecycle hooks using custom decorators since any such code executes after `ɵɵdefineComponent` has extracted the lifecycle hooks from the prototype. Additionally the behavior is inconsistent between AOT and JIT mode. In JIT mode overriding lifecycle hooks is possible because the whole `ɵɵdefineComponent` is placed in getter which is executed lazily. This is because JIT mode must compile a template which can be specified as `templateURL` and those we are waiting for its resolution. - `+` `ɵɵdefineComponent` becomes smaller as it no longer needs to copy lifecycle hooks from prototype to `ComponentDef` - `-` `ɵɵNgOnChangesFeature` feature is now always included with the codebase as it is no longer tree shakable. Previously we have read lifecycle hooks from prototype in the `ɵɵdefineComponent` so that lifecycle hook access would be monomorphic. This decision was made before we had `T*` data structures. By not reading the lifecycle hooks we are moving the megamorhic read form `ɵɵdefineComponent` to instructions. However, the reads happen on `firstTemplatePass` only and are subsequently cached in the `T*` data structures. The result is that the overall performance should be same (or slightly better as the intermediate `ComponentDef` has been removed.) - [ ] Remove `ɵɵNgOnChangesFeature` from compiler. (It will no longer be a feature.) - [ ] Discuss the future of `Features` as they hinder meta-programing. Fix angular#30497
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Reviewed-for: size-tracking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, using global approvers because the public-api change here is a false positive
Reviewed-for: global-approvers
Hi @mhevery, this PR was merged to master only, since there was a conflict while merging into a patch branch. Could you please create a new PR that targets patch branch? Thank you. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
…strap (angular#35464) Currently we read lifecycle hooks eagerly during `ɵɵdefineComponent`. The result is that it is not possible to do any sort of meta-programing such as mixins or adding lifecycle hooks using custom decorators since any such code executes after `ɵɵdefineComponent` has extracted the lifecycle hooks from the prototype. Additionally the behavior is inconsistent between AOT and JIT mode. In JIT mode overriding lifecycle hooks is possible because the whole `ɵɵdefineComponent` is placed in getter which is executed lazily. This is because JIT mode must compile a template which can be specified as `templateURL` and those we are waiting for its resolution. - `+` `ɵɵdefineComponent` becomes smaller as it no longer needs to copy lifecycle hooks from prototype to `ComponentDef` - `-` `ɵɵNgOnChangesFeature` feature is now always included with the codebase as it is no longer tree shakable. Previously we have read lifecycle hooks from prototype in the `ɵɵdefineComponent` so that lifecycle hook access would be monomorphic. This decision was made before we had `T*` data structures. By not reading the lifecycle hooks we are moving the megamorhic read form `ɵɵdefineComponent` to instructions. However, the reads happen on `firstTemplatePass` only and are subsequently cached in the `T*` data structures. The result is that the overall performance should be same (or slightly better as the intermediate `ComponentDef` has been removed.) - [ ] Remove `ɵɵNgOnChangesFeature` from compiler. (It will no longer be a feature.) - [ ] Discuss the future of `Features` as they hinder meta-programing. Fix angular#30497 PR Close angular#35464
Overview
Currently we read lifecycle hooks eagerly during
ɵɵdefineComponent
. The result is that it is not possible to do any sort of meta-programing such as mixins or adding lifecycle hooks using custom decorators since any such code executes afterɵɵdefineComponent
has extracted the lifecycle hooks from the prototype. Additionally the behavior is inconsistent between AOT and JIT mode. In JIT mode overriding lifecycle hooks is possible because the wholeɵɵdefineComponent
is placed in getter which is executed lazily. This is because JIT mode must compile a template which can be specified astemplateURL
and those we are waiting for its resolution.Size tradeoffs
+
ɵɵdefineComponent
becomes smaller as it no longer needs to copy lifecycle hooks from prototype toComponentDef
-
ɵɵNgOnChangesFeature
feature is now always included with the codebase as it is no longer tree shakable.Perf tradeoffs
Previously we have read lifecycle hooks from prototype in the
ɵɵdefineComponent
so that lifecycle hook access would be monomorphic. This decision was made before we hadT*
data structures. By not reading the lifecycle hooks we are moving the megamorhic read formɵɵdefineComponent
to instructions. However, the reads happen onfirstTemplatePass
only and are subsequently cached in theT*
data structures. The result is that the overall performance should be same (or slightly better as the intermediateComponentDef
has been removed)Next steps
ɵɵNgOnChangesFeature
from compiler. (It will no longer be a feature.)Features
as they hinder meta-programing.Fix #30497
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information