I have been developing an Angular component called GestionAchatTpvGenerationProgressBarComponent, which is responsible for showcasing a progress bar based on data from an Observable. This self-contained component operates with the OnPush change detection strategy and aims to illustrate the progression of specific purchases made through a TPV (Point of Sale Terminal) by updating via a stream of data (achatTitreViaTpv).
However, there seems to be a noticeable "flickering" effect or visible refresh each time the achatTitreViaTpv data is updated, resulting in a subpar user experience. I am keen on understanding the rationale behind this behavior and finding ways to mitigate it.
Below is a simplified version of the component's code:
@Component({
selector: 'app-gestion-achat-tpv-generation-progress-bar',
templateUrl: './gestion-achat-tpv-generation-progress-bar.component.html',
styleUrls: ['./gestion-achat-tpv-generation-progress-bar.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [
TranslateModule,
NgIf,
AsyncPipe,
DecimalPipe
],
standalone: true
})
export class GestionAchatTpvGenerationProgressBarComponent {
@Select(GestionAchatTpvDetailState.recupereAchat) achatTitreViaTpv!: Observable<AchatTitreViaTpv>;
}
And the corresponding template:
<div class="progress-bar-tpv-generation-container">
<ng-container *ngIf="achatTitreViaTpv | async as achat">
<div class="progress-bar-tpv-generation-container__titles-container">
<!-- Display of progress and estimated remaining time -->
</div>
<div class="progress-bar-tpv-generation-container__progress-bar">
<div class="progress-bar-tpv-generation-container__progress-bar--fill" [style.width]="(condition) + '%'"></div>
</div>
</ng-container>
</div>
My attempted solutions include:
- Optimizing data updates to prevent unnecessary re-emissions.
- Utilizing the OnPush change detection strategy to reduce change checks.
Despite these efforts, the flickering issue persists whenever data is updated. Can anyone shed light on the potential causes of this behavior and suggest how it can be resolved?