buildFormState with select evaluates admin.condition against data with unselected fields already deleted
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 40/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- react, typescript
- Domain
- frontend
Research direction
Start at forms/fieldSchemasToFormState/calculateDefaultValues/promise.ts where stripUnselectedFields deletes unselected keys, then read fieldSchemasToFormState/index.tsx to see how fullData is assigned and how iterateFields supplies sibling data to admin.condition. Reproduce by running the linked tests/int/selectCondition.int.spec.ts against the reported repro, covering both the top-level extra case and the nested address.city case. Done means conditions see the pre-strip copy while the returned state is still limited to select. Note a linked pull request (#19605) is already open, so coordinate before starting.
Written by the indexing model from the issue text.
Description
Describe the Bug
In 4.0.0-beta.9, a form state request with select checks each field's admin.condition against data that is already missing every unselected field. Any field whose condition reads a field outside select comes back with passesCondition: false, so it disappears from the form. A form that edits one field of a document (<Form select={{ extra: true }}>) therefore loses that field as soon as its condition depends on another field.
Cause: with select, stripUnselectedFields deletes unselected keys from the data object, first in calculateDefaultValues (forms/fieldSchemasToFormState/calculateDefaultValues/promise.ts) and again in iterateFields. That same object is what admin.condition later receives. At the top level it is both data and fullData (fieldSchemasToFormState/index.tsx: let fullData = dataWithDefaultValues), and for a group it is the group's sibling data.
A fix that makes the repro pass: take a copy of data before stripping when select is set (structuredClone(data)), use it as fullData, and in iterateFields pass the matching sibling object from that copy (looked up by parentPath) as the condition's siblingData. The returned state stays limited to select.
Link to the code that reproduces this issue
https://github.com/cgilly2fast/payload-select-condition-repro
Reproduction Steps
pnpm install && cp .env.example .envpnpm test:int tests/int/selectCondition.int.spec.ts
src/collections/Posts.ts has extra, shown only when title is set, and address.city, shown only when its sibling address.country is US. The test builds form state for a post with title: 'Hello' and address.country: 'US':
- No
select(control): both fields pass their conditions. select: { extra: true }:extragetspassesCondition: false. Expected: it passes, becausetitleis set.select: { address: { city: true } }:address.citygetspassesCondition: false. Expected: it passes, becausecountryisUS.
Which area(s) are affected?
area: ui
Environment Info
payload 4.0.0-beta.9, @payloadcms/ui 4.0.0-beta.9, @payloadcms/db-sqlite 4.0.0-beta.9, Node 24, created with create-payload-app@beta -t blank.
- Dominant language
- TypeScript
- Stars
- 45.8k
- Forks
- 4.4k
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 251
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from payloadcms/payload
-
db-d1-sqlite: upsert is aliased to updateOne, so payload.kv.set never inserts new keysPossibly taken @pcbeingused333 claimed this today. OpenBug db: d1-sqlite Payload OSS
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
payloadcms/payload#19766 ·
Maintainers usually reply within 1 day
-
Document bar (.doc-controls__content) overflows a 375 px viewport, clips "Created" and fails axe scrollable-region-focusablePossibly taken A pull request linked to this issue is open or already merged. Openarea: ui Bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
payloadcms/payload#19690 ·
Maintainers usually reply within 1 day
-
[v4] Blocks thumbnails croped 3:2Possibly taken @samiarif02 claimed this 2 days ago. Openarea: ui Bug Payload OSS status: needs-triage v3
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
payloadcms/payload#19609 ·
Maintainers usually reply within 1 day
-
Scheduled publish jobs are not deleted when their document is deleted (string id in the job, raw id in the cleanup)Possibly taken @volodymyrshk claimed this 10 days ago. Openarea: core Bug db: sqlite
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
payloadcms/payload#19448 ·
Maintainers usually reply within 1 day
-
plugin-multi-tenant: `isGlobal` collections redirect tenant-scoped users to `/admin` since 3.93.0 (GlobalViewRedirect prop-name mismatch)Possibly taken @JarrodMFlesch claimed this 10 days ago. OpenBug plugin: multi-tenant
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
payloadcms/payload#19420 · 1 assignee ·
Maintainers usually reply within 1 day
All issues in payloadcms/payload
Similar issues
-
`@angular/[email protected]` depends on vulnerable Vite 7.3.7 - GHSA-p4f5-76q4-ffq7 (Critical RCE)Openarea: @angular/build
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
angular/angular-cli#34764 ·
Maintainers usually reply within 1 day
-
status/need-triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
google-gemini/gemini-cli#30384 · 1 comment ·
Maintainers usually reply within 1 day
-
P2
Difficulty 1/5 Under an hour Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
bug ready-for-human
Difficulty 2/5 1-3 hours Newbie friendliness 60/100
LucasSantana-Dev/Lucky#3150 ·
Maintainers usually reply within 1 day
-
enhancement good first issue priority: low size: XS
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day