fix: sanitize collection labels to inherit defaults when only a partial config is provided (#13944)

When only a partial `labels` config is defined on a collection, the
collection defaults do not apply as expected. This leads to undefined
`singular` or `plural` properties that render as either empty or
untranslated strings on the front-end.

For example:

```ts
import type { CollectionConfig } from 'payload'

export MyCollection: CollectionConfig = {
  // ... 
  labels: {
    plural: 'Pages', // Notice that `singular` is excluded here
  },
}
```

This renders empty or untranslated strings throughout the admin panel,
here are a couple examples:

<img width="326" height="211" alt="Screenshot 2025-09-26 at 10 27 40 AM"
src="https://github.com/user-attachments/assets/3872c4dd-0dac-4c1c-b417-61ddd042bbb8"
/>

<img width="330" height="267" alt="Screenshot 2025-09-26 at 10 27 51 AM"
src="https://github.com/user-attachments/assets/78772405-b5f3-45fa-9bf0-bc078f1ba976"
/>

---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
  - https://app.asana.com/0/0/1211478736160147
This commit is contained in:
Jacob Fletcher
2025-09-26 11:24:11 -04:00
committed by GitHub
parent 2cc34d1a4a
commit 17520439e5
4 changed files with 16 additions and 1 deletions

View File

@@ -14,6 +14,10 @@ export default buildConfigWithDefaults({
collections: [
{
slug: 'pages',
labels: {
// Purposefully exclude `singular` to test default inheritance
plural: 'Pages',
},
access: {
create: () => true,
delete: () => true,

View File

@@ -126,6 +126,11 @@ describe('Config', () => {
description: 'The blockOne of this page',
})
})
it('properly merges collection.labels with defaults', () => {
const [collection] = payload.config.collections
expect(collection?.labels).toEqual({ plural: 'Pages', singular: 'Page' })
})
})
describe('global config', () => {