payloadcms / payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
https://payloadcms.com
MIT License
23.58k stars 1.5k forks source link

Undecipherable error when specifying `admin.useAsTitle` on an nonexistent field #8117

Closed tyteen4a03 closed 3 weeks ago

tyteen4a03 commented 3 weeks ago

Link to reproduction

No response

Environment Info

Node.js v20.12.2

Binaries:
  Node: 20.12.2
  npm: 10.5.0
  Yarn: 4.4.1
  pnpm: N/A
Relevant Packages:
  payload: 3.0.0-beta.100
  next: 15.0.0-canary.104
  @payloadcms/db-postgres: 3.0.0-beta.100
  @payloadcms/graphql: 3.0.0-beta.100
  @payloadcms/next/utilities: 3.0.0-beta.100
  @payloadcms/richtext-lexical: 3.0.0-beta.100
  @payloadcms/translations: 3.0.0-beta.100
  @payloadcms/ui/shared: 3.0.0-beta.100
  react: 19.0.0-rc-06d0b89e-20240801
  react-dom: 19.0.0-rc-06d0b89e-20240801
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:30 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6000
  Available memory (MB): 32768
  Available CPU cores: 10

Describe the Bug

Specifying a useAsTitle on a field that doesn't exist triggers an undecipherable error: TypeError: right-hand side of 'in' should be an object, got undefined when visiting the List page of the Collection.

Reproduction Steps

  1. Add the following Collection:
    
    import type { CollectionConfig } from "payload";

export const Example: CollectionConfig = { slug: "example", admin: { useAsTitle: "email", // this field does not exist }, fields: [], };

export default Example;



### Adapters and Plugins

_No response_
paulpopus commented 3 weeks ago

Fixed in https://github.com/payloadcms/payload/pull/8122

We'll throw a clear error if the useAsTitle is invalid

github-actions[bot] commented 2 weeks ago

This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.