Skip to content

Fix autosave form reset bug#302

Open
ideepakchauhan7 wants to merge 5 commits intoemdash-cms:mainfrom
ideepakchauhan7:fix-autosave-reset
Open

Fix autosave form reset bug#302
ideepakchauhan7 wants to merge 5 commits intoemdash-cms:mainfrom
ideepakchauhan7:fix-autosave-reset

Conversation

@ideepakchauhan7
Copy link
Copy Markdown

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 the item prop, which triggered a useEffect in ContentEditor that resets form state (formData, slug, etc.) to server values.

The fix removes the queryClient.invalidateQueries() call from the autosaveMutation onSuccess handler. 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

  • Bug fix

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes (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 format has been run
  • I have added a changeset (if this PR changes a published package)

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
Copilot AI review requested due to automatic review settings April 6, 2026 09:43
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 6, 2026

🦋 Changeset detected

Latest commit: bb26f11

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
Name Type
@emdash-cms/admin Patch
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/plugin-ai-moderation Patch
@emdash-cms/plugin-atproto Patch
@emdash-cms/plugin-audit-log Patch
@emdash-cms/plugin-color Patch
@emdash-cms/plugin-embeds Patch
@emdash-cms/plugin-forms Patch
@emdash-cms/plugin-webhook-notifier Patch

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 6, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 mutation onSuccess handler.
  • Keeps autosave feedback via lastAutosaveAt while 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.

@ideepakchauhan7
Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Autosave invalidates query cache and resets form fields to server state

2 participants