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
@@ -39,6 +39,14 @@ public abstract class ReleaseDetailBase : ComponentBase, IDisposable
// OnInitialized (which fires once per instance).
if (_loaded && _loadedId == Id) return;
// Capture the id synchronously before any await so that a re-entrant call
// (rapid navigation or a re-render that changes Id while Load is in flight)
// sees the correct guard state. Without this, a second OnParametersSetAsync
// for the same Id would bypass the guard above and start a second Load,
// causing two ViewModel.Load calls to race on the single scoped instance.
_loadedId = Id;
_loaded = true;
// The bridged payload carries both the release and its resolved track so the interactive
// pass renders identically without a second round-trip. Guard on the id: a payload for a
// different release must not seed this page (stale-bridge bleed across navigation).
@@ -52,9 +60,6 @@ public abstract class ReleaseDetailBase : ComponentBase, IDisposable
{
await ViewModel.Load(Id);
}
_loadedId = Id;
_loaded = true;
}
private Task Persist()
@@ -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()