-
Notifications
You must be signed in to change notification settings - Fork 35
feat(angular): adjust change detection as per angular 22 #755
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ import { | |
| TemplateRef, | ||
| ViewContainerRef, | ||
| input, | ||
| ChangeDetectionStrategy, | ||
| booleanAttribute | ||
| } from '@angular/core'; | ||
|
|
||
|
|
@@ -30,7 +31,7 @@ import { RowOrGroup } from '../../types/public.types'; | |
| [ngTemplateOutletContext]="rowContext" | ||
| /> | ||
| }`, | ||
| styleUrl: './body-row-def.component.scss' | ||
| changeDetection: ChangeDetectionStrategy.Eager | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| }) | ||
| export class DatatableRowDefComponent { | ||
| private host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| import { | ||
| booleanAttribute, | ||
| ChangeDetectionStrategy, | ||
| ChangeDetectorRef, | ||
| Component, | ||
| computed, | ||
|
|
@@ -59,7 +58,6 @@ import { DataTableBodyCellComponent } from './body-cell.component'; | |
| } | ||
| `, | ||
| styleUrl: './body-row.component.scss', | ||
| changeDetection: ChangeDetectionStrategy.OnPush, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing Rows are the primary container for cells, and change detection at the row level should only trigger when the row data or state actually changes. Reverting to the default change detection strategy will cause unnecessary checks across all rows and cells on every change detection cycle. |
||
| host: { | ||
| class: 'datatable-body-row', | ||
| role: 'row', | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import { NgTemplateOutlet } from '@angular/common'; | ||
| import { Component, computed, input, TemplateRef } from '@angular/core'; | ||
| import { ChangeDetectionStrategy, Component, computed, input, TemplateRef } from '@angular/core'; | ||
|
|
||
| import { TableColumnInternal } from '../../../types/internal.types'; | ||
| import { DataTableBodyRowComponent } from '../body-row.component'; | ||
|
|
@@ -48,6 +48,7 @@ const noopSumFunc = (cells: any[]): void => { | |
| } | ||
| `, | ||
| styleUrl: './summary-row.component.scss', | ||
| changeDetection: ChangeDetectionStrategy.Eager, | ||
|
spike-rabbit marked this conversation as resolved.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we just published it without Eager, without any issues. So you can just remove OnPush everywhere without adding Eager |
||
| host: { | ||
| class: 'datatable-summary-row' | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import { HashLocationStrategy, Location, LocationStrategy } from '@angular/common'; | ||
| import { Component, signal } from '@angular/core'; | ||
| import { ChangeDetectionStrategy, Component, signal } from '@angular/core'; | ||
| import { RouterLink, RouterOutlet } from '@angular/router'; | ||
|
|
||
| import packageInfo from '../../projects/ngx-datatable/package.json'; | ||
|
|
@@ -14,7 +14,8 @@ import packageInfo from '../../projects/ngx-datatable/package.json'; | |
| provide: LocationStrategy, | ||
| useClass: HashLocationStrategy | ||
| } | ||
| ] | ||
| ], | ||
| changeDetection: ChangeDetectionStrategy.Eager | ||
|
Comment on lines
+17
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| }) | ||
| export class AppComponent { | ||
| version = packageInfo.version; | ||
|
|
||
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.
Removing
ChangeDetectionStrategy.OnPushfromDataTableBodyCellComponentwill cause a severe performance regression.Since cells are rendered in large numbers and updated frequently (especially during scrolling, sorting, or filtering), using the default change detection strategy means Angular will re-evaluate every cell on every change detection cycle. Keeping
OnPushis critical to ensure that only cells with changed inputs are updated, which is vital for maintaining 60fps scrolling performance.