payload icon indicating copy to clipboard operation
payload copied to clipboard

Data passed to filterOptions sometimes without enriched data from read hooks

Open mzronek opened this issue 1 year ago • 0 comments

Describe the Bug

We are filtering a relationship field using filterOptions with data, that is added to a document in an afterRead/beforeRead hook. Sometimes the data argument is passed with the enriched property, sometimes it is not. That results in the field entries not being filtered correctly. In my reproduction I also couldn't save the entry when the undefined filter removed all options from the field.

Link to the code that reproduces this issue

https://github.com/mzronek/payload-bug-filter

Reproduction Steps

Steps:

  1. Create a second user
  2. Create a new Test entry
  3. Save Test entry (beforeRead/afterRead not called before entry is saved)
  4. Select user again and again until the issue comes up

Result: Only shows a single user, although both should be shown. Console shows: DATA FILTER undefined

To test beforeRead, comment afterRead hook, uncomment beforeRead hook in Test.ts.

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

area: core

Environment Info

Binaries:
  Node: 22.11.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  payload: 3.9.0
  next: 15.1.0
  @payloadcms/db-postgres: 3.9.0
  @payloadcms/email-nodemailer: 3.9.0
  @payloadcms/graphql: 3.9.0
  @payloadcms/next/utilities: 3.9.0
  @payloadcms/payload-cloud: 3.9.0
  @payloadcms/richtext-lexical: 3.9.0
  @payloadcms/translations: 3.9.0
  @payloadcms/ui/shared: 3.9.0
  react: 19.0.0
  react-dom: 19.0.0
Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Home
  Available memory (MB): 65241
  Available CPU cores: 32

mzronek avatar Dec 19 '24 15:12 mzronek