Conversation
Autosave was invalidating the query cache after completion, which triggered a refetch of content data from the server. This refetch updated the item prop, causing a useEffect in ContentEditor to reset form state to the server values, overwriting unsaved user changes. The fix removes the queryClient.invalidateQueries() call from the autosaveMutation onSuccess handler. The local form state remains the source of truth during editing, and manual saves still properly invalidate and refresh the cache. Fixes emdash-cms#295
🦋 Changeset detectedLatest commit: bb26f11 The changes in this PR will be included in the next version bump. This PR includes changesets to release 10 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
All contributors have signed the CLA ✍️ ✅ |
There was a problem hiding this comment.
Pull request overview
Fixes the content editor autosave behavior so that successful autosaves no longer trigger a React Query refetch that resets in-progress form edits back to server state.
Changes:
- Removes
queryClient.invalidateQueries(["content", collection, id])from the autosave mutationonSuccesshandler. - Keeps autosave feedback via
lastAutosaveAtwhile leaving manual save/publish flows to continue invalidating queries as before. - Adds a changeset to release the admin package as a patch.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/admin/src/router.tsx | Stops autosave from invalidating the content query cache, preventing editor form state resets after autosave. |
| .changeset/fix-autosave-form-reset.md | Records the bugfix for a patch release of @emdash-cms/admin. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I have read the CLA Document and I hereby sign the CLA |
What does this PR do?
Fixes a bug where autosave invalidates the query cache and resets form fields to server state, causing user edits to be lost.
When editing a content entry with many custom fields, autosave fires after 2 seconds of inactivity. Upon success, it was calling
queryClient.invalidateQueries(["content", collection, id]), which triggered a refetch from the server. This refetch updated theitemprop, which triggered auseEffectinContentEditorthat resets form state (formData,slug, etc.) to server values.The fix removes the
queryClient.invalidateQueries()call from theautosaveMutationonSuccesshandler. The local form state remains the source of truth during editing. Manual saves still properly invalidate and refresh the cache.Closes #295
Type of change
Checklist
pnpm typecheckpasses (pre-existing errors in admin package unrelated to this change)pnpm --silent lint:json | jq '.diagnostics | length'returns 0 (pre-existing errors unrelated to this change)pnpm formathas been run