fix(foryou): wait for topArtists/recentAlbums before loading dependent rails
Previously onMount fired a single 'forYouLoaded' guard that launched loadArtistsToFollow, loadSpotlight and loadSimilarAlbums immediately — but each of those functions early-returns when its input prop is empty, and the guard prevented re-running once the prop arrived. Users who switched to the For You tab before HomeView finished resolving topArtists would see these rails stay permanently blank (no 'Artists to Follow', no Spotlight, no 'Similar to'). Replaces the single guard with per-section guards and $effects that react to topArtists / recentAlbums becoming non-empty. Sections with no prop dependencies (forgotten, essentials, release watch) still fire once at mount. cc
This commit is contained in:
1 file changed
+32
-7
@@ -186,7 +186,16 @@
|
||||
// Phase 2: Artists to Follow
|
||||
let suggestedArtists = $state<SuggestedArtist[]>([]);
|
||||
let loadingSuggestedArtists = $state(false);
|
||||
let forYouLoaded = $state(false);
|
||||
|
||||
// Per-section load guards so a section that depends on a prop (e.g.
|
||||
// topArtists) does not permanently skip loading when the prop is empty
|
||||
// at mount and arrives later.
|
||||
let artistsToFollowLoaded = false;
|
||||
let spotlightLoaded = false;
|
||||
let similarAlbumsLoaded = false;
|
||||
let forgottenLoaded = false;
|
||||
let essentialsLoaded = false;
|
||||
let releaseWatchLoaded = false;
|
||||
|
||||
// Phase 2: Spotlight
|
||||
let spotlightData = $state<SpotlightData | null>(null);
|
||||
@@ -269,16 +278,32 @@
|
||||
}
|
||||
});
|
||||
|
||||
// Load Phase 2+3 sections when component mounts (once)
|
||||
// Sections that do not depend on props fire once at mount.
|
||||
onMount(() => {
|
||||
if (!forYouLoaded) {
|
||||
forYouLoaded = true;
|
||||
if (!forgottenLoaded) { forgottenLoaded = true; loadForgottenFavorites(); }
|
||||
if (!essentialsLoaded) { essentialsLoaded = true; loadEssentials(); }
|
||||
if (!releaseWatchLoaded) { releaseWatchLoaded = true; loadReleaseWatch(); }
|
||||
});
|
||||
|
||||
// Sections that consume HomeView-provided props fire as soon as the
|
||||
// relevant prop becomes non-empty. Without this, switching to For You
|
||||
// before Home finishes loading leaves these rails permanently blank.
|
||||
$effect(() => {
|
||||
if (!artistsToFollowLoaded && topArtists.length > 0) {
|
||||
artistsToFollowLoaded = true;
|
||||
loadArtistsToFollow();
|
||||
}
|
||||
});
|
||||
$effect(() => {
|
||||
if (!spotlightLoaded && topArtists.length > 0) {
|
||||
spotlightLoaded = true;
|
||||
loadSpotlight();
|
||||
}
|
||||
});
|
||||
$effect(() => {
|
||||
if (!similarAlbumsLoaded && recentAlbums.length > 0) {
|
||||
similarAlbumsLoaded = true;
|
||||
loadSimilarAlbums();
|
||||
loadForgottenFavorites();
|
||||
loadEssentials();
|
||||
loadReleaseWatch();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user