Skip to content

fix(ui): prevent autosave from reverting recently edited fields - #1

Closed
lucasvass1 wants to merge 1 commit into
beyondwebb:mainfrom
lucasvass1:fix/autosave-overwrites-recent-edits
Closed

fix(ui): prevent autosave from reverting recently edited fields#1
lucasvass1 wants to merge 1 commit into
beyondwebb:mainfrom
lucasvass1:fix/autosave-overwrites-recent-edits

Conversation

@lucasvass1

Copy link
Copy Markdown

Fixes payloadcms#17676

Summary

  • Autosave could overwrite recently typed field values: switching to a different field while a previous autosave request was still in flight cleared that field's "modified" protection, so the stale response (with an older/partial value) could land and overwrite the newer edit. Fixed by tracking a per-field modifiedAt timestamp and comparing it against when each request was sent — a response is only accepted for a field if no local edit happened to it after that specific request was dispatched.
  • Media library (and any relationship/upload) list drawer would flicker/reload during editing: unmodified object/array-valued fields (relationship, upload) got a brand new, content-identical value reference on every accepted autosave merge, which cascaded into useListDrawer recomputing and remounting the open drawer. Fixed by preserving the existing reference in mergeServerFormState when the incoming value is deeply equal to the current one.

Test plan

  • Added an e2e regression test reproducing the reported race (type in one field, switch to another before autosave completes) — fails without the fix, passes with it
  • Added an e2e test asserting an open relationship list drawer isn't remounted by an unrelated autosave — fails without the fix, passes with it
  • Added a unit test in mergeServerFormState covering reference preservation for content-identical values
  • Existing autosave/computed-field tests in test/form-state still pass (no regression to the "don't overwrite a field being actively edited" behavior)
  • pnpm run build:core and lint pass

… remounting relationship/upload list drawers

Switching to a different field while a previous autosave request was still
in flight cleared that field's modified protection, so a stale response
could overwrite the newer local edit. Track a per-field last-modified
timestamp and compare it against when each request was sent, so a response
is only accepted if no local edit happened after it was dispatched.

Also preserve the value/initialValue reference for unmodified fields when
the incoming server value is content-identical, since object/array-shaped
values (e.g. relationship and upload fields) otherwise get a new reference
on every autosave merge, causing their list drawers to needlessly recompute
filter options and remount.
@vercel

vercel Bot commented Aug 6, 2026

Copy link
Copy Markdown

@lucasvass1 is attempting to deploy a commit to the Beyond Communication Team on Vercel.

A member of the Team first needs to authorize it.

@lucasvass1

Copy link
Copy Markdown
Author

Opened this by mistake against this reproduction repo instead of the actual payloadcms/payload repository. Closing this and moving the fix to the correct PR:

payloadcms#17697

@lucasvass1 lucasvass1 closed this Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Autosave can overwrite recently typed field values and reload the media library

1 participant