fix(ui): upload dropzone error when collectionConfig is undefined (#14043)

### What?

Fixes a bug where dragging a file into an upload dropzone when the
drawer is closed throws an error: "Cannot read properties of undefined".

### Why?

The `collectionConfig` variable can be undefined when the drawer is not
opened, causing the code to fail when trying to access
`collectionConfig.upload?.displayPreview`.

### How?

Added optional chaining (`?.`) to safely access `collectionConfig`,
changing `collectionConfig.upload?.displayPreview` to
`collectionConfig?.upload?.displayPreview`.

Fixes #13999
This commit is contained in:
Patrik
2025-10-03 09:42:21 -04:00
committed by GitHub
parent bbff65c9ec
commit 62fcf18cc3

View File

@@ -89,7 +89,7 @@ export function RelationshipContent(props: Props) {
} }
const metaText = withMeta ? generateMetaText(mimeType, byteSize) : '' const metaText = withMeta ? generateMetaText(mimeType, byteSize) : ''
const previewAllowed = displayPreview ?? collectionConfig.upload?.displayPreview ?? true const previewAllowed = displayPreview ?? collectionConfig?.upload?.displayPreview ?? true
return ( return (
<div className={[baseClass, className].filter(Boolean).join(' ')}> <div className={[baseClass, className].filter(Boolean).join(' ')}>