fix(detail): reload track on route-param change so Play uses the right track
Detail pages loaded only in OnInitialized, which doesn't re-run when an InteractiveAuto component instance is reused across same-template navigations, leaving a stale track that Play streamed. Move load to OnParametersSetAsync keyed on the route id, and guard the prerender bridge restore against an id mismatch.
This commit is contained in:
@@ -14,23 +14,42 @@ public partial class TrackDetail : ComponentBase, IDisposable
|
||||
|
||||
private PersistingComponentStateSubscription _persistingSubscription;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
// The entry key the ViewModel currently holds. Tracks param-only navigations
|
||||
// (e.g. /track/A -> /track/B) which reuse this component instance and fire
|
||||
// OnParametersSet without re-running OnInitialized — without this, the page keeps
|
||||
// the prior track and Play streams the wrong audio.
|
||||
private string? _loadedEntryKey;
|
||||
|
||||
protected override void OnInitialized()
|
||||
// Carry the prerendered track across the prerender -> interactive (WASM) seam.
|
||||
// Without this, the WASM pass gets a fresh scoped ViewModel, re-renders the
|
||||
// skeleton, and re-fetches. Mirror the TracksView bridge: persist on the way
|
||||
// out of prerender, restore on the interactive pass, and only fetch on a miss.
|
||||
_persistingSubscription = PersistentState.RegisterOnPersisting(PersistTrack);
|
||||
=> _persistingSubscription = PersistentState.RegisterOnPersisting(PersistTrack);
|
||||
|
||||
if (PersistentState.TryTakeFromJson<TrackDto>(PersistKey, out var restored) && restored is not null)
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
// Re-run whenever the route key changes. Component instances are reused across
|
||||
// same-template navigations, so the load decision must live here, not in
|
||||
// OnInitialized (which fires once per instance).
|
||||
if (_loadedEntryKey == EntryKey) return;
|
||||
|
||||
// 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)
|
||||
&& restored is not null
|
||||
&& restored.EntryKey == EntryKey)
|
||||
{
|
||||
ViewModel.Track = restored;
|
||||
ViewModel.NotFound = false;
|
||||
ViewModel.IsLoading = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
await ViewModel.Load(EntryKey);
|
||||
}
|
||||
|
||||
_loadedEntryKey = EntryKey;
|
||||
}
|
||||
|
||||
private Task PersistTrack()
|
||||
|
||||
Reference in New Issue
Block a user