You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: Autosave invalidates query cache and resets form fields to server state #295
When editing a content entry with many custom fields, autosave fires after 2 seconds of inactivity and resets all form fields to the previous server state, discarding any unsaved changes the user made.
Steps to Reproduce
Create a collection with many custom fields (e.g. 80+ flat fields for a homepage)
Open the content editor in admin panel
Edit any field value
Wait ~2 seconds for autosave to trigger
Observe: The field reverts to its previous value
Expected Behavior
Autosave should save the current form state without resetting the form. User edits should persist after autosave completes.
Actual Behavior
After autosave completes, the form fields revert to the server state (the values before the edit). The user's changes are lost.
Manual save (clicking the Save button) works correctly — changes persist.
Root Cause (from source analysis)
In the admin bundle (@emdash-cms/admin/dist/index.js):
Autosave mutation (autosaveMutation) calls updateContent() with skipRevision: true
On success, it calls queryClient.invalidateQueries(["content", collection, id]) — this triggers a refetch of the entry from the server
The refetch updates the item prop, which triggers a useEffect that does:
setFormData(item.data);// Resets form to server state
If the autosave payload didn't include all fields (or if there's a race condition between the save completing and the refetch), the form gets reset to stale server data
The useEffect dependency on item?.updatedAt / itemDataString causes a form reset every time the query cache is refreshed.
Suggested Fix
Option A: Don't invalidate the query cache after autosave — just update lastAutosaveAt without refetching:
onSuccess: ()=>{setLastAutosaveAt(newDate());// Don't invalidate queries — the local form state IS the source of truth}
Option B: After refetch, merge server data with local unsaved changes instead of replacing form state.
Environment
EmDash v0.1.0
Cloudflare Workers
Collection with 85+ custom fields
Chrome / Edge (latest)
Workaround
Clicking the manual Save button immediately after editing works correctly. Only the debounced autosave exhibits this issue.
Activity
Fix autosave form reset bug (emdash-cms#295)
Fix autosave form reset bug
Fix autosave form reset bug (#302)
Fix autosave form reset bug (emdash-cms#302)
Fix autosave form reset bug (emdash-cms#302)