quintodrome/ui/src/common/CoverArtAvatar.jsx

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

53 lines
1.3 KiB
React
Raw Normal View History

import { useRecordContext } from 'react-admin'
import { Avatar } from '@material-ui/core'
import { makeStyles } from '@material-ui/core/styles'
import clsx from 'clsx'
fix(artwork): address WebP performance regression on low-power hardware (#5286) * refactor(artwork): rename DevJpegCoverArt to EnableWebPEncoding Replaced the internal DevJpegCoverArt flag with a user-facing EnableWebPEncoding config option (defaults to true). When disabled, the fallback encoding now preserves the original image format — PNG sources stay PNG for non-square resizes, matching v0.60.3 behavior. The previous implementation incorrectly re-encoded PNG sources as JPEG in non-square mode. Also added EnableWebPEncoding to the insights data. * feat: add configurable UICoverArtSize option Converted the hardcoded UICoverArtSize constant (600px) into a configurable option, allowing users to reduce the cover art size requested by the UI to mitigate slow image encoding. The value is served to the frontend via the app config and used by all components that request cover art. Also simplified the cache warmer by removing a single-iteration loop in favor of direct code. * style: fix prettier formatting in subsonic test * feat: log WebP encoder/decoder selection Signed-off-by: Deluan <deluan@navidrome.org> * fix(artwork): address PR review feedback - Add DevJpegCoverArt to logRemovedOptions so users with the old config key get a clear warning instead of a silent ignore. - Include EnableWebPEncoding in the resized artwork cache key to prevent stale WebP responses after toggling the setting. - Skip animated GIF to WebP conversion via ffmpeg when EnableWebPEncoding is false, so the setting is consistent across all image types. - Fix data race in cache warmer by reading UICoverArtSize at construction time instead of per-image, avoiding concurrent access with config cleanup in tests. - Clarify cache warmer docstring to accurately describe caching behavior. * Revert "fix(artwork): address PR review feedback" This reverts commit 3a213ef03e401930977138afe0e84c83290df683. * fix(artwork): avoid data race in cache warmer config access Capture UICoverArtSize at construction time instead of reading from conf.Server on each doCacheImage call. The background goroutine could race with test config cleanup, causing intermittent race detector failures in CI. * fix(configuration): clamp UICoverArtSize to be within 200 and 1200 Signed-off-by: Deluan <deluan@navidrome.org> * fix(artwork): preserve album cache key compatibility with v0.60.3 Restored the v0.60.3 hash input order for album artwork cache keys (Agents + CoverArtPriority) so that existing caches remain valid on upgrade when EnableExternalServices is true. Also ensures CoverArtPriority is always part of the hash even when external services are disabled, fixing a v0.60.3 bug where changing CoverArtPriority had no effect on cache invalidation. Signed-off-by: Deluan <deluan@navidrome.org> * fix: default EnableWebPEncoding to false and reduce artwork parallelism Changed EnableWebPEncoding default to false so that upgrading users get the same JPEG/PNG encoding behavior as v0.60.3 out of the box, avoiding the WebP WASM overhead until native libwebp is available. Users can opt in to WebP by setting EnableWebPEncoding=true. Also reduced the default DevArtworkMaxRequests to half the CPU count (min 2) to lower resource pressure during artwork processing. * fix(configuration): update DefaultUICoverArtSize to 300 Signed-off-by: Deluan <deluan@navidrome.org> * fix(Makefile): append EXTRA_BUILD_TAGS to GO_BUILD_TAGS Signed-off-by: Deluan <deluan@navidrome.org> --------- Signed-off-by: Deluan <deluan@navidrome.org>
2026-04-04 11:17:01 -08:00
import config from '../config'
import subsonic from '../subsonic'
fix(ui): cancel in-flight image requests on pagination, cache across remounts (#5249) * feat(ui): cancel in-flight image requests on pagination and cache across remounts When paginating quickly through list/grid views, image requests for previous pages were never canceled, queuing on the server and blocking new images. This adds a useImageUrl hook that loads images via fetch() with AbortController, so requests are canceled when components unmount. A module-level cache (URL → blob URL) with reference counting ensures React Admin refreshes display images instantly without re-fetching. * feat(ui): update AlbumListPagination to conditionally render based on albumListType Signed-off-by: Deluan <deluan@navidrome.org> * feat(ui): abort all in-flight image fetches on pagination change Pagination component now watches page/perPage via useListContext and calls abortAllInFlight() when either changes, freeing the browser connection pool immediately for the next page's data request. Also adds empty placeholder style to CoverArtAvatar so it renders as a clean transparent area while loading instead of the default person icon. * Revert "feat(ui): abort all in-flight image fetches on pagination change" This reverts commit 3bc09f9d0374aa63572a381e38a30e2f2cec4da8. * fix(ui): limit concurrent image fetches to prevent connection pool saturation With <img src>, the browser prioritizes API requests over image loads. With fetch(), all requests compete equally for the HTTP/1.1 connection pool (6 per origin), causing API requests to queue behind images and making pagination feel unresponsive. Caps concurrent image fetches at 4 with a pending queue, leaving connections free for API requests. Queued fetches for unmounted components are removed without ever hitting the network. * fix(ui): fix queued fetch not aborted on unmount Set queued=false when doFetch executes from the pending queue, so cleanup correctly calls controller.abort() instead of searching an already-drained queue. --------- Signed-off-by: Deluan <deluan@navidrome.org>
2026-03-25 17:30:40 -08:00
import { useImageUrl } from './useImageUrl'
const useStyles = makeStyles({
avatar: {
width: '55px',
height: '55px',
},
fix(ui): cancel in-flight image requests on pagination, cache across remounts (#5249) * feat(ui): cancel in-flight image requests on pagination and cache across remounts When paginating quickly through list/grid views, image requests for previous pages were never canceled, queuing on the server and blocking new images. This adds a useImageUrl hook that loads images via fetch() with AbortController, so requests are canceled when components unmount. A module-level cache (URL → blob URL) with reference counting ensures React Admin refreshes display images instantly without re-fetching. * feat(ui): update AlbumListPagination to conditionally render based on albumListType Signed-off-by: Deluan <deluan@navidrome.org> * feat(ui): abort all in-flight image fetches on pagination change Pagination component now watches page/perPage via useListContext and calls abortAllInFlight() when either changes, freeing the browser connection pool immediately for the next page's data request. Also adds empty placeholder style to CoverArtAvatar so it renders as a clean transparent area while loading instead of the default person icon. * Revert "feat(ui): abort all in-flight image fetches on pagination change" This reverts commit 3bc09f9d0374aa63572a381e38a30e2f2cec4da8. * fix(ui): limit concurrent image fetches to prevent connection pool saturation With <img src>, the browser prioritizes API requests over image loads. With fetch(), all requests compete equally for the HTTP/1.1 connection pool (6 per origin), causing API requests to queue behind images and making pagination feel unresponsive. Caps concurrent image fetches at 4 with a pending queue, leaving connections free for API requests. Queued fetches for unmounted components are removed without ever hitting the network. * fix(ui): fix queued fetch not aborted on unmount Set queued=false when doFetch executes from the pending queue, so cleanup correctly calls controller.abort() instead of searching an already-drained queue. --------- Signed-off-by: Deluan <deluan@navidrome.org>
2026-03-25 17:30:40 -08:00
avatarEmpty: {
backgroundColor: 'transparent',
},
square: {
borderRadius: '4px',
},
})
export const CoverArtAvatar = ({
record: recordProp,
variant = 'circular',
}) => {
const classes = useStyles()
const recordContext = useRecordContext()
const record = recordProp || recordContext
const square = variant !== 'circular'
fix(ui): cancel in-flight image requests on pagination, cache across remounts (#5249) * feat(ui): cancel in-flight image requests on pagination and cache across remounts When paginating quickly through list/grid views, image requests for previous pages were never canceled, queuing on the server and blocking new images. This adds a useImageUrl hook that loads images via fetch() with AbortController, so requests are canceled when components unmount. A module-level cache (URL → blob URL) with reference counting ensures React Admin refreshes display images instantly without re-fetching. * feat(ui): update AlbumListPagination to conditionally render based on albumListType Signed-off-by: Deluan <deluan@navidrome.org> * feat(ui): abort all in-flight image fetches on pagination change Pagination component now watches page/perPage via useListContext and calls abortAllInFlight() when either changes, freeing the browser connection pool immediately for the next page's data request. Also adds empty placeholder style to CoverArtAvatar so it renders as a clean transparent area while loading instead of the default person icon. * Revert "feat(ui): abort all in-flight image fetches on pagination change" This reverts commit 3bc09f9d0374aa63572a381e38a30e2f2cec4da8. * fix(ui): limit concurrent image fetches to prevent connection pool saturation With <img src>, the browser prioritizes API requests over image loads. With fetch(), all requests compete equally for the HTTP/1.1 connection pool (6 per origin), causing API requests to queue behind images and making pagination feel unresponsive. Caps concurrent image fetches at 4 with a pending queue, leaving connections free for API requests. Queued fetches for unmounted components are removed without ever hitting the network. * fix(ui): fix queued fetch not aborted on unmount Set queued=false when doFetch executes from the pending queue, so cleanup correctly calls controller.abort() instead of searching an already-drained queue. --------- Signed-off-by: Deluan <deluan@navidrome.org>
2026-03-25 17:30:40 -08:00
const url = record
fix(artwork): address WebP performance regression on low-power hardware (#5286) * refactor(artwork): rename DevJpegCoverArt to EnableWebPEncoding Replaced the internal DevJpegCoverArt flag with a user-facing EnableWebPEncoding config option (defaults to true). When disabled, the fallback encoding now preserves the original image format — PNG sources stay PNG for non-square resizes, matching v0.60.3 behavior. The previous implementation incorrectly re-encoded PNG sources as JPEG in non-square mode. Also added EnableWebPEncoding to the insights data. * feat: add configurable UICoverArtSize option Converted the hardcoded UICoverArtSize constant (600px) into a configurable option, allowing users to reduce the cover art size requested by the UI to mitigate slow image encoding. The value is served to the frontend via the app config and used by all components that request cover art. Also simplified the cache warmer by removing a single-iteration loop in favor of direct code. * style: fix prettier formatting in subsonic test * feat: log WebP encoder/decoder selection Signed-off-by: Deluan <deluan@navidrome.org> * fix(artwork): address PR review feedback - Add DevJpegCoverArt to logRemovedOptions so users with the old config key get a clear warning instead of a silent ignore. - Include EnableWebPEncoding in the resized artwork cache key to prevent stale WebP responses after toggling the setting. - Skip animated GIF to WebP conversion via ffmpeg when EnableWebPEncoding is false, so the setting is consistent across all image types. - Fix data race in cache warmer by reading UICoverArtSize at construction time instead of per-image, avoiding concurrent access with config cleanup in tests. - Clarify cache warmer docstring to accurately describe caching behavior. * Revert "fix(artwork): address PR review feedback" This reverts commit 3a213ef03e401930977138afe0e84c83290df683. * fix(artwork): avoid data race in cache warmer config access Capture UICoverArtSize at construction time instead of reading from conf.Server on each doCacheImage call. The background goroutine could race with test config cleanup, causing intermittent race detector failures in CI. * fix(configuration): clamp UICoverArtSize to be within 200 and 1200 Signed-off-by: Deluan <deluan@navidrome.org> * fix(artwork): preserve album cache key compatibility with v0.60.3 Restored the v0.60.3 hash input order for album artwork cache keys (Agents + CoverArtPriority) so that existing caches remain valid on upgrade when EnableExternalServices is true. Also ensures CoverArtPriority is always part of the hash even when external services are disabled, fixing a v0.60.3 bug where changing CoverArtPriority had no effect on cache invalidation. Signed-off-by: Deluan <deluan@navidrome.org> * fix: default EnableWebPEncoding to false and reduce artwork parallelism Changed EnableWebPEncoding default to false so that upgrading users get the same JPEG/PNG encoding behavior as v0.60.3 out of the box, avoiding the WebP WASM overhead until native libwebp is available. Users can opt in to WebP by setting EnableWebPEncoding=true. Also reduced the default DevArtworkMaxRequests to half the CPU count (min 2) to lower resource pressure during artwork processing. * fix(configuration): update DefaultUICoverArtSize to 300 Signed-off-by: Deluan <deluan@navidrome.org> * fix(Makefile): append EXTRA_BUILD_TAGS to GO_BUILD_TAGS Signed-off-by: Deluan <deluan@navidrome.org> --------- Signed-off-by: Deluan <deluan@navidrome.org>
2026-04-04 11:17:01 -08:00
? subsonic.getCoverArtUrl(record, config.uiCoverArtSize, square)
fix(ui): cancel in-flight image requests on pagination, cache across remounts (#5249) * feat(ui): cancel in-flight image requests on pagination and cache across remounts When paginating quickly through list/grid views, image requests for previous pages were never canceled, queuing on the server and blocking new images. This adds a useImageUrl hook that loads images via fetch() with AbortController, so requests are canceled when components unmount. A module-level cache (URL → blob URL) with reference counting ensures React Admin refreshes display images instantly without re-fetching. * feat(ui): update AlbumListPagination to conditionally render based on albumListType Signed-off-by: Deluan <deluan@navidrome.org> * feat(ui): abort all in-flight image fetches on pagination change Pagination component now watches page/perPage via useListContext and calls abortAllInFlight() when either changes, freeing the browser connection pool immediately for the next page's data request. Also adds empty placeholder style to CoverArtAvatar so it renders as a clean transparent area while loading instead of the default person icon. * Revert "feat(ui): abort all in-flight image fetches on pagination change" This reverts commit 3bc09f9d0374aa63572a381e38a30e2f2cec4da8. * fix(ui): limit concurrent image fetches to prevent connection pool saturation With <img src>, the browser prioritizes API requests over image loads. With fetch(), all requests compete equally for the HTTP/1.1 connection pool (6 per origin), causing API requests to queue behind images and making pagination feel unresponsive. Caps concurrent image fetches at 4 with a pending queue, leaving connections free for API requests. Queued fetches for unmounted components are removed without ever hitting the network. * fix(ui): fix queued fetch not aborted on unmount Set queued=false when doFetch executes from the pending queue, so cleanup correctly calls controller.abort() instead of searching an already-drained queue. --------- Signed-off-by: Deluan <deluan@navidrome.org>
2026-03-25 17:30:40 -08:00
: null
const { imgUrl } = useImageUrl(url)
if (!record) return null
return (
<Avatar
fix(ui): cancel in-flight image requests on pagination, cache across remounts (#5249) * feat(ui): cancel in-flight image requests on pagination and cache across remounts When paginating quickly through list/grid views, image requests for previous pages were never canceled, queuing on the server and blocking new images. This adds a useImageUrl hook that loads images via fetch() with AbortController, so requests are canceled when components unmount. A module-level cache (URL → blob URL) with reference counting ensures React Admin refreshes display images instantly without re-fetching. * feat(ui): update AlbumListPagination to conditionally render based on albumListType Signed-off-by: Deluan <deluan@navidrome.org> * feat(ui): abort all in-flight image fetches on pagination change Pagination component now watches page/perPage via useListContext and calls abortAllInFlight() when either changes, freeing the browser connection pool immediately for the next page's data request. Also adds empty placeholder style to CoverArtAvatar so it renders as a clean transparent area while loading instead of the default person icon. * Revert "feat(ui): abort all in-flight image fetches on pagination change" This reverts commit 3bc09f9d0374aa63572a381e38a30e2f2cec4da8. * fix(ui): limit concurrent image fetches to prevent connection pool saturation With <img src>, the browser prioritizes API requests over image loads. With fetch(), all requests compete equally for the HTTP/1.1 connection pool (6 per origin), causing API requests to queue behind images and making pagination feel unresponsive. Caps concurrent image fetches at 4 with a pending queue, leaving connections free for API requests. Queued fetches for unmounted components are removed without ever hitting the network. * fix(ui): fix queued fetch not aborted on unmount Set queued=false when doFetch executes from the pending queue, so cleanup correctly calls controller.abort() instead of searching an already-drained queue. --------- Signed-off-by: Deluan <deluan@navidrome.org>
2026-03-25 17:30:40 -08:00
src={imgUrl || undefined}
variant={variant}
fix(ui): cancel in-flight image requests on pagination, cache across remounts (#5249) * feat(ui): cancel in-flight image requests on pagination and cache across remounts When paginating quickly through list/grid views, image requests for previous pages were never canceled, queuing on the server and blocking new images. This adds a useImageUrl hook that loads images via fetch() with AbortController, so requests are canceled when components unmount. A module-level cache (URL → blob URL) with reference counting ensures React Admin refreshes display images instantly without re-fetching. * feat(ui): update AlbumListPagination to conditionally render based on albumListType Signed-off-by: Deluan <deluan@navidrome.org> * feat(ui): abort all in-flight image fetches on pagination change Pagination component now watches page/perPage via useListContext and calls abortAllInFlight() when either changes, freeing the browser connection pool immediately for the next page's data request. Also adds empty placeholder style to CoverArtAvatar so it renders as a clean transparent area while loading instead of the default person icon. * Revert "feat(ui): abort all in-flight image fetches on pagination change" This reverts commit 3bc09f9d0374aa63572a381e38a30e2f2cec4da8. * fix(ui): limit concurrent image fetches to prevent connection pool saturation With <img src>, the browser prioritizes API requests over image loads. With fetch(), all requests compete equally for the HTTP/1.1 connection pool (6 per origin), causing API requests to queue behind images and making pagination feel unresponsive. Caps concurrent image fetches at 4 with a pending queue, leaving connections free for API requests. Queued fetches for unmounted components are removed without ever hitting the network. * fix(ui): fix queued fetch not aborted on unmount Set queued=false when doFetch executes from the pending queue, so cleanup correctly calls controller.abort() instead of searching an already-drained queue. --------- Signed-off-by: Deluan <deluan@navidrome.org>
2026-03-25 17:30:40 -08:00
className={clsx(
classes.avatar,
square && classes.square,
!imgUrl && classes.avatarEmpty,
)}
alt={record.name}
fix(ui): cancel in-flight image requests on pagination, cache across remounts (#5249) * feat(ui): cancel in-flight image requests on pagination and cache across remounts When paginating quickly through list/grid views, image requests for previous pages were never canceled, queuing on the server and blocking new images. This adds a useImageUrl hook that loads images via fetch() with AbortController, so requests are canceled when components unmount. A module-level cache (URL → blob URL) with reference counting ensures React Admin refreshes display images instantly without re-fetching. * feat(ui): update AlbumListPagination to conditionally render based on albumListType Signed-off-by: Deluan <deluan@navidrome.org> * feat(ui): abort all in-flight image fetches on pagination change Pagination component now watches page/perPage via useListContext and calls abortAllInFlight() when either changes, freeing the browser connection pool immediately for the next page's data request. Also adds empty placeholder style to CoverArtAvatar so it renders as a clean transparent area while loading instead of the default person icon. * Revert "feat(ui): abort all in-flight image fetches on pagination change" This reverts commit 3bc09f9d0374aa63572a381e38a30e2f2cec4da8. * fix(ui): limit concurrent image fetches to prevent connection pool saturation With <img src>, the browser prioritizes API requests over image loads. With fetch(), all requests compete equally for the HTTP/1.1 connection pool (6 per origin), causing API requests to queue behind images and making pagination feel unresponsive. Caps concurrent image fetches at 4 with a pending queue, leaving connections free for API requests. Queued fetches for unmounted components are removed without ever hitting the network. * fix(ui): fix queued fetch not aborted on unmount Set queued=false when doFetch executes from the pending queue, so cleanup correctly calls controller.abort() instead of searching an already-drained queue. --------- Signed-off-by: Deluan <deluan@navidrome.org>
2026-03-25 17:30:40 -08:00
>
{/* Empty child prevents default person icon while loading */}
{!imgUrl && <span />}
</Avatar>
)
}
CoverArtAvatar.defaultProps = { label: '', sortable: false }