Repository navigation
Description
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 metadataWe'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)
Activity
fix(ui): prevent stale responses from overwriting form state (payload…
github-actions commentedon Nov 24, 2026
🚀 This is included in version v4.0.0-beta.12