payload icon indicating copy to clipboard operation
payload copied to clipboard

WhereBuilder throws "Cannot read properties of undefined (reading 'value')" when the list URL filters on a field that is not filterable

Open paurushrai opened this issue 1 month ago • 1 comments

Describe the Bug

Opening a collection list view whose URL where query references a path that is not among the filterable fields causes an unhandled promise rejection about 300ms after the filters render:

TypeError: Cannot read properties of undefined (reading 'value')
    at WhereBuilder.useCallback[updateCondition] (packages/ui/src/elements/WhereBuilder/index.tsx)
    at Condition.useEffectEvent[updateValue] (packages/ui/src/elements/WhereBuilder/Condition/index.tsx)
    at Condition.useEffect

The filter row itself renders fine (empty field select). Nothing breaks visually, but every such page load raises an unhandled rejection. In dev, Next.js shows "1 Issue". In production it reaches error monitoring as an unhandledrejection. We found it in production through Grafana Faro on /admin/collections/posts/.

Realistic ways to get there:

  • A shared or bookmarked list URL that filters on a field that was later renamed or removed.
  • A shared list URL that filters on a field the current user cannot read. Since #14118, reduceFieldsToOptions drops fields without read access from the filter options.

Cause: Condition resolves its field with reducedFields.find((field) => field.value === fieldPath), which is undefined for these paths. Its debounced value effect still calls updateCondition({ type: 'value', field: reducedField, ... }) on mount. updateCondition then reads field.value without a guard, inside an async callback, so the rejection is unhandled.

The same trigger (pasting a filtered list URL) crashed at a different spot in #9179, fixed in #9276. On main this is already guarded (field?.fieldPath, from #16810), so it only affects 3.x.

Link to the code that reproduces this issue

https://github.com/paurushrai/payload-wherebuilder-unknown-field

Reproduction Steps

  1. Clone the repo above (stock [email protected] -t blank, SQLite). The only change: Users has a field with access: { read: () => false }.
  2. cp .env.example .env and set PAYLOAD_SECRET.
  3. npm install && npm run dev, then open http://localhost:3000/admin and create the first user.
  4. Open either URL:
    • http://localhost:3000/admin/collections/users?where[or][0][and][0][internalNote][equals]=x (field the user cannot read)
    • http://localhost:3000/admin/collections/users?where[or][0][and][0][doesNotExist][equals]=x (field that does not exist)
  5. Open the browser console. About 300ms after load: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'value').

Expected: the row renders and nothing throws.

Which area(s) are affected?

area: ui

Environment Info

Binaries:
  Node: 24.18.0
  npm: 11.16.0
  pnpm: 11.28.6
Relevant Packages:
  payload: 3.92.0
  next: 16.3.3
  @payloadcms/db-sqlite: 3.92.0
  @payloadcms/ui/shared: 3.92.0
  react: 19.2.6
  react-dom: 19.2.6
Operating System:
  Platform: darwin
  Arch: arm64

Also seen on payload 3.85.2 with @payloadcms/db-postgres, Next 16.2.10, in production.

paurushrai avatar Oct 23 '26 07:10 paurushrai

Hi! I'd like to contribute a fix for this issue.

I read the report and noticed that the issue affects the 3.x branch, while a related guard already exists on main.

I'd like to reproduce the unhandled rejection, add a regression test for filters referencing missing or inaccessible fields, and implement the smallest compatible fix.

Could you confirm which 3.x branch should be targeted and whether a fix for this issue would be welcome?

Thanks!

Leanderroshan07 avatar Oct 24 '26 01:10 Leanderroshan07