Skip to content

Late autosave answers overwrite fields changed meanwhile (only the last changed field is kept) #19368

Closed

Description

@wolffc

Describe the Bug

When an editor changes two fields while an autosave is still on its way, the first of them goes back to its old value, and a later autosave stores that old value. The change is lost without notice. This happens on any slow server or connection.

The autosave answer is built from the form state that was sent with the request, and mergeServerFormState merges it into the current client state:

  1. Values. On autosave (acceptValues: { overrideLocalChanges: false }), a value is skipped only when the client field has isModified set. The UPDATE action of the field reducer removes isModified from every other field whenever a field changes. So only the field changed last is protected. After two quick changes (A, then B) during a running autosave, A is back on its old value once the autosaves that follow are done.
  2. Server-computed state. passesCondition, rows (including collapsed) and valid / errorMessage are always taken from the answer. A stale answer shows the fields for an old condition, or marks a field valid again right after a save returned an error for it.
  3. No follow-up request. MERGE_SERVER_STATE sets prevStateRef.current to the merged state, so the debounced onChange sees no change and doesn't send the form-state request that would correct point 2.

The reproduction covers point 1. We saw points 2 and 3 in our own project: after a quick change of a select, the fields for its old value stayed visible; and a server-side validation error disappeared when a form-state answer from typing came back after Save's 400 (the error toast stayed).

Expected: an answer doesn't overwrite values that changed after its request was sent, and server-computed state from a stale answer is replaced by a fresh request.

Possibly related: #15719 (autosave reverts the link type in the rich text link drawer).

Link to the code that reproduces this issue

https://github.com/wolffc/payload-autosave-stale-merge

Reproduction Steps

The repository has one Playwright test (tests/stale-autosave.e2e.spec.ts) on a posts collection with versions.drafts.autosave (interval: 100) and two fields, color (radio, default Light) and size (select, default Small).

docker compose run --rm test
# or: npm install && npx playwright install chromium && npx playwright test

What the test does:

  1. Open a post in the admin panel. Autosave requests are held back for 2 s to stand in for a slow server.
  2. Edit the title. An autosave is sent with Color = Light.
  3. While it is on its way, set Color to Dark, then Size to Large.
  4. Wait until the autosaves and form-state requests are done.

Result: Color is back on Light in the form, and the saved draft has color: 'light'. Size keeps Large.

Error: expect(locator).toBeChecked() failed

Locator:  getByRole('radio', { name: 'Dark', exact: true })
Expected: checked
Received: unchecked

With only one change during the autosave (skip the Size change), Color stays Dark.

Which area(s) are affected?

area: ui

Environment Info

Binaries:
  Node: 26.13.0
  npm: 11.20.0
Relevant Packages:
  payload: 3.93.0
  next: 16.3.5
  @payloadcms/db-sqlite: 3.93.0
  @payloadcms/drizzle: 3.93.0
  @payloadcms/graphql: 3.93.0
  @payloadcms/next/utilities: 3.93.0
  @payloadcms/translations: 3.93.0
  @payloadcms/ui/shared: 3.93.0
  react: 19.2.6
  react-dom: 19.2.6
Operating System:
  Platform: linux (Docker, mcr.microsoft.com/playwright:v1.64.1-noble)
  Arch: x64

Also seen with 3.92.0 in a production project (Postgres).

Activity

  1. added
    area: ui
    on Nov 5, 2026
  2. added a commit that references this issue on Nov 23, 2026
    7c766ec
  3. github-actions commented on Nov 24, 2026

    @github-actions
    Contributor

    🚀 This is included in version v4.0.0-beta.12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugPayload OSSarea: ui

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions