buildFormState with select evaluates admin.condition against data with unselected fields already deleted

Abierto
#19,604 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@hassanabrar202 ya está trabajando en esto.

Desde el 15/11/2026.

  • #19605 de @hassanabrar202 — abierto

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
40/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
react, typescript
Área
frontend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

area: ui Bug Payload OSS
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
  1. pnpm install && cp .env.example .env
  2. pnpm 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 }: extra gets passesCondition: false. Expected: it passes, because title is set.
  • select: { address: { city: true } }: address.city gets passesCondition: false. Expected: it passes, because country is US.
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.

Lenguaje dominante
TypeScript
Estrellas
45.8k
Forks
4.4k
Merge medio
2 d 16 h
PR fusionados (30 d)
251

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de payloadcms/payload

Todos los issues de payloadcms/payload

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.