Skip to content

useAsThumbnail: empty hasMany upload field hides the upload collection's own file in cards #19234

Open

Description

@digitalwerber

Describe the Bug

In an upload collection that also has an upload field, admin.useAsThumbnail defaults to that field (documented: "Defaults to the first upload field"). When the field is a single upload and empty, getDocumentThumbnail falls back to the document itself and shows its own file. When the field is hasMany and empty ([]), it does not fall back, so grid view cards and the Recents/Pinned dashboard widget show the generic icon although the document has its own image.

Link to the code that reproduces this issue

https://github.com/digitalwerber/payload/blob/fix/thumbnail-empty-hasmany/packages/ui/src/utilities/getDocumentThumbnail.spec.ts (test case added on this branch)

Reproduction Steps

const Attachments: CollectionConfig = { slug: 'attachments', upload: true, fields: [] }

const Documents: CollectionConfig = {
  slug: 'documents',
  upload: true,
  fields: [{ name: 'attachments', type: 'upload', relationTo: 'attachments', hasMany: true }],
}
  1. Upload an image to documents without attachments.
  2. Open the documents list and switch to the grid layout: the card shows the document icon instead of the image.

Which area(s) are affected?

area: ui

Environment Info

payload: 4.0.0-beta.6
@payloadcms/ui: 4.0.0-beta.6
@payloadcms/db-d1-sqlite: 4.0.0-beta.6
next: 16.4.2
node: 24.22.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugPayload OSSarea: ui

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions