Angular flickering issue

Discussão em 'Angular' iniciado por Maks Szokalski, Novembro 20, 2024.

  1. I’m using Angular 19 with SSR, and I have a dropdown that momentarily displays the wrong value (e.g., the first option or a default) before updating to the correct one. I need the dropdown to show the correct value immediately upon rendering.

    Current Behavior:

    The dropdown briefly displays an incorrect or default value (e.g., "All categories") for a second.
    After a moment, it updates to the correct value based on the route parameter or the state.


    Expected Behavior:

    The dropdown should show the correct value immediately upon rendering without flickering or showing the default value.


    What I've Tried:

    Synchronizing state updates in explicitEffect and ngOnInit.
    Delaying rendering using @if.
    Forcing change detection (ChangeDetectorRef.detectChanges()).


    Despite these attempts, the issue persists. I suspect it might be due to SSR, route initialization, or how Angular renders the dropdown initially.

    Code Example: If you want to reproduce the issue, here’s the code hosted on StackBlitz. Make sure to open the StackBlitz preview in a new tab for route parameters to work:

    StackBlitz Link

    Current behavior

    Continue reading...

Compartilhe esta Página