Skip to content

Unhandled Exception since v3.43: "TypeError: Cannot use 'in' operator to search for 'relationTo' in ..." when accessing version view of a document with a deleted related document #12915

Open
@jhb-dev

Description

@jhb-dev

Describe the Bug

After upgrading from Payload CMS v3.42 to v3.43, I encountered an unhandled exception when trying to view a version of a document that contains a relationship field pointing to a deleted document. (Related to #12027)

Instead of gracefully handling the missing relation (e.g., displaying "Untitled" like the main document view does), the version view crashes with the following error:

TypeError: Cannot use 'in' operator to search for 'relationTo' in 685a93b1c6c9ce7a381d301a

2025-06-24.14-01-44.mp4

Thanks! (BTW, the new version view is great!) 🖤

Link to the code that reproduces this issue

https://github.com/jhb-dev/payload-343-version-view-bug-reproduction

Reproduction Steps

  1. Create a document with a relationship field.
  2. Save a version of the document.
  3. Add a document to the relationship field.
  4. Delete the related document that was selected in the relationship field.
  5. Try to open the version view of the original document.
  6. Observe the unhandled exception.

Which area(s) are affected? (Select all that apply)

area: ui

Environment Info

Binaries:
  Node: 20.19.0
  npm: N/A
  Yarn: N/A
  pnpm: 10.5.2
Relevant Packages:
  payload: 3.43.0
  next: 15.3.0
  @payloadcms/db-mongodb: 3.43.0
  @payloadcms/email-nodemailer: 3.43.0
  @payloadcms/graphql: 3.43.0
  @payloadcms/next/utilities: 3.43.0
  @payloadcms/payload-cloud: 3.43.0
  @payloadcms/richtext-lexical: 3.43.0
  @payloadcms/translations: 3.43.0
  @payloadcms/ui/shared: 3.43.0
  react: 19.1.0
  react-dom: 19.1.0
Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Home
  Available memory (MB): 32694
  Available CPU cores: 24

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs-triagePossible bug which hasn't been reproduced yet

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions