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.
/illunix/flickering-issue-angular
Current behavior
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.
https://stackblitz/github/illunix/flickering-issue-angular
Current behavior
Share Improve this question edited Nov 20, 2024 at 18:03 Ross Bush 15.2k2 gold badges38 silver badges63 bronze badges asked Nov 20, 2024 at 15:17 Maks SzokalskiMaks Szokalski 112 bronze badges 4 |1 Answer
Reset to default 3The SSR should set the field then become stable and then serve the HTML on the server, this does not happen, until then you can workaround with defer
which only renders on the browser, which is as per Sam Scholefield
comment.
@defer {
<select
#category
name="categories"
[(ngModel)]="selectedCategory"
style="margin-right: 10px;"
>
@for (category of categoriesState.categories; track category;) {
<option [value]="category.name">{{ category.name }}</option>
}
</select>
<input [value]="selectedCategory()" />
}
isPlatformBrowser
). – Sam Scholefield Commented Nov 21, 2024 at 6:00