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

[Ivy] detach view doesn't work #34816

Closed
marcj opened this issue Jan 16, 2020 · 2 comments
Closed

[Ivy] detach view doesn't work #34816

marcj opened this issue Jan 16, 2020 · 2 comments
Assignees
Labels
area: core Issues related to the framework runtime regression Indicates than the issue relates to something that worked in a previous version state: has PR

Comments

@marcj
Copy link

marcj commented Jan 16, 2020

🐞 bug report

Is this a regression?

Yes, worked perfectly fine in latest v8 without Ivy. Works also without Ivy in v9.

Description

I have a directive that renders a template and detaches it from the CD until some criteria is true. Once true I reattach it again. However in Ivy the whole detach doesn't work. After calling view.detach() the view is still checked in change detector runs and thus uses resources. In non-Ivy that works correctly: The view is never used in change detector runs when detach was called.

🔬 Minimal Reproduction

https://stackblitz.com/edit/angular-issue-repro2-xd8kbu

This Stackblitz uses Angular 9.0.0rc9, however the issue is not reproducible directly in Stackblitz (only god knows why). In Stackblitz you see the correct behavior:
Screenshot 2020-01-16 at 19 00 05

But if you download that Stackblitz and run npm install && ./node_modules/.bin/ng serve then you see the actual issue:

Screenshot 2020-01-16 at 19 01 29

The second line behind the : is detached and should never display anything.

Code of that wrapper:

    <div>This should increase w/ each click: <cd-counter></cd-counter></div>
    <div *wrapper>This should stay empty or 0: <cd-counter></cd-counter></div>
@Directive({
  selector: "[wrapper]"
})
export class WrapperComponent implements OnInit {
  constructor(
    protected template: TemplateRef<any>,
    protected viewContainer: ViewContainerRef
  ) {}

  ngOnInit() {
    const view = this.viewContainer.createEmbeddedView(this.template);
    view.detach();
  }
}

Versions

9.0.0: I tested rc7, rc8, rc9. None worked correctly. When I opt out of Ivy using "enableIvy": false it works correctly (only tested with with rc9).

Screenshot 2020-01-16 at 19 08 30

🌍 Your Environment

Angular Version:

Angular CLI: 9.0.0-rc.9
Node: 12.14.1
OS: darwin x64

Angular: 9.0.0-rc.9
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.900.0-rc.9
@angular-devkit/build-angular     0.900.0-rc.9
@angular-devkit/build-optimizer   0.900.0-rc.9
@angular-devkit/build-webpack     0.900.0-rc.9
@angular-devkit/core              9.0.0-rc.9
@angular-devkit/schematics        9.0.0-rc.9
@angular/cdk                      9.0.0-rc.7
@ngtools/webpack                  9.0.0-rc.9
@schematics/angular               9.0.0-rc.9
@schematics/update                0.900.0-rc.9
rxjs                              6.5.4
typescript                        3.6.4
webpack                           4.41.2

Anything else relevant?

It's interesting that in Stackblitz it works as intended, but when using Chrome and ng serve locally it doesn't work. I assume that Stackblitz uses some v8 components or not the Ivy renderer, but that's just a guess as I have no knowledge about how Stackblitz actually starts the angular dev server and whether they overwrite some settings.

@marcj marcj changed the title v9 Ivy: detach view doesn't work [Ivy] detach view doesn't work Jan 16, 2020
@alexzuza
Copy link
Contributor

@AndrewKushnir AndrewKushnir added area: core Issues related to the framework runtime comp: ivy labels Jan 16, 2020
@ngbot ngbot bot added this to the needsTriage milestone Jan 16, 2020
crisbeto added a commit to crisbeto/angular that referenced this issue Jan 18, 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 angular#34816.
crisbeto added a commit to crisbeto/angular that referenced this issue Jan 18, 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 angular#34816.
@crisbeto crisbeto self-assigned this Jan 18, 2020
crisbeto added a commit to crisbeto/angular that referenced this issue Jan 23, 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 angular#34816.
crisbeto added a commit to crisbeto/angular that referenced this issue Jan 23, 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 angular#34816.
crisbeto added a commit to crisbeto/angular that referenced this issue Jan 23, 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 angular#34816.
AndrewKushnir pushed a commit that referenced this issue 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
@kara kara added regression Indicates than the issue relates to something that worked in a previous version and removed severity5: ivy-compat labels Feb 11, 2020
sonukapoor pushed a commit to sonukapoor/angular that referenced this issue 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 Mar 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: core Issues related to the framework runtime regression Indicates than the issue relates to something that worked in a previous version state: has PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants