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): elements should run in correct zone (#24181) #37814
Conversation
As I had commented way back, what this is still missing is exiting the NgZone in outputs - we don't want to leak our app's NgZone to the parent app (which would cause unrelated activities in the parent app to trigger change detection within the wrapped child application). |
For reference: There is some relevant discussion in #24185. |
@kseamon, can you give an example of the problem (I don't quite understand how we can "leak" our Zone). |
It would look something like this: // Parent app
ngElementNode.addEventListener('customEvent', () => {
setTimeout(() => {
doSomethingUnrelated();
// Whoops we just triggered CD within the Angular Element.
});
}); It would be possible for this to happen before if the code inside of the Angular Element manually entered the NgZone. This PR just makes it more likely to be an issue, and I think it's something that the framework should take care of for us (just like entering the NgZone in the first place). |
Since this change is unrelated to this PR, I consider it outside of scope for this PR. Feel free to create an issue about so we can discuss there. On a quick note: I wouldn't expect Zones to be leaked the way you described (neither with nor without the changes in this PR). If I am not mistaken, what matters is the Zone in which you subscribe to the observable and this happens in the CustomElement's connectedCallback() and is not affected by the strategy's If anything, we might need to enter the Zone in the event listener callback, if the element is created in a way that causes its I only took a quick look, so I may have missed something. We should take a closer look and look at concrete examples (both with and without CustomElement polyfills). |
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.
Thx for working on this, @remackgeek!
I think this is heading into the right direction. I have left a few minor comments.
Can you also please rebase on latest master and squash the commits into one?
BTW, it would be great to have a more realistic test via an actual example app (either in packages/examples/ or in integration/ (similar to or as part of integration/ng_elements/)), but that might be too much to ask for this PR 😁
c318b26
to
5d2f4e4
Compare
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 - Thx, @remackgeek ✨
Can you please update goldens/size-tracking/aio-payloads.json#L15 to the new size?
For reference, this PR increases the angular.io main bundle by 295B (451100B --> 451395B). I inspected the bundle and confirmed that the only difference is the updated ComponentFactoryNgStrategy
class.
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
Can you rebase and fix the size-tracking conflict so that we can approve for |
b7b462a
to
02514cf
Compare
Default change detection fails in some cases for @angular/elements where component events are called from the wrong zone. This fixes the issue by running all ComponentNgElementStrategy methods in the same zone it was created in. Fixes angular#24181
02514cf
to
7b3753e
Compare
Rebased, broken size tracking changed to match actuals (not sure what else to put there). |
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.
Reviewed-for: size-tracking
Awesome thanks! |
Default change detection fails in some cases for @angular/elements where component events are called from the wrong zone. This fixes the issue by running all ComponentNgElementStrategy methods in the same zone it was created in. Fixes angular#24181 PR Close angular#37814
Default change detection fails in some cases for @angular/elements where component events are called from the wrong zone. This fixes the issue by running all ComponentNgElementStrategy methods in the same zone it was created in. Fixes angular#24181 PR Close angular#37814
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. |
Default change detection fails in some cases for @angular/elements where component events are called from the wrong zone. This fixes the issue by running all ComponentNgElementStrategy methods in the same zone it was created in. Fixes angular#24181 PR Close angular#37814
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?
When an angular element is created outside the angular zone, such as in setTimeout(), automatic change detection no longer works
Issue Number: #24181
What is the new behavior?
ComponentNgElementStrategy captures the zone it was created in and insures all methods are run in that zone.
Does this PR introduce a breaking change?
Other information