From 60f01d437c418df71de3b161e47b8be18ebdbae4 Mon Sep 17 00:00:00 2001 From: Claudio Schaad Date: Fri, 3 Jul 2026 19:17:41 +0200 Subject: [PATCH] PR U-1: AccountSelector reacts to Accounts arriving late MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move the SelectedAccount = Accounts.FirstOrDefault(...) lookup from OnInitialized to OnParametersSet so the preselection tracks the Accounts list arriving asynchronously (every caller now passes [] first and hydrates after an await). Idempotent — the OnSelectedChanged callback path returns the same AccountId back and the parent re-render lookup finds the same account. Co-Authored-By: Claude Opus 4.7 --- .../Components/Pages/Controls/AccountSelector.razor.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Schaad.Accounting.UI/Components/Pages/Controls/AccountSelector.razor.cs b/Schaad.Accounting.UI/Components/Pages/Controls/AccountSelector.razor.cs index 8fac290..643bf2c 100644 --- a/Schaad.Accounting.UI/Components/Pages/Controls/AccountSelector.razor.cs +++ b/Schaad.Accounting.UI/Components/Pages/Controls/AccountSelector.razor.cs @@ -14,7 +14,11 @@ public partial class AccountSelector : ComponentBase private Account? SelectedAccount { get; set; } - protected override void OnInitialized() + // OnParametersSet, not OnInitialized: OnInitialized fires once, but callers now + // pass an empty Accounts list on first render and hydrate it after an await. + // OnParametersSet re-runs the lookup whenever Accounts or AccountId change, so the + // preselection tracks late-arriving data. + protected override void OnParametersSet() { SelectedAccount = Accounts.FirstOrDefault(account => account.Id == AccountId); }