taiga-family / taiga-ui

Angular UI Kit and components library for awesome people
https://taiga-ui.dev
Apache License 2.0
3.2k stars 438 forks source link

🐞 - `Dropdown` triggers change detection too frequently #8725

Closed nsbarsukov closed 3 weeks ago

nsbarsukov commented 3 weeks ago

Playground Link

https://stackblitz.com/edit/dropdown-triggers-cd-too-frequently?file=src%2Fapp%2Fapp.component.ts,src%2Fapp%2Fapp.template.html

Description

app.component.ts ```ts import { ChangeDetectionStrategy, Component, DoCheck } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { TuiDropdown, TuiLabel } from '@taiga-ui/core'; import { TuiSwitch } from '@taiga-ui/kit'; @Component({ standalone: true, selector: 'app', templateUrl: './app.template.html', styleUrls: ['./app.style.less'], changeDetection: ChangeDetectionStrategy.OnPush, imports: [FormsModule, TuiSwitch, TuiLabel, TuiDropdown], }) export class App implements DoCheck { open = false; ngDoCheck() { console.log('=[tick]='); } } ```
app.template.html ```html

Dropdown host

Taiga UI is fully-treeshakable Angular UI Kit consisting of multiple base libraries and several add-ons. It is based on ng-polymorpheus dynamic content approach and uses Web APIs for Angular for required browser APIs. ```

https://github.com/user-attachments/assets/ec77d5da-f8f6-4771-ab26-094130af2b0d

Angular version

18

Taiga UI version

4.4.1

Which browsers have you used?

Which operating systems have you used?

splincode commented 3 weeks ago

@nsbarsukov

image

What if I comment out this line, the error will continue? I recently encountered this problem, and my guesses led to this code

image
nsbarsukov commented 3 weeks ago

@splincode I've tried to comment this line – no infinite logs more.

So, these line cause cyclic change detection

splincode commented 3 weeks ago

Possible related issues: https://github.com/taiga-family/taiga-ui/issues/8567 https://github.com/taiga-family/taiga-ui/issues/8652