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(elements): fire custom element output events during component initialization #36161
Conversation
You can preview ace1bd3 at https://pr36161-ace1bd3.ngbuilds.io/. |
ace1bd3
to
cb2871e
Compare
You can preview cb2871e at https://pr36161-cb2871e.ngbuilds.io/. |
cb2871e
to
c816e62
Compare
aio/scripts/_payload-limits.json
Outdated
@@ -12,7 +12,7 @@ | |||
"master": { | |||
"uncompressed": { | |||
"runtime-es2015": 2987, | |||
"main-es2015": 451469, | |||
"main-es2015": 452031, |
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.
This ~190B increase (for the commits that are new in this PR) is caused by the newly added === null
/!== null
checks, the extra this.componentRef
s passed as arguments to methods and the eventEmitters
and events
initialization 🤦♂
You can preview c816e62 at https://pr36161-c816e62.ngbuilds.io/. |
Marking this as blocked on #36114, because that had to go in first. |
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
c816e62
to
f70b5ed
Compare
You can preview f70b5ed at https://pr36161-f70b5ed.ngbuilds.io/. |
f70b5ed
to
3b75c64
Compare
This requires a payload size bump for ViewEngine on 9.1.x. |
…y` type-casts This commit removes some unnecessary non-null assertions (`!`) and `as any` type-casts from the `elements` package.
…tialization Previously, event listeners for component output events attached on an Angular custom element before inserting it into the DOM (i.e. before instantiating the underlying component) didn't fire for events emitted during initialization lifecycle hooks, such as `ngAfterContentInit`, `ngAfterViewInit`, `ngOnChanges` (initial call) and `ngOnInit`. The reason was that that `NgElementImpl` [subscribed to events][1] _after_ calling [ngElementStrategy#connect()][2], which is where the [initial change detection][3] takes place (running the initialization lifecycle hooks). This commit fixes this by: 1. Ensuring `ComponentNgElementStrategy#events` is defined and available for subscribing to, even before instantiating the component. 2. Ensuring `NgElementImpl` subscribes to `NgElementStrategy#events` before calling `NgElementStrategy#connect()` (which initializes the component instance). Jira issue: [FW-2010](https://angular-team.atlassian.net/browse/FW-2010) [1]: https://github.com/angular/angular/blob/c0143cb2abdd172de1b95fd1d2c4cfc738640e28/packages/elements/src/create-custom-element.ts#L167-L170 [2]: https://github.com/angular/angular/blob/c0143cb2abdd172de1b95fd1d2c4cfc738640e28/packages/elements/src/create-custom-element.ts#L164 [3]: https://github.com/angular/angular/blob/c0143cb2abdd172de1b95fd1d2c4cfc738640e28/packages/elements/src/component-factory-strategy.ts#L158 Fixes angular#36141
68d90e3
to
6a35a52
Compare
You can preview 6a35a52 at https://pr36161-6a35a52.ngbuilds.io/. |
…tialization (#36161) Previously, event listeners for component output events attached on an Angular custom element before inserting it into the DOM (i.e. before instantiating the underlying component) didn't fire for events emitted during initialization lifecycle hooks, such as `ngAfterContentInit`, `ngAfterViewInit`, `ngOnChanges` (initial call) and `ngOnInit`. The reason was that that `NgElementImpl` [subscribed to events][1] _after_ calling [ngElementStrategy#connect()][2], which is where the [initial change detection][3] takes place (running the initialization lifecycle hooks). This commit fixes this by: 1. Ensuring `ComponentNgElementStrategy#events` is defined and available for subscribing to, even before instantiating the component. 2. Ensuring `NgElementImpl` subscribes to `NgElementStrategy#events` before calling `NgElementStrategy#connect()` (which initializes the component instance). Jira issue: [FW-2010](https://angular-team.atlassian.net/browse/FW-2010) [1]: https://github.com/angular/angular/blob/c0143cb2abdd172de1b95fd1d2c4cfc738640e28/packages/elements/src/create-custom-element.ts#L167-L170 [2]: https://github.com/angular/angular/blob/c0143cb2abdd172de1b95fd1d2c4cfc738640e28/packages/elements/src/create-custom-element.ts#L164 [3]: https://github.com/angular/angular/blob/c0143cb2abdd172de1b95fd1d2c4cfc738640e28/packages/elements/src/component-factory-strategy.ts#L158 Fixes #36141 PR Close #36161
…tialization (#36161) Previously, event listeners for component output events attached on an Angular custom element before inserting it into the DOM (i.e. before instantiating the underlying component) didn't fire for events emitted during initialization lifecycle hooks, such as `ngAfterContentInit`, `ngAfterViewInit`, `ngOnChanges` (initial call) and `ngOnInit`. The reason was that that `NgElementImpl` [subscribed to events][1] _after_ calling [ngElementStrategy#connect()][2], which is where the [initial change detection][3] takes place (running the initialization lifecycle hooks). This commit fixes this by: 1. Ensuring `ComponentNgElementStrategy#events` is defined and available for subscribing to, even before instantiating the component. 2. Ensuring `NgElementImpl` subscribes to `NgElementStrategy#events` before calling `NgElementStrategy#connect()` (which initializes the component instance). Jira issue: [FW-2010](https://angular-team.atlassian.net/browse/FW-2010) [1]: https://github.com/angular/angular/blob/c0143cb2abdd172de1b95fd1d2c4cfc738640e28/packages/elements/src/create-custom-element.ts#L167-L170 [2]: https://github.com/angular/angular/blob/c0143cb2abdd172de1b95fd1d2c4cfc738640e28/packages/elements/src/create-custom-element.ts#L164 [3]: https://github.com/angular/angular/blob/c0143cb2abdd172de1b95fd1d2c4cfc738640e28/packages/elements/src/component-factory-strategy.ts#L158 Fixes #36141 PR Close #36161
…nent initialization (angular#36161)" This reverts commit e9bff5f. Failures were detected in Google tests due to this commit
…nent initialization (angular#36161)" This reverts commit e9bff5f. Failures were detected by Google tests after due to this commit.
…y` type-casts (angular#36161) This commit removes some unnecessary non-null assertions (`!`) and `as any` type-casts from the `elements` package. PR Close angular#36161
…tialization (angular#36161) Previously, event listeners for component output events attached on an Angular custom element before inserting it into the DOM (i.e. before instantiating the underlying component) didn't fire for events emitted during initialization lifecycle hooks, such as `ngAfterContentInit`, `ngAfterViewInit`, `ngOnChanges` (initial call) and `ngOnInit`. The reason was that that `NgElementImpl` [subscribed to events][1] _after_ calling [ngElementStrategy#connect()][2], which is where the [initial change detection][3] takes place (running the initialization lifecycle hooks). This commit fixes this by: 1. Ensuring `ComponentNgElementStrategy#events` is defined and available for subscribing to, even before instantiating the component. 2. Ensuring `NgElementImpl` subscribes to `NgElementStrategy#events` before calling `NgElementStrategy#connect()` (which initializes the component instance). Jira issue: [FW-2010](https://angular-team.atlassian.net/browse/FW-2010) [1]: https://github.com/angular/angular/blob/c0143cb2abdd172de1b95fd1d2c4cfc738640e28/packages/elements/src/create-custom-element.ts#L167-L170 [2]: https://github.com/angular/angular/blob/c0143cb2abdd172de1b95fd1d2c4cfc738640e28/packages/elements/src/create-custom-element.ts#L164 [3]: https://github.com/angular/angular/blob/c0143cb2abdd172de1b95fd1d2c4cfc738640e28/packages/elements/src/component-factory-strategy.ts#L158 Fixes angular#36141 PR Close angular#36161
…nent initialization (angular#36161)" (angular#37524) This reverts commit e9bff5f. Failures were detected in Google tests due to this commit PR Close angular#37524
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. |
…y` type-casts (angular#36161) This commit removes some unnecessary non-null assertions (`!`) and `as any` type-casts from the `elements` package. PR Close angular#36161
…tialization (angular#36161) Previously, event listeners for component output events attached on an Angular custom element before inserting it into the DOM (i.e. before instantiating the underlying component) didn't fire for events emitted during initialization lifecycle hooks, such as `ngAfterContentInit`, `ngAfterViewInit`, `ngOnChanges` (initial call) and `ngOnInit`. The reason was that that `NgElementImpl` [subscribed to events][1] _after_ calling [ngElementStrategy#connect()][2], which is where the [initial change detection][3] takes place (running the initialization lifecycle hooks). This commit fixes this by: 1. Ensuring `ComponentNgElementStrategy#events` is defined and available for subscribing to, even before instantiating the component. 2. Ensuring `NgElementImpl` subscribes to `NgElementStrategy#events` before calling `NgElementStrategy#connect()` (which initializes the component instance). Jira issue: [FW-2010](https://angular-team.atlassian.net/browse/FW-2010) [1]: https://github.com/angular/angular/blob/c0143cb2abdd172de1b95fd1d2c4cfc738640e28/packages/elements/src/create-custom-element.ts#L167-L170 [2]: https://github.com/angular/angular/blob/c0143cb2abdd172de1b95fd1d2c4cfc738640e28/packages/elements/src/create-custom-element.ts#L164 [3]: https://github.com/angular/angular/blob/c0143cb2abdd172de1b95fd1d2c4cfc738640e28/packages/elements/src/component-factory-strategy.ts#L158 Fixes angular#36141 PR Close angular#36161
This PR sits on top of #36114 (to avoid conflicts), so only the last two commits are new.Previously, event listeners for component output events attached on an Angular custom element before inserting it into the DOM (i.e. before instantiating the underlying component) didn't fire for events emitted during initialization lifecycle hooks, such as
ngAfterContentInit
,ngAfterViewInit
,ngOnChanges
(initial call) andngOnInit
.The reason was that that
NgElementImpl
subscribed to events after calling ngElementStrategy#connect(), which is where the initial change detection takes place (running the initialization lifecycle hooks).This commit fixes this by:
ComponentNgElementStrategy#events
is defined and available for subscribing to, even before instantiating the component.NgElementImpl
subscribes toNgElementStrategy#events
before callingNgElementStrategy#connect()
(which initializes the component instance).Jira issue: FW-2010
Fixes #36141.
For future reference:
This PR increases the main bundle by ~190B (currently 453658B --> 453847B). This is caused by the newly added
=== null
/!== null
checks, the extrathis.componentRef
s passed as arguments to methods and theeventEmitters
andevents
initialization 🤦♂