Autosave / form-state response overwrites edits made while the request was in flight
I maintainer di solito rispondono entro 1 giorno
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Describe the Bug
With drafts and autosave on, a form-state response can overwrite a value the editor changed while that request was in flight. Two cases:
- Text typed into a new array row is cleared. Add an array row, type into its text field, then (before the row's own form-state request returns, e.g. while an upload drawer saves) the response arrives and the text field comes back empty.
- A block row added during an autosave disappears or loses values. Edit a field, then immediately Add Block. When the autosave sent before the add returns, the newer client edits can be reverted.
The text is gone from the UI, so the next save stores the empty value. Publish then fails with required-field errors on fields the editor already filled in.
Root cause
In packages/ui/src/forms/Form/mergeServerFormState.ts, a server value is accepted when:
incomingField.addedByServer ||
acceptValues === true ||
(acceptValues?.overrideLocalChanges === false && !currentState[path]?.isModified)
Two problems:
addedByServeralways wins. A field the server adds to a new row is accepted even if the user has already typed into it on the client. The server value is the default from when the request was sent, so it is older than the client's.isModifiedonly protects the field edited last. TheUPDATEcase infieldReducerclearsisModifiedon every other field whenever any field's value changes. If the user edits field A, then field B, then a response sent before the A edit returns, A is no longerisModifiedand gets overwritten with the stale value.
MERGE_SERVER_STATE has no record of what the request sent, so it can't tell "the server changed this" apart from "the client changed this after the request left."
Suggested fix
Pass the form state that was sent with the request into MERGE_SERVER_STATE (both the onChange queue in Form/index.tsx and the form-state request path already build it with deepCopyObjectSimpleWithoutReactComponents). In mergeServerFormState, skip the incoming value for any path whose current client value differs from the value that was sent, unless acceptValues === true (explicit save, which disables the form):
const changedSinceRequest =
acceptValues !== true &&
requestState !== undefined &&
path in currentState &&
!dequal(currentState[path]?.value, requestState[path]?.value)
let shouldAcceptValue =
!changedSinceRequest &&
(incomingField.addedByServer ||
acceptValues === true ||
(typeof acceptValues === 'object' &&
acceptValues !== null &&
acceptValues.overrideLocalChanges === false &&
!currentState[path]?.isModified))
// when !shouldAcceptValue && changedSinceRequest: drop only `value`,
// keep the server's `initialValue` and other metadata
We're running this as a patch on @payloadcms/ui 3.93.0. It fixed both cases in our Playwright suite, with no change to explicit Save / Publish behavior. Happy to open a PR if this approach looks right.
Possibly the same root cause as #15719 (autosave reverting the link type in the rich-text link modal).
Link to the code that reproduces this issue
No public repo; the config below is enough on a blank template.
Reproduction Steps
Collection config:
{
slug: 'pages',
versions: { drafts: { autosave: { interval: 375 } } },
fields: [
{ name: 'title', type: 'text', required: true },
{
name: 'layout',
type: 'blocks',
blocks: [
{
slug: 'panels',
fields: [
{
name: 'items',
type: 'array',
fields: [
{ name: 'title', type: 'text', required: true },
{ name: 'summary', type: 'textarea', required: true },
{ name: 'image', type: 'upload', relationTo: 'media' },
],
},
],
},
],
},
],
}
Case 1:
- Create a page, add a
panelsblock, and click Add Item. - Type a Title and Summary into the new item right away.
- Under Image, click Create New, upload a file, and save the drawer.
- The image is set, but Title (and sometimes Summary) are empty again. Publish reports
Items 1 → Titleas required.
Uploading first and typing afterward keeps the text.
Case 2:
- Type a page Title, then immediately click Add Block →
panels(within the 375ms autosave window). - In about one of three tries, the drawer closes and the new row's edits are reverted, or the row is missing from Layout.
Which area(s) are affected?
area: ui
Environment Info
Binaries:
Node: 26.0.0
pnpm: 11.2.2
Relevant Packages:
payload: 3.93.0
@payloadcms/ui: 3.93.0
@payloadcms/db-postgres: 3.93.0
next: 16.3.4
react: 19.2.8
Operating System:
Platform: darwin (macOS 26)
- Lingua principale
- TypeScript
- Stelle
- 45.8k
- Fork
- 4.4k
- Merge medio
- 3g 4h
- PR unite (30g)
- 210
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di payloadcms/payload
-
area: ui Bug Payload OSS
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
payloadcms/payload#19839 ·
I maintainer di solito rispondono entro 1 giorno
-
Accessibility: list row and select-all checkboxes still unnamed in 3.x (#17376 fix not in 3.91)ApertaBug Payload OSS
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
payloadcms/payload#19837 ·
I maintainer di solito rispondono entro 1 giorno
-
Bug Payload OSS
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
payloadcms/payload#19835 ·
I maintainer di solito rispondono entro 1 giorno
-
Bug Payload OSS
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
payloadcms/payload#19833 ·
I maintainer di solito rispondono entro 1 giorno
-
Bug Payload OSS
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
payloadcms/payload#19832 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di payloadcms/payload
Issue simili
-
[BUG]: Shared links drop the configured basePath on GitHub PagesForse già presa @anshulchikhale30-p l’ha presa oggi. Apertabug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
StabilityNexus/IdentityTokens-EVM-Frontend#182 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Add: GTrekkerApertacheck:passed streams:add
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
Koenkk/zigbee-herdsman-converters#13900 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
jeanibarz/knowledge-base-mcp-server#1291 ·
I maintainer di solito rispondono entro 1 giorno