Fix Save Draft always showing Unsaved after save

The snapshot was set from buildSiteContentForSave(form) which runs
normalizeSiteContentForAdmin and rebuilds study objects, producing a
JSON string that never matched the raw form state. isDirty therefore
stayed true permanently after every save.

Fix by capturing JSON.stringify(form) before the fetch and using that
as the snapshot, so isDirty correctly clears on success.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
nmemmert
2026-06-16 11:54:39 -04:00
parent 68fa1497a3
commit d6acf85252
+2 -1
View File
@@ -1468,6 +1468,7 @@ export default function AdminPage({ content, onSave, onLogout }: Props) {
async function handleSaveDraft() {
const payload = buildSiteContentForSave(form)
const formSnapshot = JSON.stringify(form)
setStatus('saving')
setErrorMsg('')
try {
@@ -1482,7 +1483,7 @@ export default function AdminPage({ content, onSave, onLogout }: Props) {
}
const data = await res.json() as { updatedAt?: string }
setPublishState(prev => ({ ...prev, draftUpdatedAt: data.updatedAt ?? new Date().toISOString() }))
setLastSavedSnapshot(JSON.stringify(payload))
setLastSavedSnapshot(formSnapshot)
clearAutosaveDraft()
setStatus('saved')
if (saveStatusTimeoutRef.current !== null) {