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:
@@ -19,16 +19,32 @@ public abstract class ReleaseDetailBase : ComponentBase, IDisposable
|
||||
|
||||
private PersistingComponentStateSubscription _persistingSubscription;
|
||||
|
||||
// The release id the ViewModel currently holds. Tracks param-only navigations (e.g.
|
||||
// /mixes/5 -> /mixes/8) which reuse this component instance and fire OnParametersSet
|
||||
// without re-running OnInitialized — without this, the page would keep the prior
|
||||
// release's track and Play would stream the wrong audio.
|
||||
private long _loadedId;
|
||||
private bool _loaded;
|
||||
|
||||
// Distinct keys per medium so a Session restore never lands on a Mix page.
|
||||
protected abstract string PersistKey { get; }
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
protected override void OnInitialized()
|
||||
=> _persistingSubscription = PersistentState.RegisterOnPersisting(Persist);
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
_persistingSubscription = PersistentState.RegisterOnPersisting(Persist);
|
||||
// Re-run whenever the route id 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 (_loaded && _loadedId == Id) return;
|
||||
|
||||
// The bridged payload carries both the release and its resolved track so the interactive
|
||||
// pass renders identically without a second round-trip.
|
||||
if (PersistentState.TryTakeFromJson<BridgedDetail>(PersistKey, out var restored) && restored?.Release is not null)
|
||||
// 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).
|
||||
if (PersistentState.TryTakeFromJson<BridgedDetail>(PersistKey, out var restored)
|
||||
&& restored?.Release is not null
|
||||
&& restored.Release.Id == Id)
|
||||
{
|
||||
ViewModel.Restore(restored.Release, restored.Track);
|
||||
}
|
||||
@@ -36,6 +52,9 @@ public abstract class ReleaseDetailBase : ComponentBase, IDisposable
|
||||
{
|
||||
await ViewModel.Load(Id);
|
||||
}
|
||||
|
||||
_loadedId = Id;
|
||||
_loaded = true;
|
||||
}
|
||||
|
||||
private Task Persist()
|
||||
|
||||
Reference in New Issue
Block a user