fix(detail): capture guard fields before await to close re-entrancy window in OnParametersSetAsync

This commit is contained in:
daniel-c-harvey
2026-06-15 12:55:15 -04:00
parent f02f370ed9
commit 7d23c0654b
2 changed files with 15 additions and 5 deletions
@@ -34,6 +34,13 @@ public partial class TrackDetail : ComponentBase, IDisposable
// OnInitialized (which fires once per instance).
if (_loadedEntryKey == EntryKey) return;
// Capture the key synchronously before any await so that a re-entrant call
// (rapid navigation or a re-render that changes EntryKey while Load is in flight)
// sees the correct guard state. Without this, a second OnParametersSetAsync
// for the same EntryKey would bypass the guard above and start a second Load,
// causing two ViewModel.Load calls to race on the single scoped instance.
_loadedEntryKey = EntryKey;
// Guard the bridge on the key: a payload for a different track must not seed this
// page (stale-bridge bleed across navigation).
if (PersistentState.TryTakeFromJson<TrackDto>(PersistKey, out var restored)
@@ -48,8 +55,6 @@ public partial class TrackDetail : ComponentBase, IDisposable
{
await ViewModel.Load(EntryKey);
}
_loadedEntryKey = EntryKey;
}
private Task PersistTrack()