Skip to content
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(ivy): don't detect changes on detached child embedded views #34846

Closed

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Jan 18, 2020

Fixes Ivy detecting changes inside child embedded views, even though they're detached.

Note that there's one subtlety here: I made the changes inside refreshDynamicEmbeddedViews rather than refreshView, because we support detecting changes on a detached view (evidenced by a couple of unit tests), but only if it's triggered directly from the view's ChangeDetectorRef, however we shouldn't be detecting changes in the detached child view when something happens in the parent.

Note: I had to bump the size limit, because it looks like master was right on the edge before these changes. I haven't introduced any new imports and the new logic is only a couple of lines so I doubt that these changes would've added too much to the size.

Fixes #34816.

@crisbeto crisbeto changed the title fix(ivy): don't detect changes detached child embedded views fix(ivy): don't detect changes on detached child embedded views Jan 18, 2020
@crisbeto crisbeto force-pushed the 34816/detached-embedded-view-cd branch from c511e61 to b3b55de Compare January 18, 2020 10:47
@crisbeto crisbeto added comp: ivy action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release labels Jan 18, 2020
@ngbot ngbot bot modified the milestone: needsTriage Jan 18, 2020
@crisbeto crisbeto marked this pull request as ready for review January 18, 2020 11:30
@crisbeto crisbeto requested review from a team as code owners January 18, 2020 11:30
Copy link
Member

@pkozlowski-opensource pkozlowski-opensource left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall, just left few comments / questions that I would like have your thoughts on.

packages/core/test/acceptance/change_detection_spec.ts Outdated Show resolved Hide resolved

TestBed.configureTestingModule({declarations: [App, ViewManipulation]});
const fixture = TestBed.createComponent(App);
const vm: ViewManipulation = fixture.debugElement.childNodes[2].references['vm'];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super-nit / personal preference: in cases like this I usually do debugElement.query(By.directive(ViewManipulation)).injector.get(ViewManipulation) as I find this approach less "brittle". (BTW, for quite a bit of time I wanted to have a better API to do just this in TestBed but this is a separate story....).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EDIT: I tried it out and query didn't manage to find the directive for some reason. Maybe because I'm trying to access it before the first change detection run?

Sure, I don't feel strongly about it. I did it this way, because the other unit tests were doing the same.

@pkozlowski-opensource pkozlowski-opensource added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jan 22, 2020
@crisbeto crisbeto force-pushed the 34816/detached-embedded-view-cd branch from b3b55de to 7613282 Compare January 23, 2020 10:13
Copy link
Member Author

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've addressed/replied to all of the feedback @pkozlowski-opensource.


TestBed.configureTestingModule({declarations: [App, ViewManipulation]});
const fixture = TestBed.createComponent(App);
const vm: ViewManipulation = fixture.debugElement.childNodes[2].references['vm'];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EDIT: I tried it out and query didn't manage to find the directive for some reason. Maybe because I'm trying to access it before the first change detection run?

Sure, I don't feel strongly about it. I did it this way, because the other unit tests were doing the same.

@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Jan 23, 2020
@crisbeto crisbeto force-pushed the 34816/detached-embedded-view-cd branch from 7613282 to 6b9881f Compare January 23, 2020 11:58
@crisbeto crisbeto requested a review from a team January 23, 2020 11:58
@crisbeto
Copy link
Member Author

I've added the extra unit test.

Fixes Ivy detecting changes inside child embedded views, even though they're detached.

Note that there's on subtlety here: I made the changes inside `refreshDynamicEmbeddedViews` rather than `refreshView`, because we support detecting changes on a detached view (evidenced by a couple of unit tests), but only if it's triggered directly from the view's `ChangeDetectorRef`, however we shouldn't be detecting changes in the detached child view when something happens in the parent.

Fixes angular#34816.
@crisbeto crisbeto force-pushed the 34816/detached-embedded-view-cd branch from 6b9881f to feac972 Compare January 23, 2020 12:20
Copy link
Member

@pkozlowski-opensource pkozlowski-opensource left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The size increase is unfortunate but I believe that it is mostly because of the creeping size increase from the previous PRs.

@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker action: presubmit The PR is in need of a google3 presubmit and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jan 24, 2020
@AndrewKushnir
Copy link
Contributor

Presubmit

@AndrewKushnir AndrewKushnir removed the action: presubmit The PR is in need of a google3 presubmit label Jan 24, 2020
Copy link
Contributor

@IgorMinar IgorMinar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm - global approval (the size diff is not caused by this change)

AndrewKushnir pushed a commit that referenced this pull request Jan 24, 2020
Fixes Ivy detecting changes inside child embedded views, even though they're detached.

Note that there's on subtlety here: I made the changes inside `refreshDynamicEmbeddedViews` rather than `refreshView`, because we support detecting changes on a detached view (evidenced by a couple of unit tests), but only if it's triggered directly from the view's `ChangeDetectorRef`, however we shouldn't be detecting changes in the detached child view when something happens in the parent.

Fixes #34816.

PR Close #34846
sonukapoor pushed a commit to sonukapoor/angular that referenced this pull request Feb 13, 2020
…lar#34846)

Fixes Ivy detecting changes inside child embedded views, even though they're detached.

Note that there's on subtlety here: I made the changes inside `refreshDynamicEmbeddedViews` rather than `refreshView`, because we support detecting changes on a detached view (evidenced by a couple of unit tests), but only if it's triggered directly from the view's `ChangeDetectorRef`, however we shouldn't be detecting changes in the detached child view when something happens in the parent.

Fixes angular#34816.

PR Close angular#34846
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Feb 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes target: patch This PR is targeted for the next patch release type: bug/fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Ivy] detach view doesn't work
5 participants