From fbcda304736779451ea9cfd805ea8efc2081bfe5 Mon Sep 17 00:00:00 2001 From: Deluan Date: Wed, 29 Jul 2026 17:21:36 -0400 Subject: [PATCH] fix(ui): keep the album grid working outside the Random list Hoisting the shown-seed ref into AlbumList made the prop mandatory in practice: ArtistShow renders the same grid through ReferenceManyField and passes no seed tracking, so useRollChanged dereferenced undefined and the artist page died with "Cannot read properties of undefined (reading 'current')". Own a ref in the grid when none is passed. A caller with no roll to track then behaves as it did before, while the Random list keeps the ref that has to outlive the refresh remount. --- ui/src/album/AlbumGridView.jsx | 7 +++++-- ui/src/album/AlbumGridView.test.jsx | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 ui/src/album/AlbumGridView.test.jsx diff --git a/ui/src/album/AlbumGridView.jsx b/ui/src/album/AlbumGridView.jsx index bd10f62dd..9e46fdd43 100644 --- a/ui/src/album/AlbumGridView.jsx +++ b/ui/src/album/AlbumGridView.jsx @@ -1,4 +1,4 @@ -import React from 'react' +import React, { useRef } from 'react' import { GridList, GridListTile, @@ -239,9 +239,12 @@ const AlbumGridView = ({ shownSeed, ...props }) => { + // ArtistShow renders this grid too, with no roll to track, so own a ref when none is passed. + const ownSeed = useRef(null) // A re-roll replaces every album, so the previous roll must not linger while it loads. const rerolling = - useRollChanged(shownSeed, seed, loading) && albumListType === 'random' + useRollChanged(shownSeed ?? ownSeed, seed, loading) && + albumListType === 'random' const hide = rerolling || !props.data || !props.ids return hide ? : } diff --git a/ui/src/album/AlbumGridView.test.jsx b/ui/src/album/AlbumGridView.test.jsx new file mode 100644 index 000000000..1f06c3fd7 --- /dev/null +++ b/ui/src/album/AlbumGridView.test.jsx @@ -0,0 +1,18 @@ +import { render } from '@testing-library/react' +import { describe, it, expect, vi } from 'vitest' +import AlbumGridView from './AlbumGridView' + +// react-admin's Link/useListContext need a router and a store; the grid body is not under test here. +vi.mock('react-admin', () => ({ + linkToRecord: () => '/album/1', + useListContext: () => ({}), + Loading: () =>
, +})) +describe('AlbumGridView', () => { + // ArtistShow renders the grid through ReferenceManyField, which passes no seed tracking. + it('renders without a shownSeed ref', () => { + expect(() => + render(), + ).not.toThrow() + }) +})