question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make ChangeDetectorRef#detach() work with most child components

See original GitHub issue

šŸš€ feature request

Relevant Package

@angular/core

Description

Detaching views is (sometimes) absolutely necessary for good performance.

<item *ngFor="let item of longList" [value]="item"></item>

Whenever a single item is invalidated (even for a mousemove event), Angular has to check every single item. Unless of course they are detached.

But…detach() is practically unusable because it’s very, very poorly supported.

Angular Material is perhaps the best-made Angular library and even it breaks if detaching any parent. Example: https://stackblitz.com/edit/angular-nvcgil (expandable area will not expand)

Describe the solution you’d like

When I detach from change detection, what I really want is to not to dirty the parent, not to change how the children operate.

In other words, I want to make the component a ā€œrootā€ for change detection.

AFAIK there is no mechanism to do that currently.

Describe alternatives you’ve considered

  • Not detaching. The causes poor performance.
  • Fixed libraries for detached change detection. But I’m 100% certain the Angular team will refuse my PRs to Angular Material.
  • Not using libraries.

It’s unfortunate having to choose between using libraries and having performance.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:9
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
pkozlowski-opensourcecommented, Jul 8, 2022

I’m going to keep this issue open as this is one of the reports that highlights possible improvements in our change detection system.

1reaction
pauldrapercommented, Dec 10, 2020

Yes, you understand correctly.

This is a feature request for a detach() that is actually usable.

Right now, almost nothing the ecosystem supports it, and it seems impossible (except earlier hack mucking with View), to make them work with it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular 4 detach change detection between children
OnPush and changeDetectorRef.detach() the function ngDoCheck keep been called. I have thousands of components in my app, and I'd like to blockĀ ...
Read more >
How To Use Change Detection Strategy in Angular
Let's examine a sample component with a child component that ... thing you can do with ChangeDetectorRef is to completely detach andĀ ...
Read more >
Angular Change Detection-Detaching the Change Detector
Here we have 2 components parent and child, and we detach the child comp from the change detection, and based upon some condition...
Read more >
Everything you need to know about change detection in Angular
Most of its functionality performs operations on child component views. ... However, if we remove this line this.cd.detach() , everything will work asĀ ......
Read more >
ChangeDetectorRef - Angular
A change-detection tree collects all views that are to be checked for changes. ... To do that, we detach the component's change detector...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found