mirror of
https://github.com/kilyabin/psysonic.git
synced 2026-07-21 22:15:40 +00:00
fix(artist): decouple artist info fetch from main render path (fix #132)
getArtistInfo2.view can trigger Navidrome to do slow external lookups (Last.fm / Apple Music) when no local artist image exists, blocking the entire page for 10+ seconds. Render the page immediately after getArtist() resolves (local data only), then fire getArtistInfo and getTopSongs in the background. A cancelled flag prevents stale state updates when the user navigates away before either background fetch completes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -80,24 +80,32 @@ export default function ArtistDetail() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
|
let cancelled = false;
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
setInfo(null);
|
||||||
|
setTopSongs([]);
|
||||||
setFeaturedAlbums([]);
|
setFeaturedAlbums([]);
|
||||||
getArtist(id).then(artistData => {
|
getArtist(id).then(artistData => {
|
||||||
|
if (cancelled) return;
|
||||||
setArtist(artistData.artist);
|
setArtist(artistData.artist);
|
||||||
setAlbums(artistData.albums);
|
setAlbums(artistData.albums);
|
||||||
setIsStarred(!!artistData.artist.starred);
|
setIsStarred(!!artistData.artist.starred);
|
||||||
return Promise.all([
|
// Render the page immediately from local data
|
||||||
getArtistInfo(id).catch(() => null),
|
|
||||||
getTopSongs(artistData.artist.name).catch(() => []),
|
|
||||||
]);
|
|
||||||
}).then(([artistInfo, songsData]) => {
|
|
||||||
if (artistInfo !== undefined) setInfo(artistInfo as SubsonicArtistInfo | null);
|
|
||||||
if (songsData !== undefined) setTopSongs(songsData as SubsonicSong[]);
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|
||||||
|
// Fetch artist info (may trigger slow external lookup on the server)
|
||||||
|
// and top songs in the background — do not block rendering
|
||||||
|
getArtistInfo(id).then(artistInfo => {
|
||||||
|
if (!cancelled) setInfo(artistInfo ?? null);
|
||||||
|
}).catch(() => {});
|
||||||
|
|
||||||
|
getTopSongs(artistData.artist.name).then(songsData => {
|
||||||
|
if (!cancelled) setTopSongs(songsData ?? []);
|
||||||
|
}).catch(() => {});
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.error(err);
|
if (!cancelled) { console.error(err); setLoading(false); }
|
||||||
setLoading(false);
|
|
||||||
});
|
});
|
||||||
|
return () => { cancelled = true; };
|
||||||
}, [id]);
|
}, [id]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user